function Animation:Draw() if self.sprite ~= nil then local relative_position_x = self.pos.x - Camera.pos.x local relative_position_y = self.pos.y - Camera.pos.y local origin_compensation_x = - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) local origin_compensation_y = - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) local dimensions_x = self.sprite_scale.x * self.sprite_flip.x local dimensions_y = self.sprite_scale.y * self.sprite_flip.y love.graphics.draw( self.sprite, relative_position_x + origin_compensation_x * dimensions_x, relative_position_y + origin_compensation_y * dimensions_y, self.sprite_rotation, self.sprite_scale.x * self.sprite_flip.x, self.sprite_scale.y * self.sprite_flip.y ) if debug_collision then love.graphics.setColor(1, 0, 0) love.graphics.circle( "line", relative_position_x, relative_position_y, 2 ) love.graphics.setColor(0, 1 ,0) love.graphics.circle( "line", relative_position_x + origin_compensation_x * dimensions_x, relative_position_y + origin_compensation_y * dimensions_y, 2 ) end love.graphics.setColor(1, 1 ,1) end end function Animation:New(anim,frames,speed) local anim_data = { frame = 1, subframe = 1, path = anim.path, frames = anim.frames, speed = anim.speed, imgs = anim.imgs } self.animations[#self.animations+1] = anim_data return self.animations[#self.animations] end function DrawAnimationFrame(animation, frame, x, y, rotate, sx, sy) local x = x or 0 local y = y or 0 local sx = sx or 1 local sy = sy or 1 love.graphics.draw( animation.imgs[frame], x - Camera.pos.x, y - Camera.pos.y, rotate, sx, sy ) end function DrawAnimation(animation, x, y, rotate, sx, sy) local x = x or 0 local y = y or 0 local sx = sx or 1 local sy = sy or 1 if game_paused ~= true then -- try to animate animation.subframe = animation.subframe + current_dt if animation.subframe >= animation.speed then animation.frame = animation.frame + 1 animation.subframe = animation.subframe - animation.speed end -- cycle if animation.frame >= animation.frames+1 then animation.frame = animation.frame - animation.frames end end love.graphics.draw( animation.imgs[animation.frame], x - Camera.pos.x, y - Camera.pos.y, rotate, sx, sy ) end function Entity:Animate() if game_paused ~= true and self.anim.path ~= nil then -- try to animate self.anim.subframe = self.anim.subframe + current_dt if self.anim.subframe >= self.anim.speed then self.anim.frame = self.anim.frame + 1 self.anim.subframe = self.anim.subframe - self.anim.speed end -- cycle if self.anim.frame >= self.anim.frames+1 then self.anim.frame = self.anim.frame - self.anim.frames end -- change self.sprite = self.anim.imgs[self.anim.frame] end end function Entity:LoadAnimation(anim,frames,speed) if self.anim.path ~= anim and self.anim.path ~= anim.path then if frames ~= nil and speed ~= nil then self.anim.path = anim or nil self.anim.frames = frames or 4 self.anim.speed = speed or frames else self.anim.path = anim.path self.anim.frames = anim.frames self.anim.speed = anim.speed end self.anim.imgs = anim.imgs end end require "data/scripts/entities/kupo" require "data/scripts/entities/arrow" require "data/scripts/entities/player"