feat: add floor collisions
This commit is contained in:
parent
9385d9deb9
commit
63dbac57fd
5 changed files with 41 additions and 4 deletions
|
@ -218,7 +218,10 @@ end
|
||||||
-- Handle everything related to shadow
|
-- Handle everything related to shadow
|
||||||
|
|
||||||
function Actor3D:castShadow()
|
function Actor3D:castShadow()
|
||||||
local shadowTargets = self.world:getTerrainInRect(self.x, self.y, self.w, self.d)
|
local SHADOW_CAST_AREA = 12
|
||||||
|
local xshad, yshad = self.x-(SHADOW_CAST_AREA), self.y-(SHADOW_CAST_AREA)
|
||||||
|
local wshad, dshad = self.w+(SHADOW_CAST_AREA*2), self.d+(SHADOW_CAST_AREA*2)
|
||||||
|
local shadowTargets = self.world:getTerrainInRect(xshad, yshad, wshad, dshad)
|
||||||
-- initialize the shadowTargetsPrevious variable if it doesn't exist
|
-- initialize the shadowTargetsPrevious variable if it doesn't exist
|
||||||
if (self.shadowTargetsPrevious == nil) then
|
if (self.shadowTargetsPrevious == nil) then
|
||||||
self.shadowTargetsPrevious = {}
|
self.shadowTargetsPrevious = {}
|
||||||
|
|
|
@ -11,4 +11,19 @@ function Floor:update(dt)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Floor:draw()
|
||||||
|
local drawx, drawy, drawz = self.x, self.y, self.z
|
||||||
|
if (self.world.maptype == "shoot") then
|
||||||
|
drawx = drawx + math.floor(drawy/2)
|
||||||
|
end
|
||||||
|
self:drawStart()
|
||||||
|
if (self.box ~= nil) then
|
||||||
|
self.box:draw(drawx, drawy, drawz)
|
||||||
|
else
|
||||||
|
local x, y = math.floor(drawx), math.floor(drawy - drawz - self.d + (self.h/2))
|
||||||
|
self:drawSprite(x, y)
|
||||||
|
end
|
||||||
|
self:drawEnd()
|
||||||
|
end
|
||||||
|
|
||||||
return Floor
|
return Floor
|
||||||
|
|
|
@ -16,7 +16,13 @@ function Parent:draw()
|
||||||
self.box:draw(drawx, drawy, drawz)
|
self.box:draw(drawx, drawy, drawz)
|
||||||
else
|
else
|
||||||
local x, y = math.floor(drawx), math.floor(drawy - drawz - self.d + (self.h/2))
|
local x, y = math.floor(drawx), math.floor(drawy - drawz - self.d + (self.h/2))
|
||||||
|
if (math.floor(drawz) < -2) and (self.world.maptype == "shoot") then
|
||||||
|
core.screen:setScissor(0, 0, 424, 58+drawy/2)
|
||||||
self:drawSprite(x, y)
|
self:drawSprite(x, y)
|
||||||
|
core.screen:resetScissor()
|
||||||
|
else
|
||||||
|
self:drawSprite(x, y)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self:drawEnd()
|
self:drawEnd()
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,10 @@ end
|
||||||
function ShootMap:loadCollisions()
|
function ShootMap:loadCollisions()
|
||||||
self:loadLayout();
|
self:loadLayout();
|
||||||
local w, h = self:getDimensions()
|
local w, h = self:getDimensions()
|
||||||
self.world:newCollision("floor", 0, 0, -16, w, h, 16)
|
--self.world:newCollision("floor", 0, 0, -16, w, h, 16)
|
||||||
|
for i, chunk in ipairs(self.layout) do
|
||||||
|
chunk:spawnGrounds((i-1)*31*8)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ShootMap:loadLayout()
|
function ShootMap:loadLayout()
|
||||||
|
@ -242,7 +245,7 @@ function ShootMap:drawChunks(x)
|
||||||
for i=1, 6 do
|
for i=1, 6 do
|
||||||
local chunkID = firstChunk + i
|
local chunkID = firstChunk + i
|
||||||
if (self.layout[chunkID] ~= nil) then
|
if (self.layout[chunkID] ~= nil) then
|
||||||
self.layout[chunkID]:draw(chunkID * (8*31))
|
self.layout[chunkID]:draw((chunkID-1) * (8*31))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,16 @@ function Chunk:update(dt)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Chunk:spawnGrounds(x)
|
||||||
|
for i=1, 5 do
|
||||||
|
for j=1, 8 do
|
||||||
|
if (self.data.terrain[i][j] ~= 3) then
|
||||||
|
self.map.world:newCollision("floor", x+(j-1)*31, (i-1)*20, -48, 31, 20, 48)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Chunk:draw(x)
|
function Chunk:draw(x)
|
||||||
for i=1, 5 do
|
for i=1, 5 do
|
||||||
for j=1, 8 do
|
for j=1, 8 do
|
||||||
|
|
Loading…
Reference in a new issue