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