Repository navigation
Expand file tree
/
Copy pathobj.enemy-weapon.lua
More file actions
64 lines (56 loc) · 1.89 KB
/
Copy pathobj.enemy-weapon.lua
File metadata and controls
64 lines (56 loc) · 1.89 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
cEnemyWeapon = CreateClass(cEnemyBase)
function cEnemyWeapon:Init(x,y,wType)
self.enemy_kind = "weapon"
self.x = x
self.y = y
self.dx = 300
self.dy = 0
self.wType = wType
self.energy = 100
if (wType == "blue") then self.gfx = gfx_dnabonus_blau
elseif (wType == "green") then self.gfx = gfx_dnabonus_gruen
elseif (wType == "red") then self.gfx = gfx_dnabonus_rot
elseif (wType == "white") then self.gfx = gfx_dnabonus_weis
end
self:Register()
self.time_per_frame = 0.1
self.radius = gPlayer.radius*1.5
self.bCanLeaveScreen = true
end
function cEnemyWeapon:Draw() self:DrawWobble(0.2,0.1,gEnemyGfxScale) end
function cEnemyWeapon:Update(dt)
self.dx = clamp(self.dx + math.random(-50, 50), 300, 800)
self.x = self.x - self.dx * dt
if self.x < 0 then
self:Destroy()
end
local dy = self.y - gPlayer.y
if (math.abs(dy) < 250) then
self.dy = clamp(self.dy + sign(dy) * math.random(15, 30), -50, 50)
if self.bCollidingWithTop == true then
self.dy = -self.dy
self.bCollidingWithTop = false
elseif self.bCollidingWithBottom == true then
self.dy = -self.dy
self.bCollidingWithBottom = false
end
self.y = self.y + self.dy * dt
end
if(self:DistToObj(gPlayer) < self.radius) then
self:Destroy()
gPlayer:AddPoints(125)
gPlayer:UpdateWeapon(self.wType)
if self.wType == "blue" then
effects:CreateEffect("powerup_blue", gPlayer.x, gPlayer.y, 0, true)
elseif self.wType == "green" then
effects:CreateEffect("powerup_green", gPlayer.x, gPlayer.y, 0, true)
elseif self.wType == "red" then
effects:CreateEffect("powerup_red", gPlayer.x, gPlayer.y, 0, true)
elseif self.wType == "white" then
effects:CreateEffect("powerup_yellow", gPlayer.x, gPlayer.y, 0, true)
end
end
end
function cEnemyWeapon:ShotTest(shot, stype)
--if shot.sType == stype and shot:DistToObj(self) < 25 then self:Damage(20) end
end