-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitem.lua
40 lines (34 loc) · 830 Bytes
/
item.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
Item = Entity:extend()
function Item:init(conf)
local conf = extend({
w = 8,
h = 8,
velx = 0,
vely = 0,
speed = 30,
}, conf or {})
Entity.init(self, conf)
self.velx = self.conf.velx
self.vely = self.conf.vely
end
function Item:update(dt)
-- Apply friction
self.velx = self.velx * 0.9
self.vely = self.vely * 0.9
if math.abs(self.velx) < 0.01 then self.velx = 0 end
if math.abs(self.vely) < 0.01 then self.vely = 0 end
self:tryMove(self.velx, self.vely, dt)
end
Module = Item:extend()
function Module:init(conf)
local conf = extend({
hit = "module"
}, conf or {})
Item.init(self, conf)
self.sprite = Sprite {
image = assets.gfx.module,
frame_w = 8,
frame_h = 8,
speed = 0.5,
}
end