feat(battlemaps): add basic parallax capabilities
This commit is contained in:
parent
69b9068e49
commit
1041688c8e
4 changed files with 53 additions and 6 deletions
BIN
sonic-radiance.love/datas/gamedata/maps/battle/ebeach/back1.png
Normal file
BIN
sonic-radiance.love/datas/gamedata/maps/battle/ebeach/back1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
sonic-radiance.love/datas/gamedata/maps/battle/ebeach/back2.png
Normal file
BIN
sonic-radiance.love/datas/gamedata/maps/battle/ebeach/back2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
|
@ -1,11 +1,15 @@
|
|||
return {
|
||||
name = "Emerald Beach",
|
||||
blocks = {
|
||||
{96, 48, 64, 32, "top1", "side2"},
|
||||
{112, 80, 32, 32, "top3", "side1"},
|
||||
{80, 64, 64, 32, "top1", "side2"},
|
||||
{96, 96, 32, 32, "top3", "side1"},
|
||||
{192, 32, 96, 32, "top2", "side3"},
|
||||
{240, 112, 32, 64, "top4", "side1"},
|
||||
{112, 160, 32, 64, "top4", "side1"},
|
||||
{208, 224, 64, 32, "top5", "side2"},
|
||||
{224, 128, 32, 64, "top4", "side1"},
|
||||
{96, 176, 32, 64, "top4", "side1"},
|
||||
{192, 240, 64, 32, "top5", "side2"},
|
||||
},
|
||||
parallax = {
|
||||
{0, 0, .5, 0, true, false, "back1"},
|
||||
{0, 10, 1, 1, true, false, "back2"},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ function BattleMap:new(world, maptype, mapname)
|
|||
self.background = love.graphics.newImage(self.directory .. "background.png")
|
||||
self.data = require(self.mappath)
|
||||
self.assets = world.scene.assets
|
||||
|
||||
self:addParallax()
|
||||
end
|
||||
|
||||
function BattleMap:loadCollisions()
|
||||
|
@ -47,8 +49,49 @@ function BattleMap:draw()
|
|||
love.graphics.draw(self.background, 0, 0, 0, 1, 0.5)
|
||||
end
|
||||
|
||||
function BattleMap:addParallax()
|
||||
self.parallax = {}
|
||||
|
||||
for i,layerdata in ipairs(self.data.parallax) do
|
||||
local layer = {}
|
||||
layer.basex = layerdata[1]
|
||||
layer.basey = layerdata[2]
|
||||
layer.background = love.graphics.newImage(self.directory .. layerdata[7] .. ".png")
|
||||
local w, h = layer.background:getDimensions()
|
||||
layer.w = w
|
||||
layer.h = h
|
||||
|
||||
if (layerdata[5]) then
|
||||
layer.repeatx = math.ceil(424/w + 1)
|
||||
else
|
||||
layer.repeatx = 1
|
||||
end
|
||||
|
||||
if (layerdata[6]) then
|
||||
layer.repeaty = math.ceil(240/h + 1)
|
||||
else
|
||||
layer.repeaty = 1
|
||||
end
|
||||
|
||||
layer.decalx = layerdata[3]
|
||||
layer.decaly = layerdata[4]
|
||||
|
||||
table.insert(self.parallax, layer)
|
||||
end
|
||||
end
|
||||
|
||||
function BattleMap:drawParallax(x, y, w, h)
|
||||
-- Empty Placeholder function
|
||||
for i1, layer in ipairs(self.parallax) do
|
||||
local x = math.floor((x)*layer.decalx) % layer.w
|
||||
|
||||
for i=1, layer.repeatx do
|
||||
for j=1, layer.repeaty do
|
||||
local xx = math.floor(layer.basex + (layer.w * (i-1)) - x)
|
||||
local yy = math.floor(layer.basey + (layer.h * (j-1)) - (y+96)*layer.decaly)
|
||||
love.graphics.draw(layer.background, xx, yy)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return BattleMap
|
||||
|
|
Loading…
Reference in a new issue