-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy_urn.lua
41 lines (34 loc) · 1.1 KB
/
enemy_urn.lua
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
local flux = require ("flux/flux")
local Enemy = require("enemy")
local EnemyBlue= require("enemy_blue")
local EnemyRed = require("enemy_red")
local EnemyUrn = Enemy:extend()
function EnemyUrn:new(x, y, quadName, spawnType)
EnemyUrn.super.new(self, x, y, 10, 1, 0, "smash", quadName or "urn")
self.spawnType = spawnType or "blue"
end
function EnemyUrn:checkCollision(shot, enemies)
local hit,kill = EnemyUrn.super.checkCollision(self, shot)
if kill then
self.smash(self, enemies)
end
return hit,kill
end
function EnemyUrn:smash(enemies)
local swarmNum = 10
if self.spawnType == "red" then
swarmNum = 6
end
for i=0,(swarmNum-1) do
local enemy
if self.spawnType == "red" then
enemy = EnemyRed(self.x, self.y)
elseif self.spawnType == "blue" then
enemy = EnemyBlue(self.x, self.y)
end
flux.to(enemy, 2, { x = self.x + 120*math.cos(i * 2*math.pi / swarmNum),
y = self.y + 80*math.sin(i * 2*math.pi / swarmNum) }):ease("backout")
table.insert(enemies, enemy)
end
end
return EnemyUrn