feat: add floor collisions

This commit is contained in:
Kazhnuz 2020-01-12 00:02:06 +01:00
parent 9385d9deb9
commit 63dbac57fd
5 changed files with 41 additions and 4 deletions

View file

@ -218,7 +218,10 @@ end
-- Handle everything related to shadow
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
if (self.shadowTargetsPrevious == nil) then
self.shadowTargetsPrevious = {}

View file

@ -11,4 +11,19 @@ function Floor:update(dt)
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

View file

@ -16,7 +16,13 @@ function Parent:draw()
self.box:draw(drawx, drawy, drawz)
else
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)
core.screen:resetScissor()
else
self:drawSprite(x, y)
end
end
self:drawEnd()
end

View file

@ -49,7 +49,10 @@ end
function ShootMap:loadCollisions()
self:loadLayout();
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
function ShootMap:loadLayout()
@ -242,7 +245,7 @@ function ShootMap:drawChunks(x)
for i=1, 6 do
local chunkID = firstChunk + i
if (self.layout[chunkID] ~= nil) then
self.layout[chunkID]:draw(chunkID * (8*31))
self.layout[chunkID]:draw((chunkID-1) * (8*31))
end
end
end

View file

@ -19,6 +19,16 @@ function Chunk:update(dt)
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)
for i=1, 5 do
for j=1, 8 do