Log In  


Hi. I'm new to PICO-8 and programming in general.

I followed the guide for Squasy in the first issue of the fanzine. After that, I decided that I wanted to try and add a few stuff. I managed to limit the paddle to the inside of the screen and was able to add a menu screen (with some tutorial help). My problem is that for some reason, the game over screen doesn't work. Not sure what I'm doing wrong.

My idea is to display the game over screen if lives==0.

Here is the code to see if lives==0:
function losedeadball()
if bally>128-ballsize then
if lives>0 then
sfx(3)
bally=64
ballx=64
lives-=1
else
ballydir=0
ballxdir=0
bally=64
ballx=64
sfx(4)
over_init()
end
end
end

The idea is that the over_init() sets the game state=3 and the displays the game over screen. Here is the game over screen code:
--initiliaze game over screen--
function over_init()
state=3
end

--restart button--
function over_update()
if(btnp(❎)) menu_init()
end

--draws game over screen--
function over_draw()
cls()
rectfill(0,0,128,128,3)
print("game over!",44,58,15)
print("press ❎ to play again.",18,66,15)
end

I'm not sure what I'm doing wrong here. I used the same logic to switch from the menu to the game itself. Can anyone please tell me where to problem is? I've been trying to figure this out for over two hours and an completely stumped.

I also added the cart if that would be more usefull. Sorry for the weird name. I just choose a random ID since I'm going to delete the cart later.

Cart #hesubozeku-0 | 2025-03-25 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA



in game_update and in game_draw you are doing something weird :
instead of updating the game or drawing the game, you are creating new versions of _update and _draw.
These noew versions will be called by pico-8, so the game will be propperly updated and drawn, but these version do not check the state variable, so you're effectivelu stuck in game mode.

just do the game update in game_update, and the game drawing in game_draw.

--updates game funtion--
function game_update()
   movepaddle()
   moveball()
   bounceball()
   bouncepaddle()   
   losedeadball()
end

--draws game funtion--   
function game_draw()
     rectfill(0,0,128,128,3) 
     for i=1,lives do
            spr(001, 90+i*8, 4)
      end
      print(score,12,6,15)
     rectfill(padx,pady,padx+padw,pady+padh,15)
     circfill(ballx,bally,ballsize,15)
end    

Ah ok. Thank you for the help. I appreciate it. I got confused when the two tutorials used different versions of _update and _draw so I just used both. Typing it out, it doesn't make the a whole lot of sense. Refer back to the "beginner" part I mentioned.


No problem, asking is a great way to learn. You can change the post category from cartridge to question/bug, and also tag it as resolved. This way it won't show in splore, and will not take time from other helpers.



[Please log in to post a comment]