-
Notifications
You must be signed in to change notification settings - Fork 1
/
Disc.lua
44 lines (38 loc) · 873 Bytes
/
Disc.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
local assets = require('assets')
local GameState = require('GameState')
local Animation = require('Animation')
local mt = {}
mt.__index = mt
function mt:update(dt)
-- update animation
self.current_anim:update(dt)
end
function mt:draw()
assets.qdraw(self.current_anim:getFrame(), self.x, self.y)
end
function mt:onTouch(other)
if other.is_hero then
self:setAnim('bloody')
GameState.getCurrent():trigger('hero:kill', self, other)
end
end
function mt:setAnim(name)
self.current_anim = self.anims[name]
end
return {
new = function(x, y)
local d = setmetatable({
is_touchable = true,
x = x,
y = y,
w = GAME_SPRITE_SIZE,
h = GAME_SPRITE_SIZE,
anims = {
idle = Animation.new(15, 2, 0.2),
bloody = Animation.new(17, 2, 0.2),
},
}, mt)
d:setAnim('idle')
return d;
end
}