-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.lua
55 lines (46 loc) · 1.57 KB
/
enemy.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local enemy = {
new = function (self, colour, speed, hits, x, y)
local table = {
x = x or 400,
y = y or 200,
w = Map.tilesize,
h = Map.tilesize,
health = hits,
colour = colour,
speed = speed * Map.tilesize,
movement = 0,
update = function (self, dt)
-- Health Check
if (self.health <= 0) then
Map:DeleteEntity(self)
return
end
-- Movement
self.movement = self.movement + self.speed * dt
if self.movement >= Map.tilesize then
Map:MoveEntity(self, -self.movement, 0)
self.movement = 0
end
end,
draw = function (self)
love.graphics.setColor(self.colour)
love.graphics.rectangle("fill", self.x, self.y, self.w, self.h)
--love.graphics.print(self.health, self.x - 10, self.y, 0, 1, 1, 0, 0, 0, 0)
love.graphics.setColor(1, 1, 1, 1)
end,
onScreenBounds = function (self)
Map:DeleteEntity(self)
end,
resolveCollision = function (self, entity)
if entity:__tostring() == "bullet" then
self.health = self.health - 1;
end
end,
__tostring = function (self)
return "enemy"
end
}
return table
end,
}
return enemy