kupo nice now
bow nice aim nice arrow nice all nice
This commit is contained in:
@@ -6,12 +6,15 @@ function Entity:New(x,y)
|
||||
o.pos = {x = x, y = y}
|
||||
o.vel = {x = 0, y = 0}
|
||||
o.class = "Entity"
|
||||
o.anim_subframe = 0
|
||||
o.anim_frame = 0
|
||||
o.anim_imgs = {}
|
||||
o.offset = {x = 0, y = 0}
|
||||
o.scale = {x = 1, y = 1}
|
||||
o.flip = { x = 1, y = 1}
|
||||
o.anim = {}
|
||||
o.anim.subframe = 0
|
||||
o.anim.frame = 1
|
||||
o.anim.imgs = {}
|
||||
o.animations = {}
|
||||
o.sprite_offset = {x = 0, y = 0}
|
||||
o.sprite_scale = {x = 1, y = 1}
|
||||
o.sprite_rotation = math.rad(0)
|
||||
o.sprite_flip = { x = 1, y = 1}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
@@ -23,52 +26,128 @@ end
|
||||
|
||||
function Entity: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)) * game.scale
|
||||
local origin_compensation_y = - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * game.scale
|
||||
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,
|
||||
self.pos.x - Camera.pos.x + self.offset.x * game.scale * self.scale.x * self.flip.x,
|
||||
self.pos.y - Camera.pos.y + self.offset.y * game.scale * self.scale.y * self.flip.y,
|
||||
0,
|
||||
game.scale * self.scale.x * self.flip.x,
|
||||
game.scale * self.scale.y * self.flip.y
|
||||
relative_position_x + origin_compensation_x * dimensions_x,
|
||||
relative_position_y + origin_compensation_y * dimensions_y,
|
||||
self.sprite_rotation,
|
||||
game.scale * self.sprite_scale.x * self.sprite_flip.x,
|
||||
game.scale * 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 Entity:NewAnimation(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,
|
||||
game.scale * sx,
|
||||
game.scale * 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,
|
||||
game.scale * sx,
|
||||
game.scale * sy
|
||||
)
|
||||
end
|
||||
|
||||
function Entity:Animate()
|
||||
if game_paused ~= true then
|
||||
-- try to animate
|
||||
self.anim_subframe = self.anim_subframe + current_dt
|
||||
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
|
||||
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
|
||||
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]
|
||||
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 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
|
||||
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
|
||||
self.anim.path = anim.path
|
||||
self.anim.frames = anim.frames
|
||||
self.anim.speed = anim.speed
|
||||
end
|
||||
|
||||
self.anim_imgs = anim.imgs
|
||||
self.anim.imgs = anim.imgs
|
||||
end
|
||||
end
|
||||
|
||||
require "data/scripts/entities/kupo"
|
||||
require "data/scripts/entities/arrow"
|
||||
require "data/scripts/entities/player"
|
||||
|
||||
Reference in New Issue
Block a user