81 lines
2.2 KiB
Lua
81 lines
2.2 KiB
Lua
local Background = Object:extend()
|
|
|
|
function Background:new(controller, levelname)
|
|
self.controller = controller
|
|
local backname = self.controller.datas.background or "city"
|
|
local tileline = self.controller.datas.tiles or 1
|
|
local borderline = self.controller.datas.borders or 1
|
|
|
|
self.textures = {}
|
|
self.textures.tiles = love.graphics.newImage("assets/backgrounds/normaltile.png")
|
|
self.textures.back1 = love.graphics.newImage("assets/backgrounds/parallax/" .. backname .. "-back.png")
|
|
self.textures.back2 = love.graphics.newImage("assets/backgrounds/parallax/" .. backname .. "-fore.png")
|
|
self.textures.borders = love.graphics.newImage("assets/backgrounds/borders.png")
|
|
|
|
self.quads = {}
|
|
self.quads.tiles = {}
|
|
|
|
local w, h = self.textures.tiles:getDimensions()
|
|
self.quads.tiles[1] = love.graphics.newQuad( 0, tileline*24, 40, 24, w, h)
|
|
self.quads.tiles[2] = love.graphics.newQuad(40, tileline*24, 40, 24, w, h)
|
|
|
|
local w, h = self.textures.borders:getDimensions()
|
|
self.quads.borders = love.graphics.newQuad(0, borderline*10, 80, 10, w, h)
|
|
|
|
|
|
end
|
|
|
|
function Background:destroy()
|
|
self.back1:release( )
|
|
self.back2:release( )
|
|
end
|
|
|
|
function Background:draw()
|
|
local x0, x1, x2
|
|
|
|
local turn = 0
|
|
|
|
x0 = 0
|
|
x1 = x0 / 3 % 240
|
|
x2 = x0 / 9 % 480
|
|
|
|
local sx = 1
|
|
for i=1, 4 do
|
|
if (i == 2) or (i == 4) then
|
|
love.graphics.draw(self.textures.back1, (i)*240 - x2, 20, 0, -1, 1)
|
|
else
|
|
love.graphics.draw(self.textures.back1, (i-1)*240 - x2, 20, 0, 1, 1)
|
|
end
|
|
end
|
|
|
|
|
|
for i=1, 7 do
|
|
love.graphics.draw(self.textures.borders, self.quads.borders, (i-1)*80, 80, 0, 1, 1)
|
|
end
|
|
|
|
for i=1, 3 do
|
|
love.graphics.draw(self.textures.back2, (i-1)*240 - x1, 20, 0, 1, 1)
|
|
end
|
|
|
|
--self:drawBorders()
|
|
self:drawGround(-8, 86)
|
|
end
|
|
|
|
function Background:drawGround(x, y)
|
|
for i=1, 9 do
|
|
for j= -2, 17 do
|
|
local k = 1 + ((i + j) % 2)
|
|
if (i >= 1) and (i <= 7) and (j >= 1) and (j <= 12) then
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
else
|
|
love.graphics.setColor(.6,.6,.6, 1)
|
|
end
|
|
|
|
love.graphics.draw(self.textures.tiles, self.quads.tiles[k], x + (j-1)*31 + (i-1)*10 , y + (i-1)*20)
|
|
end
|
|
end
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
end
|
|
|
|
return Background
|