From a1ce249e00a43d5f7df64468143c2f6de299a7c8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 May 2019 19:46:13 +0200 Subject: [PATCH] module/world: take coin when the player collide to it --- examples/gameplay/plateform/actors/coin.lua | 4 ++++ examples/gameplay/plateform/actors/player.lua | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/examples/gameplay/plateform/actors/coin.lua b/examples/gameplay/plateform/actors/coin.lua index a4bdaa2..4e718e2 100644 --- a/examples/gameplay/plateform/actors/coin.lua +++ b/examples/gameplay/plateform/actors/coin.lua @@ -6,4 +6,8 @@ function Coin:new(world, x, y) self:setSprite("coin") end +function Coin:takeCoin(other) + self:destroy( ) +end + return Coin diff --git a/examples/gameplay/plateform/actors/player.lua b/examples/gameplay/plateform/actors/player.lua index f96059c..f519d12 100644 --- a/examples/gameplay/plateform/actors/player.lua +++ b/examples/gameplay/plateform/actors/player.lua @@ -51,4 +51,11 @@ function Player:setDirection(direction) end end +function Player:collisionResponse(collision) + if collision.other.type == "coin" then + collision.other:takeCoin(self) + end +end + + return Player