feat: add a very basic shadow system

This commit is contained in:
Kazhnuz 2024-11-02 09:08:04 +01:00
parent bde4808d7b
commit 2083374adc
3 changed files with 39 additions and 1 deletions

View file

@ -68,12 +68,29 @@ function Actor:destroy()
end end
function Actor:draw() function Actor:draw()
self:drawShadow()
self:_drawVisual() self:_drawVisual()
if (self.def.drawHitboxes == true) then if (self.def.drawHitboxes == true) then
self:_drawHitboxes() self:_drawHitboxes()
end end
end end
function Actor:drawShadow()
if (self.world.type ~= "3D" and self.world.drawShadow ~= true) then
return
end
local shadowZ = self:getGroundZ()
if (shadowZ == nil) then
return
end
local r, g, b, a = love.graphics.getColor( )
local x, y = self.position.x + (self.dimensions.w / 2), self.position.y + (3 * self.dimensions.h / 4) - shadowZ
love.graphics.setColor(0, 0, 0, .3)
love.graphics.ellipse( "fill", math.floor(x), math.floor(y), self.dimensions.w / 2, self.dimensions.w / 4 )
love.graphics.setColor(r, g, b, a)
end
-- Callbacks -- Callbacks
function Actor:onInit() function Actor:onInit()

View file

@ -184,6 +184,27 @@ function Physics:checkGround()
end end
end end
function Physics:getGroundZ()
if (self.world.type ~= "3D") then
return 0
end
-- On check to les acteurs qui pourraient être en dessous
local bodiesBehind = self.world:getBodiesInCube(self.position.x, self.position.y, self.position.z - 10000, self.dimensions.w, self.dimensions.h, 10000)
local z = nil
for _, body in ipairs(bodiesBehind) do
if (body.type ~= "main" and body.isSolid and body.owner ~= self) then
local zToCheck = body.position.z + body.dimensions.d
if (z == nil) then
z = zToCheck
else
z = math.max(z, zToCheck)
end
end
end
return z
end
function Physics:_applyCollisionResponses(col) function Physics:_applyCollisionResponses(col)
if (self.type == "player") and (col.other.owner ~= nil) and (col.other.owner.onPlayerCollision ~= nil) then if (self.type == "player") and (col.other.owner ~= nil) and (col.other.owner.onPlayerCollision ~= nil) then
col.other.owner:onPlayerCollision(self, "main", col) col.other.owner:onPlayerCollision(self, "main", col)

View file

@ -41,7 +41,7 @@ function Visual:_getShapeData()
if (self.world.type == "3D") then if (self.world.type == "3D") then
-- TODO: vérifier si l'algo est bon -- TODO: vérifier si l'algo est bon
position.y = position.y - self.dimensions.d - position.z + (self.dimensions.h) position.y = position.y - self.dimensions.d - position.z + (3 * self.dimensions.h / 4)
dimensions = { dimensions = {
w = self.dimensions.w, w = self.dimensions.w,
h = self.dimensions.h + self.dimensions.d, h = self.dimensions.h + self.dimensions.d,