Heart Score
code:
tab 0:
player = {}
player.x=40
player.y=40
player.size=4
player.lives=3
player.speed=2
player.score=0
player.maxscore=0
dots={}
numdots=1
poke(0x5f2d,1)
lastm={}
lastm.x=0
lastm.y=0
usingmouse=false
lasttime=time()
musicplaying=false
function _init()
cls(0)
while(time() < 5) and not btn(4) and not btn(5) do
print("collect energy spheres", 20, 60, 7)
print("to your heart!",24,70, 7)
if(flr(time()*10)%2==1) then
print("power",34,70,10)
else
print("power",34,70,7)
end
print("press ❎ to toggle mouse control", 0, 100, 7)
end
lasttime=time()
for x=1, numdots do
add(dots, makedot())
end
end
function _update()
if (player.lives!=0) then
if(time()-lasttime > (numdots*numdots)+4)then
numdots+=1
add(dots, makedot())
end
if(btnp(5))then
usingmouse=not usingmouse
lastm.x=stat(32)
lastm.y=stat(33)
end
if usingmouse then mouse()
else controls()
end
bounds()
for i in all(dots) do
i=checkdot(i)
end
else
if not musicplaying then
sfx(2, 1)
musicplaying=true
end
player.maxscore=max(player.score,player.maxscore)
if btn(4) then
sfx(4, 1)
player.lives=3
player.score=0
numdots=1
for i in all(dots) do
del(dots, i)
end
add(dots, makedot())
lasttime=time()
musicplaying=false
end
end
end
function _draw()
if(player.lives!=0) then
cls(12)
for i in all(dots) do
circfill(i.x,i.y,2,i.colour)
end
spr(1, player.x, player.y)
print(player.score, 12, 3, 15)
print("lives:"..player.lives, 90, 3, 15)
if(usingmouse)then rect(stat(32)-1, stat(33)-1, stat(32)+1, stat(33)+1, 2)
end
else
cls(0)
print("game over", 40, 16, 7)
print("game over", 40, 10, 2)
print("game over", 40, 12, 8)
print("game over", 40, 14, 14)
print("game over", 40, 16, 7)
print("you scored:"..player.score, 32, 80, 2)
print("high score:"..player.maxscore, 32, 90, 2)
print("press 🅾️ to restart",20, 110,2)
spr(2, 54, 50)
end
end
tab1:
function controls()
if btn(0) then
player.x-=player.speed
elseif btn(1) then
player.x+=player.speed
end
if btn(2) then
player.y-=player.speed
elseif btn(3) then
player.y+=player.speed
end
end
function mouse()
x=stat(32) -3
y=stat(33) -4
if(x-player.x<-1) then
player.x-=player.speed
elseif(x-player.x>1) then
player.x+=player.speed
end
if(y-player.y<-1) then
player.y-=player.speed
elseif(y-player.y>1) then
player.y+=player.speed
end
end
function bounds()
if player.x < -1 then
player.x+=player.speed
end
if player.x >121 then
player.x-=player.speed
end
if player.y < -1 then
player.y+=player.speed
end
if player.y >121 then
player.y-=player.speed
end
end
tab2:
function makedot()
d={}
d.x=rnd(122)+3
d.y=rnd(122)+3
d.time = time()
d.colour=7
return d
end
function checkdot(d)
if(time() - d.time) < 3 then
d.colour=7
elseif(time() - d.time) < 5 then
d.colour=10
elseif(time() - d.time) < 7 then
d.colour=9
elseif(time() - d.time) < 9 then
d.colour=8
elseif(time() - d.time) < 12 then
sfx(3)
d.x=rnd(122)+3
d.y=rnd(122)+3
d.colour=7
d.time=time()
player.lives-=1
end
x=abs((player.x+player.size)-d.x)
y=abs((player.y+player.size)-d.y)
if x < (player.size) and
y < (player.size) then
sfx(1)
player.score+=10
d.x=rnd(122)+3
d.y=rnd(122)+3
d.colour=7
d.time=time()
end
return d
end