]>
Commit | Line | Data |
---|---|---|
10a0e290 BB |
1 | --Configuration for the Main Actor |
2 | this.actorname = "Main Character" | |
3 | this.enemy = enemy_neutral | |
4 | this.controllable = true | |
5 | this.jumpstrength = 5.4 | |
6 | this.speed = 3 | |
7 | this.shotlimit = 3 | |
8 | this.physics = true | |
9 | this.currentweapon = 0 | |
10 | ||
11 | print(">>> Entity Created - "..this.actorname); | |
12 | ||
13 | function this.jump(this) | |
14 | if not this:get_jumplock() | |
15 | --and this:can_move(up,this:get_x()-this:get_ownspeed(),this:get_y()+this:get_vertical_speed()) | |
16 | and not this:can_move(down,this:get_x()-this:get_ownspeed(),this:get_y()) then | |
17 | this:set_vertical_speed(this:get_vertical_speed()-this.jumpstrength) | |
18 | end | |
19 | end | |
20 | ||
21 | function this.centermap(this) | |
22 | ||
23 | this:set_map_sx(this:get_x() - this:get_cfg_screen_width()/2) | |
24 | this:set_map_sy(this:get_y() - this:get_cfg_screen_height()/2) | |
25 | ||
26 | if this:get_map_sx() < 0 then | |
27 | this:set_map_sx(0) | |
28 | elseif this:get_map_sx() + this:get_cfg_screen_width() >= this:get_cfg_max_map_w()*25 then | |
29 | this:set_map_sx(this:get_cfg_max_map_w()*25 - this:get_cfg_screen_width()) | |
30 | end | |
31 | ||
32 | if this:get_map_sy() < 0 then | |
33 | this:set_map_sy(0) | |
34 | elseif this:get_map_sy() + this:get_cfg_screen_height() >= this:get_cfg_max_map_h()*25 then | |
35 | this:set_map_sy(this:get_cfg_max_map_h()*25 - this:get_cfg_screen_height()) | |
36 | end | |
37 | end | |
38 | ||
39 | function this.handleinput(this) | |
40 | if (this:get_leftkey() > 0 and (this:get_leftkey() > this:get_rightkey() or this:get_rightkey() == 0)) then | |
41 | this:set_ownspeed(-this.speed) | |
42 | this:set_oldclip(1) | |
43 | this:set_currentdirection(left) | |
44 | end | |
45 | ||
46 | if (this:get_rightkey() > 0 and (this:get_rightkey() > this:get_leftkey() or this:get_leftkey() == 0)) then | |
47 | this:set_ownspeed(this.speed) | |
48 | this:set_oldclip(2) | |
49 | this:set_currentdirection(right) | |
50 | end | |
51 | ||
52 | if (this:get_rightkey() == 0 and this:get_leftkey() == 0) then | |
53 | this:set_ownspeed(0) | |
54 | end | |
55 | ||
56 | if (this:get_xkey() > 0) then | |
57 | if not this:get_jumplock() then | |
58 | this:jump() | |
59 | this:set_jumplock(true) | |
60 | end | |
61 | else | |
62 | this:set_jumplock(false) | |
63 | if(this:get_vertical_speed() < -1) then | |
64 | this:set_vertical_speed(-1) | |
65 | end | |
66 | end | |
67 | ||
68 | if (this:get_zkey() > 0) then | |
69 | if not this:get_shootlock() and this:get_shotcount() < this.shotlimit then | |
70 | if this.currentweapon == 0 then | |
71 | this:add_bullet("./shotsprite.png","./scripts/shot.lua") | |
72 | end | |
73 | if this.currentweapon == 1 then | |
74 | this:add_bullet("./shotsprite.png","./scripts/shot-crawl.lua") | |
75 | end | |
76 | if this.currentweapon == 2 then | |
77 | this:add_bullet("./shotsprite.png","./scripts/shot-wave.lua") | |
78 | end | |
79 | this:set_shootlock(true) | |
80 | end | |
81 | else | |
82 | this:set_shootlock(false) | |
83 | end | |
84 | ||
85 | if (this:get_ckey() > 0) then | |
86 | if not this:get_switchlock() then | |
87 | this.currentweapon = (this.currentweapon + 1) % 3 | |
88 | print ("current weapon is: "..this.currentweapon) | |
89 | this:set_switchlock(true) | |
90 | end | |
91 | else | |
92 | this:set_switchlock(false) | |
93 | end | |
94 | end | |
95 | ||
96 | function this.act(this) | |
97 | this:centermap() | |
98 | this:handleinput() | |
99 | end | |
100 | --END |