enemy.lua
1.35 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
enemy = class:new()
function enemy:init()
self.quad = 1
self.x = 100
self.y = math.random()*20+40
self.quadtimer = 0
self.movement = math.random(7)-4
if self.movement > 0 then
self.movement = 1
elseif self.movement < 0 then
self.movement = -1
end
self.speed = math.random(30)+40
self.dead = false
end
function enemy:update(dt)
self.quadtimer = self.quadtimer + dt*30
if self.quadtimer > 1 then
self.quadtimer = self.quadtimer - 1
self.quad = self.quad + 1
if self.quad == 17 then
self.quad = 1
end
end
if self.movement == 1 then
self.y = self.y - dt*30
if self.y < 40 then
self.movement = -1
end
elseif self.movement == -1 then
self.y = self.y + dt*30
if self.y > 70 then
self.movement = 1
end
end
self.x = self.x - self.speed*dt
if self.dead then
return true
end
end
function enemy:explode()
self.dead = true
table.insert(explosions, explosion:new(self.x-5, self.y-10))
pointsget(1)
skycolor = getrainbowcolor(math.random())
love.graphics.setBackgroundColor(skycolor)
end
function enemy:checkcol(x, y, newx)
if x < self.x+4 and newx > self.x+4 and math.abs(self.y+7-y) < 6 then
return true
end
return false
end
function enemy:draw()
love.graphics.drawq(enemyimg, enemyquad[self.quad], self.x*scale, self.y*scale, 0, 0.1875*scale, 0.1875*scale)
end