Log In  

Hi, i'm new to pico 8 programming so i was trying to redo the pong game from the pico-zine 1! I understood almost all the code (minus the collision stuff) and i was trying to make the game restart when pressing a specific button (for example X). I tried "while btnp(5) == 1 do" but it isn't working as inteded.. What i'm missing is a way to hang the game until the button is pressed and how to restart the game completely... This is the cart i'm working at atm (i commented the broken function)

Cart #46576 | 2017-11-22 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Thanks!

P#46577 2017-11-22 10:49 ( Edited 2017-11-24 22:55)

You need some form of state machine, eg:

  • variable(s) to hold state
  • action to transition from one state to another

Pseudo code with a single ‘game_over’ state:

local game_over=false
function _update()
 if ... player lost ...  then
  game_over=true
  ... other state change as need like switch current screen to welcome screen ...
 end
 if game_over==true and btnp(5) then
  game_over=false
  ... reset player lives, score, enable game screen...
 end
end
P#46589 2017-11-22 14:54 ( Edited 2017-11-22 19:54)

Thanks freds72! I had to make some IFs in the _draw() function too, is that the "correct" way of doing so? Because if i tried to RECTFILL or PRINT in the _update function it didn't show anything (i'm assuming because it's refreshed too fast?).. Besides, if i wanted to make a simple menu, should i write some IFs in the _draw() function? Like

menu = 1
if menu then
 --PRINT THE MENU
end

if menu == 0 then
 --start the game
end
P#46617 2017-11-23 05:22 ( Edited 2017-11-23 10:22)

You got it. Key aspect is to change state only in update and use state in draw (e.g. ‘if’ in draw is normal!)

P#46629 2017-11-23 12:51 ( Edited 2017-11-23 17:51)

Thanks a lot! Can you actually recommend me some nice PICO tutorials? I read the PICO-zines and it feels like it goes from "hello world" to something very difficult rather quickly... Thanks a lot again!

P#46637 2017-11-23 16:20 ( Edited 2017-11-23 21:20)

Hu...I got 20+ years of programming under the belt, so no real need of tutorials :]
Seriously, get back to the basics, e.g. generic programming tutorial. Get a firm grasp of data structures, control flow... and experiment "theory" with some basic pico-8 demo.

P#46667 2017-11-24 17:55 ( Edited 2017-11-24 22:55)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 15:42:05 | 0.013s | Q:26