function make_sprite(x, y, anim, speed) s = { x=x, y=y, anim=animations[anim], speed=speed, frame=0, last_update=t(), flip_x=false, flip_y=false, loop=false, } return s end function update_sprite(s) local now = t() if s.last_update == 0 then s.last_update = now return end if s.speed != 0 then if now - s.last_update > s.speed then s.frame += 1 s.last_update = now if s.frame > #s.anim.frames then if s.loop then s.frame = 0 else s.speed = 0 s.frame = #s.anim.frames end end end end end function draw_sprite(s) spr(s.anim.frames[s.frame], s.x, s.y, s.anim.w, s.anim.h, s.flip_x, s.flip_y) end