-abad fall damage, life lost, endgame, reset

This commit is contained in:
2022-11-02 18:55:30 +01:00
parent 8d95eb10e1
commit 823b771c08

View File

@@ -1,7 +1,8 @@
abad={x=40,y=24,flip=false,frame=1,wait=0,hab=10,vides=3,energia=40,step=0,update=nil,jumpfwd=false,anim={0,1,0,2},bb={x=4,y=0,w=8,h=16}}
abad={x=40,y=24,flip=false,frame=1,wait=0,hab=10,vides=3,energia=40,falling=0,step=0,update=nil,jumpfwd=false,anim={0,1,0,2},bb={x=4,y=0,w=8,h=16},safe={hab=10,x=40,y=24}}
function abad_init()
abad={x=40,y=24,flip=false,frame=1,wait=0,hab=10,vides=3,energia=40,falling=0,step=0,draw=abad.draw,update=nil,jumpfwd=false,anim={0,1,0,2},bb={x=4,y=0,w=8,h=16},safe={hab=10,x=40,y=24}}
abad.update=abad_state_normal
abad.objects={}
end
@@ -14,12 +15,48 @@ function abad:draw()
sspr(abad.frame*16,0,16,16,abad.x,abad.y,16,16,flip)
end
function abad_make_safe()
if abad.safe.hab~=abad.hab then
abad.safe.hab=abad.hab
abad.safe.x=abad.x
abad.safe.y=abad.y
cls(4)
end
end
function abad_hurt(howmuch)
abad.energia=abad.energia-howmuch
if abad.energia<=0 then
abad.vides=abad.vides-1
if abad.vides==0 then
--final de la partida
dead.start()
else
abad.energia=40
abad.hab=abad.safe.hab
abad.x=abad.safe.x
abad.y=abad.safe.y
cls(3)
end
else
cls(3)
end
end
function abad_state_normal()
abad.frame=0
abad.wait=0
abad.step=0
abad.jumpfwd=false
if abad.falling>0 then
if abad.falling>12 then
abad_hurt(abad.falling-12)
end
abad.falling=0
end
abad_make_safe()
if btn(KEY_RIGHT) then
abad.update=abad_state_walking
abad.flip=false
@@ -109,6 +146,8 @@ function abad_state_walking()
end
end
abad_make_safe()
if btn(KEY_UP) then
abad.update=abad_state_jumping
abad.step=0
@@ -198,6 +237,7 @@ function abad_state_falling()
return
end
abad.y=abad.y+2
abad.falling=abad.falling+1
else
abad.hab=abad.hab+10
imp.reset()