From c637fceca7eea640bd085fbca106711b92157c10 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 28 Apr 2019 14:49:45 +0200 Subject: [PATCH] add buy mecanism --- right_coin.lua | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/right_coin.lua b/right_coin.lua index ad9ff25..59ab259 100644 --- a/right_coin.lua +++ b/right_coin.lua @@ -11,14 +11,14 @@ h=136 mh=h/s GameState = { start=0, game=1, gameover=2, market=3 } -currentState = GameState.start +currentState = GameState.game life=100 -coinBlue=0 +coinBlue=5 valueBlue=1.0 -coinRed=0 -valueRed=1.0 -coinYellow=0 -valueYellow=1.0 +coinRed=2 +valueRed=5.0 +coinYellow=21 +valueYellow=0.8 MarketOptions = { blue=0, red=1, yellow=2, all=3, done=4 } marketSelection = MarketOptions.blue @@ -225,14 +225,14 @@ function drawMarket() spr(81,4*s,6*s,0) print("x"..coinRed,5*s+4,6*s+2) print("x"..valueRed,8*s+4,6*s+2,12) - print("= "..math.floor(coinBlue*valueBlue),12*s,6*s+2) + print("= "..math.floor(coinRed*valueRed),12*s,6*s+2) spr(83,15*s,6*s,0) print("Buy",20*s,6*s+2) spr(82,4*s,8*s,0) print("x"..coinYellow,5*s+4,8*s+2) print("x"..valueYellow,8*s+4,8*s+2,14) - print("= "..math.floor(coinBlue*valueBlue),12*s,8*s+2) + print("= "..math.floor(coinYellow*valueYellow),12*s,8*s+2) spr(83,15*s,8*s,0) print("Buy",20*s,8*s+2) @@ -264,6 +264,7 @@ function draw(state) elseif currentState == GameState.game then drawGame() elseif currentState == GameState.market then + drawGame() drawMarket() elseif currentState == GameState.gameover then drawGameOver() @@ -315,9 +316,26 @@ function updateMarket() marketSelection = marketSelection + 1 end elseif btnp(4) then -- A (Z key) - if marketSelection == MarketOptions.done then + if marketSelection == MarketOptions.blue then + life = life + math.floor(coinBlue*valueBlue) + coinBlue=0 + elseif marketSelection == MarketOptions.red then + life = life + math.floor(coinRed*valueRed) + coinRed=0 + elseif marketSelection == MarketOptions.yellow then + life = life + math.floor(coinYellow*valueYellow) + coinYellow=0 + elseif marketSelection == MarketOptions.all then + life = life + math.floor(coinBlue*valueBlue) + life = life + math.floor(coinRed*valueRed) + life = life + math.floor(coinYellow*valueYellow) + coinBlue=0 + coinRed=0 + coinYellow=0 + elseif marketSelection == MarketOptions.done then currentState = GameState.game end + life=math.min(life,100) elseif btnp(5) then -- B (X key) currentState = GameState.game end