feat: add parallax backgrounds

This commit is contained in:
Kazhnuz 2019-07-27 13:52:41 +02:00
parent b3d9ed582e
commit b92f441d40
2 changed files with 40 additions and 1 deletions

View file

@ -16,7 +16,6 @@ function RadianceWorld:createMapController()
end
end
function RadianceWorld:loadMapObjects()
RadianceWorld.super.loadMapObjects(self)
self:addInvisibleWalls()
@ -31,4 +30,29 @@ function RadianceWorld:addInvisibleWalls()
self.obj.collisions["invisible"](self, -16, 0, 0, 16, h, 1000)
end
function RadianceWorld:draw(dt)
self:drawBackgroundColor()
local camNumber = self.cameras:getViewNumber()
if (camNumber == 0) then
self:drawMap()
self:drawActors()
else
for i=1, camNumber do
self:drawParallax(i)
self.cameras:attachView(i)
self:drawMap(i)
self:drawActors(i)
self.cameras:detachView(i)
end
end
end
function RadianceWorld:drawParallax(i)
local x, y, w, h = self.cameras:getViewCoordinate(i)
if (self.map ~= nil) and (self.maptype ~= "sti") then
self.map:drawParallax(x, y, w, h)
end
end
return RadianceWorld

View file

@ -4,6 +4,8 @@ local TestMap = BaseMap:extend()
function TestMap:new(world)
TestMap.super.new(self, world)
self:setPadding(0, 96, 0, 0)
self.background = love.graphics.newImage("assets/backgrounds/parallax/test-back.png")
end
function TestMap:loadCollisions()
@ -30,4 +32,17 @@ function TestMap:draw()
-- Empty Placeholder function
end
function TestMap:drawParallax(x, y, w, h)
local imax, jmax = (w/32)+1, (h/32)+1
local x, y = x or 0, y or 0
local x = math.floor(x/4) % 32
local y = math.floor((y+96)/6) % 32
for i=0, math.ceil(imax) do
for j=0, math.ceil(jmax) do
love.graphics.draw(self.background, (i-1)*32-x, (j-1)*32-y)
end
end
end
return TestMap