uh yeah i keep forgetting ab pushing these. sorry.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
Entity = {
|
||||
}
|
||||
Entity = {class = "Entity"}
|
||||
|
||||
function Entity:New(x,y)
|
||||
o = {}
|
||||
@@ -8,14 +7,14 @@ function Entity:New(x,y)
|
||||
|
||||
o.boxCollision = {
|
||||
from = {x = x, y = y},
|
||||
to = {x = x, y = y}
|
||||
to = {x = x, y = y},
|
||||
}
|
||||
|
||||
o.class = "Entity"
|
||||
|
||||
o.target_offset = {x = 0, y = 0}
|
||||
o.sprite_offset = {x = 0, y = 0}
|
||||
o.sprite_scale = {x = 1, y = 1}
|
||||
o.sprite_rotation = math.rad(0)
|
||||
o.sprite_tint = {1,1,1}
|
||||
o.sprite_flip = { x = 1, y = 1}
|
||||
o.illuminated = false
|
||||
|
||||
@@ -24,14 +23,45 @@ function Entity:New(x,y)
|
||||
return o
|
||||
end
|
||||
|
||||
function Entity:centerOffset(animation,x,y)
|
||||
local x = x or 0
|
||||
local y = y or 0
|
||||
self.sprite_offset.x = animation.imgs[1]:getWidth()/2 + x
|
||||
self.sprite_offset.y = animation.imgs[1]:getHeight()/2 + y
|
||||
end
|
||||
|
||||
function Entity:getBoundingBox(animation,left,right,top,bottom)
|
||||
local left = left or 0
|
||||
local right = right or 0
|
||||
local top = top or 0
|
||||
local bottom = bottom or 0
|
||||
self.boxCollision.from.x = -animation.imgs[1]:getWidth()/2 + left
|
||||
self.boxCollision.to.x = animation.imgs[1]:getWidth()/2 + right
|
||||
self.boxCollision.from.y = -animation.imgs[1]:getHeight()/2 + top
|
||||
self.boxCollision.to.y = animation.imgs[1]:getHeight()/2 + bottom
|
||||
end
|
||||
|
||||
function Entity:Draw(animation)
|
||||
local c1, c2, c3, a = love.graphics.getColor()
|
||||
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3])
|
||||
animation:Draw(
|
||||
self.pos.x - Camera.pos.x - ( (self.sprite_offset.x) * math.cos(self.sprite_rotation) - (self.sprite_offset.y) * math.sin(self.sprite_rotation)) * self.sprite_scale.x * self.sprite_flip.x,
|
||||
self.pos.y - Camera.pos.y - ( (self.sprite_offset.x) * math.sin(self.sprite_rotation) + (self.sprite_offset.y) * math.cos(self.sprite_rotation)) * self.sprite_scale.y * self.sprite_flip.y,
|
||||
self.sprite_rotation,
|
||||
self.sprite_scale.x * self.sprite_flip.x,
|
||||
self.sprite_scale.y * self.sprite_flip.y
|
||||
)
|
||||
love.graphics.setColor(c1,c2,c3,a)
|
||||
end
|
||||
|
||||
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
|
||||
function Entity:isCollidingAt(x,y,object)
|
||||
local result = false
|
||||
for _, col in pairs(object) do
|
||||
result = self.pos.x + self.boxCollision.from.x < col.to.x
|
||||
and self.pos.x + self.boxCollision.to.x > col.from.x
|
||||
and self.pos.y + self.boxCollision.from.y < col.to.y
|
||||
and self.pos.y + self.boxCollision.to.y > col.from.y
|
||||
result = x + self.boxCollision.from.x < col.to.x
|
||||
and col.from.x < x + self.boxCollision.to.x
|
||||
and y + self.boxCollision.from.y < col.to.y
|
||||
and col.from.y < y + self.boxCollision.to.y
|
||||
if result == true then break end
|
||||
end
|
||||
return result
|
||||
@@ -39,9 +69,9 @@ end
|
||||
|
||||
function Entity:isCollidingWith(entity)
|
||||
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x
|
||||
and self.pos.x + self.boxCollision.to.x > entity.pos.x + entity.boxCollision.from.x
|
||||
and entity.pos.x + entity.boxCollision.from.x < self.pos.x + self.boxCollision.to.x
|
||||
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y
|
||||
and self.pos.y + self.boxCollision.to.y > entity.pos.y + entity.boxCollision.from.y
|
||||
and entity.pos.y + entity.boxCollision.from.y < self.pos.y + self.boxCollision.to.y
|
||||
end
|
||||
|
||||
function Entity:isCollidingAtAll(x,y)
|
||||
@@ -58,131 +88,8 @@ function Entity:isCollidingAtAll(x,y)
|
||||
return result
|
||||
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))
|
||||
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 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,
|
||||
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/decoration"
|
||||
require "data/scripts/entities/player"
|
||||
require "data/scripts/entities/fairy"
|
||||
|
||||
Reference in New Issue
Block a user