you can now collect the coins
This commit is contained in:
parent
12365663e2
commit
1a92ebe2aa
|
@ -50,7 +50,14 @@ function drawActor(self)
|
||||||
self.spr=self.ani[(((t)//3)% #self.ani)+1]
|
self.spr=self.ani[(((t)//3)% #self.ani)+1]
|
||||||
local flip
|
local flip
|
||||||
if self.isFlipped then flip = 1 else flip = 0 end
|
if self.isFlipped then flip = 1 else flip = 0 end
|
||||||
spr(self.spr, self.x, self.y, 1, 1, flip)
|
spr(self.spr, self.x, self.y, 0, 1, flip)
|
||||||
|
end
|
||||||
|
|
||||||
|
function hitTest(rect1, rect2)
|
||||||
|
return rect1.x < rect2.x + rect2.w
|
||||||
|
and rect1.x + rect1.w > rect2.x
|
||||||
|
and rect1.y < rect2.y + rect2.h
|
||||||
|
and rect1.y + rect1.h > rect2.y
|
||||||
end
|
end
|
||||||
|
|
||||||
colors={"blue","red","yellow"}
|
colors={"blue","red","yellow"}
|
||||||
|
@ -121,6 +128,7 @@ function addRandomCoin()
|
||||||
newCoin.y=loc.y
|
newCoin.y=loc.y
|
||||||
coins[#coins + 1]=newCoin
|
coins[#coins + 1]=newCoin
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MOCK
|
-- MOCK
|
||||||
addRandomCoin()
|
addRandomCoin()
|
||||||
addRandomCoin()
|
addRandomCoin()
|
||||||
|
@ -152,6 +160,7 @@ do -- Player
|
||||||
self:resolve()
|
self:resolve()
|
||||||
self.x = self.x + self.vx
|
self.x = self.x + self.vx
|
||||||
self.y = self.y + self.vy
|
self.y = self.y + self.vy
|
||||||
|
self:collectCoin()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:resolve()
|
function Player:resolve()
|
||||||
|
@ -198,6 +207,18 @@ do -- Player
|
||||||
return y
|
return y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Player:collectCoin()
|
||||||
|
for i,v in pairs(coins) do
|
||||||
|
if hitTest(self, v) then
|
||||||
|
table.remove(coins,i)
|
||||||
|
if v.color == "blue" then coinBlue=coinBlue+1
|
||||||
|
elseif v.color == "red" then coinRed=coinRed+1
|
||||||
|
elseif v.color == "yellow" then coinYellow=coinYellow+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Player:draw()
|
function Player:draw()
|
||||||
drawActor(self)
|
drawActor(self)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue