From 71db337cb1928080f78b6b14646cce3731ecff5a Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 26 Jun 2016 21:04:31 +0200 Subject: Scaled background image --- assets/background-default.png | Bin 0 -> 790 bytes camera.lua | 1 + main.lua | 3 +++ maps/default.lua | 4 +--- world.lua | 16 +++++++--------- 5 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 assets/background-default.png diff --git a/assets/background-default.png b/assets/background-default.png new file mode 100644 index 0000000..959f4f9 Binary files /dev/null and b/assets/background-default.png differ diff --git a/camera.lua b/camera.lua index 0245218..32a1bed 100644 --- a/camera.lua +++ b/camera.lua @@ -8,6 +8,7 @@ Camera = { dest_x = 0, dest_y = 0, scale = getScale(), + scaler = getRealScale(), shake = 0, timer = 0, delay = 0, diff --git a/main.lua b/main.lua index d5552d0..930a57b 100644 --- a/main.lua +++ b/main.lua @@ -10,6 +10,9 @@ end function getScale() return math.max(1, math.floor(love.graphics.getWidth() / 320)-1, math.floor(love.graphics.getHeight() / 180)-1) end +function getRealScale() + return math.max(love.graphics.getWidth() / 320, love.graphics.getHeight() / 180) +end -- Require require "world" diff --git a/maps/default.lua b/maps/default.lua index 956f24c..df909b4 100644 --- a/maps/default.lua +++ b/maps/default.lua @@ -4,9 +4,7 @@ return { center_y = 0, width = 360, height = 240, - color_top = {193, 100, 99, 255}, - color_mid = {189, 95, 93, 255}, - color_bot = {179, 82, 80, 255}, + background = "assets/background-default.png", respawns = { {x = -15, y = -80}, {x = -5, y = -80}, diff --git a/world.lua b/world.lua index 6fd5203..1e46c06 100644 --- a/world.lua +++ b/world.lua @@ -25,6 +25,7 @@ World = { clouds_initial = nil, -- Map map = nil, + background = nil, -- Gameplay status lastNaut = false, -- "WINNER" @@ -94,6 +95,7 @@ function World:loadMap(name) for _,decoration in pairs(self.map.decorations) do self:createDecoration(decoration.x, decoration.y, decoration.sprite) end + self.background = love.graphics.newImage(self.map.background) end -- Spawn all the nauts for the round @@ -245,18 +247,14 @@ end -- Draw function World:draw() - -- Hard-coded background (for now) - love.graphics.setColor(self.map.color_bot) - love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()) - love.graphics.setColor(self.map.color_mid) - love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()*0.8) - love.graphics.setColor(self.map.color_top) - love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight()*0.25) - -- Camera stuff local offset_x, offset_y = self.camera:getOffsets() local scale = self.camera.scale - + local scaler = self.camera.scaler + + -- Background + love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) + -- Draw clouds for _,cloud in pairs(self.Clouds) do cloud:draw(offset_x, offset_y, scale) -- cgit v1.1