Log In  
Follow
AtticusFinn

Hi everyone,

I made a couple of videos on making Pong in Pico 8 if anyone's interested.

As I mention in the video I don't consider this to be a tutorial really, since I'm new to Pico 8 and programming as a whole but it'd be great to get some feedback!

0 comments



Hi everyone, I'm fairly new to programming and Pico8.

I'm trying to add powerups to one of my games. I've made an empty table and a function to create each powerup within it.
The problem I'm having is that I'd like one single random powerup to be created depending on the score (say when score==5)

I've managed to do this but the problem was that a second powerup gets created before the player has the chance to up the score.
I've tried to use time() and also creating a boolean but I haven't managed to get 1 single powerup on screen at a time, I either get more than one or nothing.

What would be the best way to do this?

here's the code I have at the moment:

function _init()
	score=0
        powerups={}
end

function _update()
        if score==5 then
		powerup=true
	end

	if powerup==true then
		create_powerup()	
	end
end

function _draw()
         for capsule in all(powerups) do
		spr(capsule.sp,capsule.x,capsule.y)
	end
end

--powerups

powerups_start=5
total_powerups=4
fall=1

function create_powerup()	
	capsule={
	sp=powerups_start+flr(rnd(total_powerups)),
	x=flr(rnd(100)+20),
	y=flr(rnd(10))+20
	}
	add(powerups,capsule)

	powerup=false

	if powerup==false then
		del(powerups,capsule)
	end							
end

function update_powerup()
	for capsule in all(powerups) do
		capsule.y+=fall

		if capsule.x>=player.x and
					capsule.x<=player.x+player.w and
					capsule.y==player.y-player.h then
						sfx(2)
					 lives.left+=1
					 del(powerups,capsule)
		end	

		if capsule.y>128 then
			del(powerups,capsule)
		end	
	end
end	

Thanks in advance!

5 comments