-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.lua
40 lines (33 loc) · 995 Bytes
/
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
Enemy = Object:extend()
local offsetWidth = 0
local offsetHeight = 32
local textureWidth = 8
local textureHeight = 8
function Enemy:new(x, y)
self.speed = 300
self.x = x
self.y = y
self.spriteSheet = love.graphics.newImage('Sprites.png')
self.animationGrid = ANIMATE.newGrid(8, 8, self.spriteSheet:getWidth(), self.spriteSheet:getHeight(), 0, 32)
self.animation = ANIMATE.newAnimation(self.animationGrid('1-4', 1), 0.1)
self.sprite = love.graphics.newQuad(offsetWidth, offsetHeight, textureWidth, textureHeight, self.spriteSheet:getDimensions())
end
function Enemy:update(dt)
self.animation:update(dt)
end
function Enemy:draw()
self.spriteSheet:setFilter('nearest')
self.animation:draw(self.spriteSheet, self.x, self.y, 0, 4, 4, 8, 8)
end
function Enemy:left()
return self.x
end
function Enemy:right()
return self.x + textureWidth
end
function Enemy:top()
return self.y
end
function Enemy:bottom()
return self.y + textureHeight
end