-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.lua
More file actions
172 lines (142 loc) · 4.44 KB
/
Copy pathenemy.lua
File metadata and controls
172 lines (142 loc) · 4.44 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
-- This file is part of SpaceShooter.
--
-- SpaceShooter is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- SpaceShooter is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with SpaceShooter. If not, see <http://www.gnu.org/licenses/>.
Enemy = class {}
Enemy.__name = "Enemy"
function Enemy:__init()
local edge = math.random () * 4
if (edge < 2) then -- left or right
self.y = math.random () * win_height
if (edge < 1) then -- left
self.x = 0
else -- right
self.x = win_width
end
else -- top or bottom
self.x = math.random () * win_width
if (edge < 3) then -- top
self.y = 0
else -- bottom
self.y = win_height
end
end
self.velocity = {}
self.velocity.speed = 0
self.velocity.angle = 0
self.rad = 15
self.angle = self.velocity.angle
self.bounds = {}
self.bounds.rad = self.rad
self.max_speed = 100
self.min_speed = 0
self.drop = nil
self.weapons = {}
self.cannon_fire_mult = 1
self.missile_fire_mult = 1
self.destroyed = function (self)
make_explosion (self.x, self.y, self.rad)
enemies[self] = nil
enemy_count = enemy_count -1
if powerup_roulette (game.powerup_chance_inc) then
powerup_drop_random (self)
end
end
self.hit_with = function (self, object)
if (object:is (Player) or object:is (Shot)) then
self:destroyed ()
end
end
self.update = function (self, dt)
update_pos (self, dt)
wrap_edges (self)
for weapon in pairs (self.weapons) do
if (weapon.update) then
weapon:update ()
end
weapon.fire ()
end
end
end
Drone = Enemy:extends()
Drone.__name = "Drone"
function Drone:__init()
Drone.super.__init(self)
self.velocity.speed = 100
self.velocity.angle = math.random () * math.pi * 2
self.angle = self.velocity.angle
self.icon = icons.drone["green"]
self.draw = function (self)
icon_draw (self, self.icon)
end
end
Seeker = Enemy:extends()
Seeker.__name = "Seeker"
function Seeker:__init()
Seeker.super.__init(self)
self.velocity.speed = 100
self.velocity.angle = angle_between (self, player)
self.accel = 500
self.icon = icons.seeker["green"]
self.update = function (self, dt)
self.angle = angle_between (self, player)
accelerate (self, dt)
check_limits (self)
update_pos (self, dt)
wrap_edges (self)
for weapon in pairs (self.weapons) do
weapon.fire ()
end
end
self.draw = function (self)
icon_draw (self, self.icon)
end
end
CannonDrone = Drone:extends()
CannonDrone.__name = "CannonDrone"
function CannonDrone:__init()
CannonDrone.super.__init(self)
self.icon = icons.drone["orange"]
self.weapons[EnemyCannon (self)] = true
end
MissileDrone = Drone:extends()
MissileDrone.__name = "MissileDrone"
function MissileDrone:__init()
MissileDrone.super.__init(self)
self.icon = icons.drone["red"]
self.weapons[EnemyMissile (self)] = true
end
CannonSeeker = Seeker:extends()
CannonSeeker.__name = "CannonSeeker"
function CannonSeeker:__init()
CannonSeeker.super.__init(self)
self.icon = icons.seeker["orange"]
self.weapons[EnemyCannon (self)] = true
end
MissileSeeker = Seeker:extends()
MissileSeeker.__name = "MissileSeeker"
function MissileSeeker:__init()
MissileSeeker.super.__init(self)
self.icon = icons.seeker["red"]
self.weapons[EnemyMissile (self)] = true
end
local enemy_generator = {}
enemy_generator["drone"] = Drone
enemy_generator["seeker"] = Seeker
enemy_generator["cannondrone"] = CannonDrone
enemy_generator["missiledrone"] = MissileDrone
enemy_generator["cannonseeker"] = CannonSeeker
enemy_generator["missileseeker"] = MissileSeeker
function generate_enemy (type)
return enemy_generator[type] ()
end