lutro-platformer/coin.lua

40 lines
795 B
Lua
Raw Normal View History

2017-06-25 10:00:45 +00:00
require "collisions"
local coin = {}
coin.__index = coin
function newCoin(object)
local n = object
2017-06-27 09:18:18 +00:00
n.collect = 0
2017-06-25 10:00:45 +00:00
n.anim = newAnimation(lutro.graphics.newImage(
"assets/coin.png"), 16, 16, 1, 10)
return setmetatable(n, coin)
end
function coin:update(dt)
2017-06-27 09:18:18 +00:00
if self.collect > 0 then
self.collect = self.collect - 1
2017-06-27 11:32:33 +00:00
self.x = self.x + (SCREEN_WIDTH - camera_x - self.x - self.width)/10
2017-06-27 09:18:18 +00:00
self.y = self.y + ( 0 - camera_y - self.y)/10
end
if self.collect == 1 then
entities_remove(self)
2017-06-27 09:54:52 +00:00
gold = gold + 1
2017-06-27 09:18:18 +00:00
end
2017-06-25 10:00:45 +00:00
self.anim:update(dt)
end
function coin:draw()
self.anim:draw(self.x, self.y)
end
function coin:on_collide(e1, e2, dx, dy)
if e2.type == "ninja" and e2.hit == 0 and e2.dying == 0 then
2017-06-25 10:00:45 +00:00
lutro.audio.play(sfx_coin)
2017-06-27 09:18:18 +00:00
self.collect = 30
self.on_collide = nil
2017-06-25 10:00:45 +00:00
end
end