pico-8 apple game

For things like this, what I’d introduce is a score colour variable, which you can change. I’d also create a score colour timer variable, which will be 30.

I imagine you’re printing the score as

print(score,0,0,7) (or another colour)

At the start of the code print

scorecolour=7
scorecolourtimer=0

Then on the update print

scorecolourtimer-=1

if (scorecolourtimer<0)
 scorecolour=7
end

Then when you collect the apple:-

scorecolour=10 -- or any other colour
scorecolourtimer=30

That’s how I would do it

It’s not working, must have misplaced something. Here’s all my code:

function _init()
x=63
y=85
fx=rnd(45) - 85
fy=85
score=0
time=0
reset_apple()
gameover=false
scorecolor=7
scoretimer=30
end

function _update()
–player movement
move_plr()

if not gameover then

scoretimer-=1

if (scoretimer<0) then
scorecolor=7
end

–fox movement
fx=fx+1
reset_fox()
if abs(x-fx)<4 and abs(y-fy)<4 then
score=score-2
end

ay=ay+1
time=time+1
–catch the apple
if abs(x-ax)<4 and abs(y-ay)<4 and randomapple<1.5 then
reset_apple()
score=score+1
scorecolor= 10
scorecolortimer= 30
elseif abs(x-ax)<4 and abs(y-ay)<4 and randomapple>1.5 and randomapple<1.85 then
reset_apple()
score=score+2
scorecolor= 10
scorecolortimer= 30
end

if abs(x-ax)<4 and abs(y-ay)<4 and randomapple>1.85 then
reset_apple()
time=time-450
end

if randomapple>1.5 then
ay=ay+1.08
end

if abs(ay)>120 then
reset_apple()
end
else
end
if time==2970 then
gameover=true
end
end

function _draw()
cls()
map(1)
spr(1,x,y)
spr(as,ax,ay)–apple
spr(8,fx,fy)–fox
print (score,3,2)
print (flr(time/30),118,2)

if gameover==true then
print ("time’s up! score: "..score,24,50,7)
end
end

–reset stuff

function reset_apple()
ax= rnd(120)
ay=-8

randomapple = rnd(2)

if randomapple>1.5 and randomapple<1.85 then
as=3
elseif randomapple>1.85 then
as=7
else
as=2
end
end

function reset_fox()
if fx>200 then
fx=rnd(45) - 85
end
end

Now I want to do the same thing for the timer when you catch a clock (have the time flash green for a second).

But it stays green rather than going back to white like I want it to. Here’s what I did.

Init:

Time=0

Timecolor=7

Update:

If abs(x-ax)<4 and abs(y-ay)<4 and randomapple>1.85 then

Reset_apple()

Time=time-450

Timecolor=11

End

Draw:

Print(flr(time/30),118,2,timecolor)

The next thing to do is limit the time the bucket can hover. Otherwise a player can just hold x and avoid the fox the whole time. Hmm… I’m not sure where to start with that.

Almost done! Just trying to figure out how to make a sound effect (a very short tune) play only once when gameover = true. The current code is calling it every frame and making it sound like a continuous buzz.