]> git.r.bdr.sh - rbdr/pico-engine/blame - scripts/main_actor.lua
Update project so it compiles
[rbdr/pico-engine] / scripts / main_actor.lua
CommitLineData
10a0e290
BB
1--Configuration for the Main Actor
2this.actorname = "Main Character"
3this.enemy = enemy_neutral
4this.controllable = true
5this.jumpstrength = 14
6this.speed = 6
7this.shotlimit = 3
8this.physics = true
9this.currentweapon = 0
10
11--Experimental Configuration for new Physics Engine.
12this.jump_strength = 10
13this.walk_speed = 10
14this.walk_acc = .1
15
16print(">>> Entity Created - "..this.actorname);
17
18function this.jump(this)
19 if not this:get_jumplock()
20 --and this:can_move(up,this:get_x()-this:get_ownspeed(),this:get_y()+this:get_vertical_speed())
21 and not this:can_move(down,this:get_x()-this:get_ownspeed(),this:get_y()) then
22 this:set_vertical_speed(this:get_vertical_speed()-this.jumpstrength)
23 end
24end
25
26function this.centermap(this)
27
28
29 --This is the map center. Set it.
30 this:set_map_sx(this:get_x() - this:get_cfg_screen_width()/2)
31 this:set_map_sy(this:get_y() - this:get_cfg_screen_height()/2)
32
33 --Unless of course we're at one of the edges.
34 if this:get_map_sx() < 0 then
35 this:set_map_sx(0)
36 elseif this:get_map_sx() + this:get_cfg_screen_width() >= this:get_cfg_max_map_w()*this:get_cfg_tile_w() then
37 this:set_map_sx(this:get_cfg_max_map_w()*this:get_cfg_tile_w() - this:get_cfg_screen_width())
38 end
39
40 if this:get_map_sy() < 0 then
41 this:set_map_sy(0)
42 elseif this:get_map_sy() + this:get_cfg_screen_height() >= this:get_cfg_max_map_h()*this:get_cfg_tile_h() then
43 this:set_map_sy(this:get_cfg_max_map_h()*this:get_cfg_tile_h() - this:get_cfg_screen_height())
44 end
45end
46
47function this.handleinput(this)
48 if (this:get_leftkey() > 0 and (this:get_leftkey() > this:get_rightkey() or this:get_rightkey() == 0)) then
49 this:accelerate(-this.walk_acc, -this.walk_speed)
50 --this:set_ownspeed(-this.speed)
51 this:set_oldclip(1)
52 this:set_currentdirection(left)
53 end
54
55 if (this:get_rightkey() > 0 and (this:get_rightkey() > this:get_leftkey() or this:get_leftkey() == 0)) then
56 this:accelerate(this.walk_acc, this.walk_speed)
57 --this:set_ownspeed(this.speed)
58 this:set_oldclip(2)
59 this:set_currentdirection(right)
60 end
61
62 if (this:get_rightkey() == 0 and this:get_leftkey() == 0) then
63 this:decelerate(this.walk_acc)
64 --this:set_ownspeed(0)
65 --this:set_walk_time(0)
66 end
67
68 if (this:get_xkey() > 0) then
69 if not this:get_jumplock() then
70 this:jump()
71 this:set_jumplock(true)
72 end
73 else
74 this:set_jumplock(false)
75 if(this:get_vertical_speed() < -1) then
76 this:set_vertical_speed(-1)
77 end
78 end
79
80 if (this:get_zkey() > 0) then
81 if not this:get_shootlock() and this:get_shotcount() < this.shotlimit then
82 if this.currentweapon == 0 then
83 this:add_bullet("./sprites/shotsprite.png","./scripts/shot.lua")
84 end
85 if this.currentweapon == 1 then
86 this:add_bullet("./sprites/shotsprite.png","./scripts/shot-crawl.lua")
87 end
88 if this.currentweapon == 2 then
89 this:add_bullet("./sprites/shotsprite.png","./scripts/shot-wave.lua")
90 end
91 this:set_shootlock(true)
92 end
93 else
94 this:set_shootlock(false)
95 end
96
97 if (this:get_ckey() > 0) then
98 if not this:get_switchlock() then
99 this.currentweapon = (this.currentweapon + 1) % 3
100 print ("current weapon is: "..this.currentweapon)
101 this:set_switchlock(true)
102 end
103 else
104 this:set_switchlock(false)
105 end
106end
107
108function this.act(this)
109 this:centermap()
110 this:handleinput()
111end
112--END