From d068315fffce63e01d263ab6a3e2451a42a4dc23 Mon Sep 17 00:00:00 2001 From: Pascal Batty Date: Mon, 29 Apr 2019 13:35:04 +0200 Subject: [PATCH] set initial game state --- right_coin.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/right_coin.lua b/right_coin.lua index b117108..1677c0b 100644 --- a/right_coin.lua +++ b/right_coin.lua @@ -166,6 +166,13 @@ do -- Player local accel=0.3 local decel=0.5 + function Player:new(o) + o = o or {} + self.__index = self + setmetatable(o, self) + return o + end + function Player:direct() if btn(2) then self:goLeft() @@ -494,14 +501,24 @@ function draw(state) end end +function setInitialGameState() + p=Player:new() + t=0 + secondsAlive=0 + life=100 + dropInitialCoins() + sickCounter=20 -- how many seconds before the sickness get stronger? + sickLapse=20 -- how many ticks before the life decreases? + coinBlue=0 + coinRed=0 + coinYellow=0 +end + function update(state) if currentState == GameState.start then if btnp(4) then -- A (Z key) currentState = GameState.game - t=0 - secondsAlive=0 - life=100 - dropInitialCoins() + setInitialGameState() end elseif currentState == GameState.game then updateGame()