From 3ecd48d11d57f07a1fd369caaec567f7cdeb6fac Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 28 Apr 2019 19:26:03 +0200 Subject: [PATCH] remember time alive --- right_coin.lua | 61 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/right_coin.lua b/right_coin.lua index 4c307ae..94d6dd2 100644 --- a/right_coin.lua +++ b/right_coin.lua @@ -21,6 +21,7 @@ coinYellow=0 valueYellow=0.8 MarketOptions = { blue=0, red=1, yellow=2, all=3, done=4 } marketSelection = MarketOptions.blue +secondsAlive=0 solids={} do @@ -248,6 +249,8 @@ function drawStart() print("You're dying, and medicine",130,40,15,false,1,true) print("ain't cheap. Exchange your",130,50,15,false,1,true) print("most valuable coins for life.",130,60,15,false,1,true) + print("The market will dictate how",130,70,15,false,1,true) + print("much medicine you can buy.",130,80,15,false,1,true) if t%60 > 20 then print("Press Z to start",75,100) end @@ -255,9 +258,26 @@ function drawStart() end function drawGameOver() - cls(1) - print("You died",80,36,6) - print("Press Z",75,96,15) + cls(0) + map(0,17,30,17) + + -- Time alive + local minutes = secondsAlive // 60 + local seconds = secondsAlive % 60 + + print("You ran out of time",70,36,6) + if minutes == 0 then + print("You survived for "..seconds.." seconds.",70,50) + elseif minutes == 1 then + print("You survived for "..minutes.." minute",70,50) + print("and "..seconds.." seconds.",70,64) + else + print("You survived for "..minutes.." minutes",70,50) + print("and "..seconds.." seconds.",70,64) + end + if t%120 > 20 then + print("Press Z",100,100) + end end function drawGame() @@ -283,6 +303,15 @@ function drawGame() print(valueBlue,190,2,8) print(valueRed,206,2,12) print(valueYellow,222,2,14) + + -- Time alive + local minutes = secondsAlive // 60 + local seconds = secondsAlive % 60 + if minutes == 0 then + print("Time: "..seconds.." sec", 8, 16) + else + print("Time: "..minutes.." min "..seconds.." sec", 8, 16) + end end function drawLife(x,y,next) @@ -422,6 +451,8 @@ 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() end @@ -445,9 +476,12 @@ function updateGame() currentState = GameState.gameover return end - if t%20 ==0 then + if t%20 == 0 then life=life-1 end + if t%60 == 0 then + secondsAlive = secondsAlive + 1 + end p:direct() p:update() @@ -537,6 +571,21 @@ end -- 086:3333333300000000000000000000000000000000000000000000000033333333 -- 096:7773377777733377777333373333333333333333777333377773337777733777 -- 097:0006660000660000066000000660000006600000066000000066000000066600 +-- 192:0000000000000000000000000000000000000000000000000000000000000003 +-- 193:0000000000000000000033370033377703377777337777773377777737777777 +-- 194:0000000000000000777770007777777077777777777777777777777777777777 +-- 195:0000000000000000000000000000000000000000700000007700000077700000 +-- 208:0000000300000033000003330000033700000337000003370000033700000337 +-- 209:3777777777777777777777777777733377773333777333337733377377337773 +-- 210:7777777777777733777773337777733737337337373373333733733337337337 +-- 211:7770000037770000337700007377000073770000337700003777000077770000 +-- 224:0000033700000337000003370000033700000337000003370000033700000337 +-- 225:7733777377333333773333377733733377337733773377777777777777777777 +-- 226:3733733777337337773377777733777737777777777777777777777777777777 +-- 227:7777000077770000777700007777000077770000777700007770000077000000 +-- 240:0000033700000337000003370000033700000337000000000000000000000000 +-- 241:7777777777777777777777707777000000000000000000000000000000000000 +-- 242:7777777077770000000000000000000000000000000000000000000000000000 -- -- @@ -582,6 +631,10 @@ end -- 014:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 015:110000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- 016:112020202020202020202020202020202020202020202020202020202011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +-- 021:00000c1c2c3c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +-- 022:00000d1d2d3d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +-- 023:00000e1e2e3e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +-- 024:00000f1f2f3f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -- --