diff --git a/load/graphics.lua b/load/graphics.lua index df97541..6fb160e 100644 --- a/load/graphics.lua +++ b/load/graphics.lua @@ -197,4 +197,17 @@ misc_graphics = { strike = love.graphics.newImage("res/img/strike.png"), santa = love.graphics.newImage("res/img/santa.png"), icon = love.graphics.newImage("res/img/cambridge_transparent.png") -} \ No newline at end of file +} + +-- utility function to allow any size background to be used +-- this will stretch the background to 4:3 aspect ratio +function drawBackground(id) + local bg_object = fetchBackgroundAndLoop(id) + local width = bg_object:getWidth() + local height = bg_object:getHeight() + love.graphics.draw( + bg_object, + 0, 0, 0, + 640 / width, 480 / height + ) +end \ No newline at end of file diff --git a/scene/credits.lua b/scene/credits.lua index fdede66..eacc9d5 100644 --- a/scene/credits.lua +++ b/scene/credits.lua @@ -30,11 +30,7 @@ function CreditsScene:render() local offset = self.frames / self.scroll_speed love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop(id), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground(19) love.graphics.setFont(font_3x5_4) love.graphics.print("Cambridge Credits", 320, 500 - offset) diff --git a/scene/game_config.lua b/scene/game_config.lua index 597a33a..68b4aff 100644 --- a/scene/game_config.lua +++ b/scene/game_config.lua @@ -45,11 +45,7 @@ end function ConfigScene:render() love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop("options_game"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("options_game") love.graphics.setFont(font_3x5_4) love.graphics.print("GAME SETTINGS", 80, 40) diff --git a/scene/input_config.lua b/scene/input_config.lua index 7909f33..230c514 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -20,11 +20,7 @@ function ConfigScene:update() end function ConfigScene:render() love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop("options_input"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("options_input") love.graphics.setFont(font_3x5_4) love.graphics.print("INPUT CONFIG", 80, 40) diff --git a/scene/key_config.lua b/scene/key_config.lua index f025bd9..ce32226 100644 --- a/scene/key_config.lua +++ b/scene/key_config.lua @@ -45,11 +45,7 @@ end function KeyConfigScene:render() love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop("input_config"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("input_config") love.graphics.setFont(font_3x5_2) for i, input in ipairs(configurable_inputs) do diff --git a/scene/mode_select.lua b/scene/mode_select.lua index 015cc0f..329de3c 100755 --- a/scene/mode_select.lua +++ b/scene/mode_select.lua @@ -58,11 +58,7 @@ function ModeSelectScene:update() end function ModeSelectScene:render() - love.graphics.draw( - fetchBackgroundAndLoop(0), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground(0) love.graphics.draw(misc_graphics["select_mode"], 20, 40) diff --git a/scene/replay_select.lua b/scene/replay_select.lua index 0d4c30b..aecb468 100644 --- a/scene/replay_select.lua +++ b/scene/replay_select.lua @@ -78,11 +78,7 @@ function ReplaySelectScene:update() end function ReplaySelectScene:render() - love.graphics.draw( - fetchBackgroundAndLoop(0), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground(0) -- Same graphic as mode select --love.graphics.draw(misc_graphics["select_mode"], 20, 40) diff --git a/scene/settings.lua b/scene/settings.lua index 14d7282..a51d8c1 100644 --- a/scene/settings.lua +++ b/scene/settings.lua @@ -29,11 +29,7 @@ function SettingsScene:update() end function SettingsScene:render() love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop("options_game"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("options_game") love.graphics.setFont(font_3x5_4) love.graphics.print("SETTINGS", 80, 40) diff --git a/scene/stick_config.lua b/scene/stick_config.lua index 7c68d23..d8bc03c 100644 --- a/scene/stick_config.lua +++ b/scene/stick_config.lua @@ -46,11 +46,7 @@ end function StickConfigScene:render() love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop("options_input"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("options_input") love.graphics.setFont(font_3x5_2) for i, input in ipairs(configurable_inputs) do diff --git a/scene/title.lua b/scene/title.lua index 72978fa..06a28ec 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -73,11 +73,7 @@ local block_offsets = { function TitleScene:render() love.graphics.setFont(font_3x5_4) love.graphics.setColor(1, 1, 1, 1 - self.snow_bg_opacity) - love.graphics.draw( - fetchBackgroundAndLoop("title_no_icon"), -- title, title_night - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("title_no_icon"), -- title, title_night -- 490, 192 for _, b in ipairs(block_offsets) do @@ -99,11 +95,7 @@ function TitleScene:render() love.graphics.setFont(font_3x5_2) love.graphics.setColor(1, 1, 1, self.snow_bg_opacity) - love.graphics.draw( - fetchBackgroundAndLoop("snow"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("snow") love.graphics.draw( misc_graphics["santa"], diff --git a/scene/tuning.lua b/scene/tuning.lua index 738d22c..42bc65a 100644 --- a/scene/tuning.lua +++ b/scene/tuning.lua @@ -34,11 +34,7 @@ end function TuningScene:render() love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop("options_game"), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground("options_game") love.graphics.setColor(1, 1, 1, 0.5) love.graphics.rectangle("fill", 75, 98 + self.highlight * 75, 400, 33) diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index 1179d20..9123e59 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -982,11 +982,7 @@ function GameMode:drawBackground() local id = self:getBackground() -- if type(id) == "number" then id = clamp(id, 0, #backgrounds) end love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw( - fetchBackgroundAndLoop(id), - 0, 0, 0, - 0.5, 0.5 - ) + drawBackground(id) end function GameMode:drawFrame()