-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.lua
52 lines (44 loc) · 1.11 KB
/
coin.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
require "collisions"
local coin = {}
coin.__index = coin
function newCoin(object)
local n = object
n.width = 2
n.height = 2
n.xspeed = math.random(-4,4)/8.0
n.yspeed = -math.random(10)/10.0
n.yaccel = 0.1
return setmetatable(n, coin)
end
function coin:on_the_ground()
return solid_at(self.x, self.y + 2, self)
end
function coin:update(dt)
-- gravity
if not self:on_the_ground() then
self.yspeed = self.yspeed + self.yaccel
self.y = self.y + self.yspeed
self.x = self.x + self.xspeed
end
solid_collisions(self)
end
function coin:draw()
lutro.graphics.draw(IMG_coin, self.x, self.y)
end
function coin:on_collide(e1, e2, dx, dy)
if e2.type == "ground" then
if math.abs(dy) < math.abs(dx) and dy ~= 0 then
self.yspeed = -self.yspeed/2.0
self.y = self.y + dy
end
if math.abs(dy) > math.abs(dx) and dx ~= 0 then
self.xspeed = -self.xspeed/2.0
self.x = self.x + dx
end
elseif e2.type == "character" and (e2.xspeed ~= 0 or e2.yspeed ~= 0) then
sfx_coin:play()
table.insert(effects, newNotif({x=self.x, y=self.y, text="3", font=fnt_numbers_yellow}))
entities_remove(self)
return
end
end