pico-8 apple game part 2

My old thread about my apple game was starting to feel cluttered, so I’ve made a new one. I’m almost finished, but there’s just one problem. I want a sound effect to play just once when the bucket (player sprite) hits the ground. The code below causes the sound effect to play over and over as long as the bucket is at y=85 (the ground). I think the solution might have to do with making a new boolean or state, but I could use some guidance.

 --enter hover
 if btnp(❎) and hover<=0 then
  hover = hover_max
  y=75
 --stay hovered, count down 
 elseif btn(❎) and (hover >0) then
  hover-=1
  y=75
 --land 
 else
  hover=0
  y=85
  sfx(05)
 end

I’m also trying this instead (play the sound when the bucket is just an imperceptibly tiny bit above ground and looks like it has landed), but keep getting syntax errors.

if hover-=0.1 then
  sfx(05)
 end

Yeah you’ll want a boolean check to see if it’s been played, and then reset it when the bucket leaves the ground again. Probably give yourself a bit of a margin so if the bucket twitches 1px for some reason it doesnt just trigger the sound over and over.

Thought so. Still learning the syntax, so can you show me how that might look with my existing code? I have put sound_played=false in init, and added this code:

if hover-=1 and y=85 then
  sfx(05)
  sound_played=true
 end

but I’m getting a syntax error and I think I’m missing something too.

Sorry on my phone currently so not the easiest… this might give you the jist of it?

Hmm… I just tried that but I’m not hearing the sound when the bucket lands.

Do you have the variable set to false to start with?

Yes, it’s set to false in init. Do I need another else statement maybe?

Wait, maybe not. Tried this and it plays continuously.

if sound_played == false then
   sound_played = true
   sfx(05)
   else sound_played = false
   end

Hmm… is there a way I could tell Pico-8 to play the sound when Y goes from 84 to 85?

I don’t use PICO-8, but you seem to be telling it to set the variable to false if it’s NOT set to false. If the code is running on a loop, when it runs again, it’ll return false and play the sound again.

You could just make it so that it does nothing if sound_played is not false. Then you could change it back to false at some other point. If this is a “game over” scenario, you could just set the variable to false when the player restarts.

I’m super sick right now so I don’t know if this makes sense haha.

It’s not game over; I just want the player sprite (a bucket) to make a little sound whenever it lands on the ground.

Just trying to get my head around how to type it out…

In that case, I’d probably just set that particular code to do nothing if the variable is not false. Then, I’d have some other place on the code where I’d change the variable back to false once the bucket is placed somewhere else.

Edit: oops, sorry, that’s unhelpful. Maybe set it to false within the “enter hover state” section?

Actually, your solution worked great. I’d forgotten to add a line and didn’t realize. Oops. Thanks!

1 Like

@ritual

I tried to do the same thing for another sound effect at game over, with outro_played = false in init. Still getting the continuous droning. What have I done wrong?

if gameover==true then
  outro_played= false
  print ("time's up! \npress ❎ to restart \nscore: "..score,26,30,7)
  if outro_played==false then
   outro_played=true
   sfx(06)
  end

You’re setting the variable to false then immediately checking if it’s false… so it’ll always be false.

1 Like
if gameover==true then
  print ("time's up! \npress ❎ to restart \nscore: "..score,26,30,7)
  if outro_played==false then
   sfx(06)
   outro_played=true
  end

All fixed!

And… it’s done! Nothing spectacular, but with a ton of help, I made a little game. Yay!:red_apple:

3 Likes

Congratulations on making your game! Programming is not easy and you should be proud of yourself for doing this. Learning in public like this is very intimidating but I think it’s also very rewarding, and this thread is a great example of it going well.

3 Likes

Yes! Cool! Well done… are we going to see a demonstration?

Would I upload it to itch.io to do that? I’ve never uploaded a game before.

Or I guess if I don’t want to publish it, I could host the file on my website and just link it here so anyone who wants to can pop it into pico-8?

I couldn’t use Export to turn it into a png because I used the free Education Edition.

Edit: here it is, hope this works. Download it from here, then load it in pico-8 to play it. (Type LOAD in the console to upload, then ctrl+R to run.)

https://callmemanatee.neocities.org/apple%20game.p8

Adding to this thread yet again because I have a request for someone experienced in pico-8.

I am trying so hard to learn collision, but none of the online tutorials break it down into tiny enough pieces for my squidgy brain to retain much of anything.

I’ve started a new practice game. So far, I have my player (px, py) moving around in 4 directions. And I have some map tiles marked with flag 0. Now I need to turn those flag 0 tiles into walls that my player can’t pass through.

So my request is this: Show me how to do that, in bite sized steps, one reply at a time. Like, smaller steps than you think they need to be. Walk me through the first little line or two of code, before even showing me the second step. Then, when I’m done with the first step (like… using mget to see what tile I’m on, or whatever comes first), I’ll let you know it’s time for the second bit.

Does that make sense? It might be the only way I can learn to make stuff hit walls, without my brain hitting a wall.