uh, a lot happened, i murdered physics code, redesigned tiles & levels, now i need to make another level editor. I'm sorry game. I'm sorry git.

This commit is contained in:
lustlion
2021-11-28 03:38:30 +01:00
parent 8607399d16
commit dd2debc0bd
30 changed files with 701 additions and 693 deletions

View File

@@ -5,6 +5,12 @@ function Entity:New(x,y)
o = {}
o.pos = {x = x, y = y}
o.vel = {x = 0, y = 0}
o.boxCollision = {
from = {x = x, y = y},
to = {x = x, y = y}
}
o.class = "Entity"
o.sprite_offset = {x = 0, y = 0}
@@ -12,13 +18,44 @@ function Entity:New(x,y)
o.sprite_rotation = math.rad(0)
o.sprite_flip = { x = 1, y = 1}
o.illuminated = false
setmetatable(o, self)
self.__index = self
return o
end
function Entity:Move(target, speed) -- target = {tx int, ty int} / speed = int
-- 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
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
and self.pos.x + self.boxCollision.to.x > entity.pos.x + entity.boxCollision.from.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
end
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
end
--[[function Entity:Draw()