lua-love-platformer/coin.lua

36 lines
697 B
Lua
Raw Normal View History

2018-01-18 04:38:37 +00:00
coins = {}
function spawnCoin(x, y)
local coin = {}
coin.x = x
coin.y = y
2018-01-18 05:19:17 +00:00
coin.collected = false
2018-01-18 04:38:37 +00:00
coin.grid = anim8.newGrid(41, 42, 123, 126)
coin.animation = anim8.newAnimation(coin.grid('1-3', 1, '1-3', 2, '1-2', 3), 0.1)
table.insert(coins, coin)
end
2018-01-18 05:19:17 +00:00
2018-01-18 05:41:26 +00:00
function spawnCoins()
for i, obj in pairs(gameMap.layers['coins'].objects) do
spawnCoin(obj.x, obj.y)
end
end
2018-01-18 05:19:17 +00:00
function coinUpdate(dt)
for i, c in ipairs(coins) do
if distanceBetween(c.x, c.y, player.body:getX(), player.body:getY()) <= 50 then
c.collected = true
end
end
for i=#coins, 1, -1 do
local c = coins[i]
if c.collected == true then
table.remove(coins, i)
end
end
end