local animedragon={}
local image
local x,y
local vy
local vx
local gravity=0
local bounceheight=180
local bounceduration=0.467
local active=false
local screenwidth=1920
local elapsedbouncetime=0
local happyimage
local initialstarttime=0
local switchedtohappyimage=false
local baselineY=879
function animedragon.load()
image=love.graphics.newImage("animedragon.png")
happyimage=love.graphics.newImage("animedragon2.png")
x=-image:getWidth()
y=baselineY-image:getHeight()
vy=0
local totaldistance=screenwidth+2*image:getWidth()
vx=totaldistance/17
end
function animedragon.update(dt,timepassed)
if timepassed>=39.6 and timepassed<=54.62 then
active=true
if initialstarttime==0 then
initialstarttime=timepassed
end
else
active=false
end
if active then
x=x+vx*dt
elapsedbouncetime=(elapsedbouncetime+dt)%bounceduration
local bounceprogress=elapsedbouncetime/bounceduration
local bounceoffset=math.sin(bounceprogress*math.pi)
y=(baselineY-image:getHeight())-bounceoffset*bounceheight
if timepassed>=initialstarttime+7.465 and not switchedtohappyimage then
image=happyimage
switchedtohappyimage=true
end end end
function animedragon.draw()
if active then
love.graphics.draw(image,x,y)
end end
return animedragon
