2022-01-17 23:14:54 +00:00
|
|
|
Entity = {class = "Entity"}
|
2021-10-25 23:19:22 +00:00
|
|
|
|
|
|
|
function Entity:New(x,y)
|
|
|
|
o = {}
|
|
|
|
o.pos = {x = x, y = y}
|
|
|
|
o.vel = {x = 0, y = 0}
|
2021-11-28 02:38:30 +00:00
|
|
|
|
|
|
|
o.boxCollision = {
|
|
|
|
from = {x = x, y = y},
|
2022-01-17 23:14:54 +00:00
|
|
|
to = {x = x, y = y},
|
2021-11-28 02:38:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 23:14:54 +00:00
|
|
|
o.target_offset = {x = 0, y = 0}
|
2021-10-25 23:19:22 +00:00
|
|
|
o.sprite_offset = {x = 0, y = 0}
|
|
|
|
o.sprite_scale = {x = 1, y = 1}
|
|
|
|
o.sprite_rotation = math.rad(0)
|
2022-01-17 23:14:54 +00:00
|
|
|
o.sprite_tint = {1,1,1}
|
2022-01-19 22:29:02 +00:00
|
|
|
o.sprite_alpha = 1
|
2021-10-25 23:19:22 +00:00
|
|
|
o.sprite_flip = { x = 1, y = 1}
|
2021-10-27 09:06:08 +00:00
|
|
|
o.illuminated = false
|
2021-11-28 02:38:30 +00:00
|
|
|
|
2021-10-25 23:19:22 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
2022-01-19 22:29:02 +00:00
|
|
|
|
2021-10-25 23:19:22 +00:00
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
2022-01-17 23:14:54 +00:00
|
|
|
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()
|
2022-01-19 22:29:02 +00:00
|
|
|
love.graphics.setColor(self.sprite_tint[1],self.sprite_tint[2],self.sprite_tint[3],self.sprite_alpha)
|
2022-01-17 23:14:54 +00:00
|
|
|
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
|
|
|
|
|
2021-11-28 02:38:30 +00:00
|
|
|
-- 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
|
2022-01-17 23:14:54 +00:00
|
|
|
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
|
2021-11-28 02:38:30 +00:00
|
|
|
if result == true then break end
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
function Entity:isCollidingWith(entity)
|
|
|
|
return self.pos.x + self.boxCollision.from.x < entity.pos.x + entity.boxCollision.to.x
|
2022-01-17 23:14:54 +00:00
|
|
|
and entity.pos.x + entity.boxCollision.from.x < self.pos.x + self.boxCollision.to.x
|
2021-11-28 02:38:30 +00:00
|
|
|
and self.pos.y + self.boxCollision.from.y < entity.pos.y + entity.boxCollision.to.y
|
2022-01-17 23:14:54 +00:00
|
|
|
and entity.pos.y + entity.boxCollision.from.y < self.pos.y + self.boxCollision.to.y
|
2021-11-28 02:38:30 +00:00
|
|
|
end
|
2021-10-25 23:19:22 +00:00
|
|
|
|
2021-11-28 02:38:30 +00:00
|
|
|
function Entity:isCollidingAtAll(x,y)
|
|
|
|
local result = false
|
|
|
|
if not result then
|
|
|
|
result = self:isCollidingAt(x,y,objects.collisions)
|
|
|
|
end
|
|
|
|
if not result then
|
|
|
|
result = self:isCollidingAt(x,y,objects.ladders)
|
|
|
|
end
|
|
|
|
if not result then
|
|
|
|
result = self:isCollidingAt(x,y,objects.platforms)
|
|
|
|
end
|
|
|
|
return result
|
2021-10-25 23:19:22 +00:00
|
|
|
end
|
|
|
|
|
2022-01-19 22:29:02 +00:00
|
|
|
function Entity:Kill()
|
|
|
|
if self.id ~= nil then
|
|
|
|
for _, e in pairs(LoadedEntities) do
|
|
|
|
if e.id > self.id then
|
|
|
|
e.id = e.id - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.remove(LoadedEntities,self.id)
|
|
|
|
end
|
|
|
|
self = nil
|
|
|
|
end
|
|
|
|
|
2021-10-25 23:19:22 +00:00
|
|
|
require "data/scripts/entities/kupo"
|
|
|
|
require "data/scripts/entities/arrow"
|
2022-01-17 23:14:54 +00:00
|
|
|
require "data/scripts/entities/decoration"
|
2021-10-25 23:19:22 +00:00
|
|
|
require "data/scripts/entities/player"
|
2022-01-17 23:14:54 +00:00
|
|
|
require "data/scripts/entities/fairy"
|
2022-01-19 22:29:02 +00:00
|
|
|
require "data/scripts/entities/particle"
|