]> git.r.bdr.sh - rbdr/pico-engine/blob - build/Debug/Pico-Lua-Test.app/Contents/Resources/main_actor.lua
Update project so it compiles
[rbdr/pico-engine] / build / Debug / Pico-Lua-Test.app / Contents / Resources / main_actor.lua
1 --Configuration for the Main Actor
2 --Also, this is pretty arbitrary: walksound=0 (for the audio track switches)
3
4 --the directions
5 up=0
6 right=1
7 down=2
8 left = 3
9
10 --Parameters
11 this.actorname = "Main Character"
12 this.enemy = 0
13 this.controllable = 1
14 this.jumpstrength = 6
15 this.speed = 3
16 this.shotlimit = 3
17
18 print(">>> Entity Created - "..this.actorname);
19
20 function this.jump(this)
21 if not this:get_jumplock()
22 and this:can_move(0,this:get_x(),this:get_y())
23 and not this:can_move(2,this:get_x(),this:get_y()) then
24 this:set_vertical_speed(this:get_vertical_speed()-this.jumpstrength)
25 end
26 end
27
28 function this.centermap(this)
29
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 if this:get_map_sx() < 0 then
34 this:set_map_sx(0)
35 elseif this:get_map_sx() + this:get_cfg_screen_width() >= this:get_cfg_max_map_w()*25 then
36 this:set_map_sx(this:get_cfg_max_map_w()*25 - this:get_cfg_screen_width())
37 end
38
39 if this:get_map_sy() < 0 then
40 this:set_map_sy(0)
41 elseif this:get_map_sy() + this:get_cfg_screen_height() >= this:get_cfg_max_map_h()*25 then
42 this:set_map_sy(this:get_cfg_max_map_h()*25 - this:get_cfg_screen_height())
43 end
44 end
45
46 function this.handleinput(this)
47 if (this:get_leftkey() > 0 and (this:get_leftkey() > this:get_rightkey() or this:get_rightkey() == 0)) then
48 this:set_ownspeed(-this.speed)
49 this:set_oldclip(1)
50 this:set_currentdirection(left)
51 end
52
53 if (this:get_rightkey() > 0 and (this:get_rightkey() > this:get_leftkey() or this:get_leftkey() == 0)) then
54 this:set_ownspeed(this.speed)
55 this:set_oldclip(2)
56 this:set_currentdirection(right)
57 end
58
59 if (this:get_rightkey() == 0 and this:get_leftkey() == 0) then
60 this:set_ownspeed(0)
61 end
62
63 if (this:get_xkey() > 0) then
64 if not this:get_jumplock() then
65 this:jump()
66 this:set_jumplock(true)
67 end
68 else
69 this:set_jumplock(false)
70 if(this:get_vertical_speed() < -1) then
71 this:set_vertical_speed(-1)
72 end
73 end
74
75 if (this:get_zkey() > 0) then
76 if not this:get_shootlock() and this:get_shotcount() < this.shotlimit then
77 this:add_bullet("./shotsprite.png","./shot.lua")
78 this:set_shootlock(true)
79 end
80 else
81 this:set_shootlock(false)
82 end
83 end
84
85 function this.act(this)
86 this:centermap()
87 this:handleinput()
88 end
89 --END