--Funciones!!!

function generar_escenario()
for i=1,#inf do
sup[i]={x=inf[i].x,y=inf[i].y-10,w=inf[i].w,h=1}

der[i]={x=inf[i].x+inf[i].w-1,y=inf[i].y-9,w=1,h=9}

izq[i]={x=inf[i].x,y=inf[i].y-9,w=1,h=9}

end
end

function perder()
pierdes:play(2)
DKGAME(true)
end

y=270
function animacion_donkey()
y=y-1
if y<10 then menu() end
if anim:time()<500 then dsprites_dk[1]:blit(350,y) end
if anim:time()>500 then dsprites_dk[2]:blit(350,y) end
if anim:time()>1000 then anim:reset() end
end

function animacion_donkey2()
if d.t:time()>10 and d.t:time()<150 then d.sprites_dk=dki[1] end
if d.t:time()>150 and d.t:time()<300 then d.sprites_dk=dki[2] end
if d.t:time()>300 and d.t:time()<450 then d.sprites_dk=dki[3] end

if d.t:time()>450 then d.t:reset() end
end

function barriles()
for i=1,30 do
if b[i].t:time()<300 then
if girar:time()>10 and  girar:time()<200 then b[i].i=bar[1] end
if girar:time()>200 and  girar:time()<400 then b[i].i=bar[2] end
if girar:time()>400 and  girar:time()<600 then b[i].i=bar[3] end
if girar:time()>600 and  girar:time()<800 then b[i].i=bar[4] end
if girar:time()>800 then girar:reset() b[i].i=bar[1] end
end
end
end

function caminando()
if jump.d=="der" then 
if movimiento_d:time()>10 and movimiento_d:time()<250 then jump.i=sprites_dk[2] end
if movimiento_d:time()>250 and movimiento_d:time()<500 then jump.i=sprites_dk[3] end
if  movimiento_d:time()>500 then movimiento_d:reset() jump.i=sprites_dk[2] end
end
if jump.d=="izq" then 
if movimiento_d:time()>10 and movimiento_d:time()<250 then jump.i=sprites_dk[5] end
if movimiento_d:time()>250 and movimiento_d:time()<500 then jump.i=sprites_dk[6] end
if  movimiento_d:time()>500 then movimiento_d:reset() jump.i=sprites_dk[5] end
end
if jump.d=="aba" then 
if movimiento_d:time()>10 and movimiento_d:time()<250 then jump.i=sprites_dk[7] end
if movimiento_d:time()>250 and movimiento_d:time()<500 then jump.i=sprites_dk[8] end
if  movimiento_d:time()>500 and movimiento_d:time()<750 then jump.i=sprites_dk[9] end
if  movimiento_d:time()>750 then movimiento_d:reset() jump.i=sprites_dk[7] end
end
end

function saltar()
if jump.t:time()>10 then flying=true end
if jump.t:time()>10 and jump.t:time()<500 then
if jump.d=="der" then jump.x=jump.x+0.2 jump.y=jump.y-1.2 end
if jump.d=="izq" then jump.x=jump.x-0.2 jump.y=jump.y-1.2 end
if jump.d=="" then  jump.y=jump.y-1.5 end
end

if jump.t:time()>500 and jump.t:time()<1000 then
if jump.d=="der" then jump.x=jump.x+1.1 jump.y=jump.y-0.85 end
if jump.d=="izq" then jump.x=jump.x-1.1 jump.y=jump.y-0.85 end
if jump.d=="" then  jump.y=jump.y-0.9 end
end

if jump.t:time()>1000 and jump.t:time()<1500 then
if jump.d=="der" then jump.x=jump.x+1.1 jump.y=jump.y+0.85 end
if jump.d=="izq" then jump.x=jump.x-1.1 jump.y=jump.y+0.85 end
if jump.d=="" then  jump.y=jump.y+0.9 end
end

if jump.t:time()>1500 and jump.t:time()<2000 then
if jump.d=="" then  jump.y=jump.y+1.5 end
if jump.d=="der" then jump.x=jump.x+0.6 jump.y=jump.y+1.2 end
if jump.d=="izq" then jump.x=jump.x-0.6 jump.y=jump.y+1.2 end
end

if jump.t:time()>2000 then jump.d=jump.d2 jump.t:reset() jump.t:stop() end
end


function presentacion()
anim:start()  
liberar(8)
while true do
controls.read()
creditos:blit(0,0)
animacion_donkey()
screen.flip()
end
end

function rescate()
if col(jump,princesa) then 
if nivel_actual<5 then
ganas:play(3)
nivel_actual=nivel_actual+1 
DKGAME(true)
else 
score=300-math.floor(tiempo_juego:time()/1000)
sistema()
end

end
if princesa.t:time()<500 then peach[1]:blit(princesa.x,princesa.y) end
if princesa.t:time()>500 and princesa.t:time()<700 then peach[2]:blit(princesa.x,princesa.y) end
if princesa.t:time()>700 then peach[3]:blit(princesa.x,princesa.y) end
if princesa.t:time()>900 then princesa.t:reset() end
end
