-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoss.lua
More file actions
101 lines (84 loc) · 2.03 KB
/
Boss.lua
File metadata and controls
101 lines (84 loc) · 2.03 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
Boss={}
Boss.xpose=700
Boss.ypose=250
Boss.xScale = 1
Boss.yScale = 1
Boss.width=0
Boss.height=0
Boss.speed=5
Boss.health=0
Boss.maxHealth = 100
Boss.imagePath = 'boss.png'
Boss.const1=0
Boss.const2=0
Boss.shootCooldown=2
Boss.bullets={}
function Boss:spawn()
self.shootCooldown=0
self.const1=0
self.const2=0
self.maxHealth = 100 * currentDifficulty
self.health = self.maxHealth
self.xpose=700
self.ypose=250
self.xScale = 1
self.yScale = 1
self.width=self.image:getWidth()
self.height=self.image:getHeight()
end
function Boss:fire ()
if self.health <= 0 then
return
end
if Boss.shootCooldown > (2 - currentDifficulty*0.1) then
Boss.shootCooldown = 0
local b=Bullet.new(self.xpose + 20, self.ypose + self.height/2, -1, 690 + 10*currentDifficulty, love.graphics.newImage('special bullet.png'))
self.bullets[b] = true
end
end
function Boss:move()
if self.xpose>500 then
self.xpose=self.xpose-0.1*self.speed
return
end
self.ypose = 250 + math.sin(self.const1/10)*100
if self.const2<0.03 then
self.const2=self.const2+0.0002
end
self.const1=self.const1+self.const2
end
function Boss:draw()
if self.health <= 0 then
self:die()
end
if self.image ~= nil then
love.graphics.draw(self.image, self.xpose, self.ypose, 0, self.xScale, self.yScale)
else
love.graphics.rectangle("fill",Boss.xpose,Boss.ypose,100,100)
end
end
function Boss:getRectangle()
return {self.xpose, self.ypose, self.width, self.height}
end
function Boss:getHit()
self.health = self.health - 50
if self.health <= 0 then
self:die()
end
end
function Boss:die()
if self.xScale > 0 then
self.xScale = self.xScale - 0.01
end
if self.yScale > 0 then
self.yScale = self.yScale - 0.01
end
if self.xScale <= 0 or self.yScale <= 0 then
bossIsDead()
end
end
function Boss:drawBullets ()
for bullet, _ in pairs(self.bullets) do
love.graphics.draw(bullet.image, bullet.xPos, bullet.yPos, math.pi, 2, 2)
end
end