Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1.  
  2. function TABLE.createCoin(posX, posY)
  3.  
  4. local data = require("assets.sprites.coin")
  5. local map = graphics.newImageSheet("assets/sprites/coin.png", data:getSheet() )
  6. local animations = {
  7. {name="idle", start=1, count=3, time=200, loopCount = 0, loopDirection = "forward"},
  8. }
  9.  
  10. local coin = display.newSprite( map , animations )
  11. elements_group:insert(coin)
  12.  
  13. coin.x = posY; coin.y = posY
  14. coin.lock = false
  15. physics.addBody(coin, "static")
  16. coin.isSensor = true
  17.  
  18. coin:setSequence("idle")
  19. coin:play()
  20.  
  21. local function coinCollision(event)
  22. if event.other.type == "player" and event.target.lock == false then
  23. event.target.lock = true
  24. display.remove(event.target)
  25. _G.player.ammo = _G.player.ammo + 1
  26. ammo.text = _G.player.ammo
  27. end
  28. end
  29.  
  30. coin:addEventListener("collision", coinCollision)
  31.  
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement