hi there
i'm very new to Pico8 and just started editing games
How do i add sfx sounds whenever colliding with object? i'm editing fruit drop from Nerdy Teachers, and want to add soundfx when the fruit hit the basket,..
do i have to put the sfx(0) in the
update _init()
update _update()
update _draw()
?
thank you
edit: i manage to trigger soundfx after pasted the soundx(0) before del(fruits,fruit) in the function update
but it seems theres only 1 fruit drop....still figuring out..tq
basket_sprite=1
player_sprite=2
player_x=64
player_y=100
fruits={}
fruit_start=16
fruit_count=6
fruit_interval=16
gravity=1
level=1
points=0
function _init()
for i=1,level do
fruit={
sprite=flr(rnd(fruit_count)+fruit_start),
x=flr(rnd(120)+5),
y=i*(-fruit_interval)
}
add(fruits,fruit)
end
function _init()
end
end
function _update()
if btn(0) then player_x-=2 end
if btn(1) then player_x+=2 end
for fruit in all(fruits) do
fruit.y+=gravity
if fruit.y+4>=player_y-8
and fruit.y+4<=player_y
and fruit.x+4>=player_x
and fruit.x+4<=player_x+8 then
points+=1
sfx(0)
del(fruits,fruit)
end
if fruit.y>100 then
del(fruits,fruit)
end
end
if #fruits==0 then
level+=1
_init()
end
end
function _draw()
cls()
rectfill(0,108,127,127,3)
spr(player_sprite,player_x,player_y)
spr(basket_sprite,player_x,player_y-8)
for fruit in all(fruits) do
spr(fruit.sprite,fruit.x,fruit.y)
end
print("score= "..points)
end
[Please log in to post a comment]