add buy mecanism

This commit is contained in:
Fabien Freling 2019-04-28 14:49:45 +02:00
parent 6c380461bb
commit c637fceca7

View file

@ -11,14 +11,14 @@ h=136
mh=h/s mh=h/s
GameState = { start=0, game=1, gameover=2, market=3 } GameState = { start=0, game=1, gameover=2, market=3 }
currentState = GameState.start currentState = GameState.game
life=100 life=100
coinBlue=0 coinBlue=5
valueBlue=1.0 valueBlue=1.0
coinRed=0 coinRed=2
valueRed=1.0 valueRed=5.0
coinYellow=0 coinYellow=21
valueYellow=1.0 valueYellow=0.8
MarketOptions = { blue=0, red=1, yellow=2, all=3, done=4 } MarketOptions = { blue=0, red=1, yellow=2, all=3, done=4 }
marketSelection = MarketOptions.blue marketSelection = MarketOptions.blue
@ -225,14 +225,14 @@ function drawMarket()
spr(81,4*s,6*s,0) spr(81,4*s,6*s,0)
print("x"..coinRed,5*s+4,6*s+2) print("x"..coinRed,5*s+4,6*s+2)
print("x"..valueRed,8*s+4,6*s+2,12) 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) spr(83,15*s,6*s,0)
print("Buy",20*s,6*s+2) print("Buy",20*s,6*s+2)
spr(82,4*s,8*s,0) spr(82,4*s,8*s,0)
print("x"..coinYellow,5*s+4,8*s+2) print("x"..coinYellow,5*s+4,8*s+2)
print("x"..valueYellow,8*s+4,8*s+2,14) 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) spr(83,15*s,8*s,0)
print("Buy",20*s,8*s+2) print("Buy",20*s,8*s+2)
@ -264,6 +264,7 @@ function draw(state)
elseif currentState == GameState.game then elseif currentState == GameState.game then
drawGame() drawGame()
elseif currentState == GameState.market then elseif currentState == GameState.market then
drawGame()
drawMarket() drawMarket()
elseif currentState == GameState.gameover then elseif currentState == GameState.gameover then
drawGameOver() drawGameOver()
@ -315,9 +316,26 @@ function updateMarket()
marketSelection = marketSelection + 1 marketSelection = marketSelection + 1
end end
elseif btnp(4) then -- A (Z key) 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 currentState = GameState.game
end end
life=math.min(life,100)
elseif btnp(5) then -- B (X key) elseif btnp(5) then -- B (X key)
currentState = GameState.game currentState = GameState.game
end end