First commit, WIP

This commit is contained in:
aur9ra 2023-07-14 17:54:35 -07:00
parent 52d4aeb3d0
commit 4478c07acf
12 changed files with 85 additions and 26 deletions

View File

@ -1,17 +1,76 @@
backgrounds = {
title = love.graphics.newImage("res/backgrounds/title.png"),
title_no_icon = love.graphics.newImage("res/backgrounds/title-no-icon.jpg"),
title_night = love.graphics.newImage("res/backgrounds/title-night.jpg"),
snow = love.graphics.newImage("res/backgrounds/snow.png"),
input_config = love.graphics.newImage("res/backgrounds/options-input.png"),
game_config = love.graphics.newImage("res/backgrounds/options-game.png"),
}
named_backgrounds = {"title", "title_no_icon", "title_night", "snow", "options_input", "options_game"}
backgrounds_played_recently = {}
image_formats = {".png", ".jpg"}
local bgpath = "res/backgrounds/"
local i = 0
local bgpath = "res/backgrounds/%d.png"
while love.filesystem.getInfo(bgpath:format(i*100)) do
backgrounds[i] = love.graphics.newImage(bgpath:format(i*100))
i = i + 1
backgrounds = {}
--helper method to populate backgrounds
function createBackgroundIfExists(name, file_name)
local format_index = 1
--try creating image backgrounds
while format_index <= #image_formats do
if love.filesystem.getInfo(bgpath.. file_name ..image_formats[format_index]) then
local tempBgPath = bgpath .. file_name .. image_formats[format_index]
backgrounds[name] = love.graphics.newImage(tempBgPath)
return true
end
format_index = format_index + 1
end
if love.filesystem.getInfo(bgpath .. file_name ..".ogv") then
local tempBgPath = bgpath .. file_name .. ".ogv"
backgrounds[name] = love.graphics.newVideo(tempBgPath, {["audio"] = false})
-- you can set audio to true, but the video will not loop properly if audio extends beyond video frames
return true
end
return false
end
function fetchBackgroundAndLoop(id)
bg = backgrounds[id]
if bg:typeOf("Video") and not bg:isPlaying() then
bg:rewind()
bg:play()
if (not backgrounds_played_recently[1] == bg) or backgrounds_played_recently[1] == nil then
table.insert(backgrounds_played_recently, 1, bg)
print(id)
end
end
--if background is not loaded, rewind it and pause it
if #backgrounds_played_recently >= 1 then
if backgrounds_played_recently[1] == bg and #backgrounds_played_recently >= 2 then
print("!")
backgrounds_played_recently[2]:pause()
backgrounds_played_recently[2]:rewind()
table.remove(backgrounds_played_recently, 2)
print("Unloaded video #2")
elseif not backgrounds_played_recently[1] == bg then
backgrounds_played_recently[1]:pause()
backgrounds_played_recently[1]:rewind()
table.remove(backgrounds_played_recently, 1)
print("Unloaded most recently played")
end
end
return bg
end
--create section backgrounds
local section = 0
while (createBackgroundIfExists(section, section*100)) do
section = section + 1
end
--create named backgrounds
local nbgIndex = 1
while nbgIndex <= #named_backgrounds do
createBackgroundIfExists(named_backgrounds[nbgIndex], string.gsub(named_backgrounds[nbgIndex], "_", "-"))
nbgIndex = nbgIndex + 1
end
-- in order, the colors are:

View File

@ -33,7 +33,7 @@ function CreditsScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds[19],
fetchBackgroundAndLoop(id),
0, 0, 0,
0.5, 0.5
)

View File

@ -46,7 +46,7 @@ end
function ConfigScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["game_config"],
fetchBackgroundAndLoop("options_game"),
0, 0, 0,
0.5, 0.5
)

View File

@ -21,7 +21,7 @@ function ConfigScene:update() end
function ConfigScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["input_config"],
fetchBackgroundAndLoop("options_input"),
0, 0, 0,
0.5, 0.5
)

View File

@ -46,7 +46,7 @@ end
function KeyConfigScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["input_config"],
fetchBackgroundAndLoop("input_config"),
0, 0, 0,
0.5, 0.5
)

View File

@ -59,7 +59,7 @@ end
function ModeSelectScene:render()
love.graphics.draw(
backgrounds[0],
fetchBackgroundAndLoop(0),
0, 0, 0,
0.5, 0.5
)

View File

@ -75,7 +75,7 @@ end
function ReplaySelectScene:render()
love.graphics.draw(
backgrounds[0],
fetchBackgroundAndLoop(0),
0, 0, 0,
0.5, 0.5
)

View File

@ -30,7 +30,7 @@ function SettingsScene:update() end
function SettingsScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["game_config"],
fetchBackgroundAndLoop("options_game"),
0, 0, 0,
0.5, 0.5
)

View File

@ -47,7 +47,7 @@ end
function StickConfigScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["input_config"],
fetchBackgroundAndLoop("options_input"),
0, 0, 0,
0.5, 0.5
)

View File

@ -74,7 +74,7 @@ function TitleScene:render()
love.graphics.setFont(font_3x5_4)
love.graphics.setColor(1, 1, 1, 1 - self.snow_bg_opacity)
love.graphics.draw(
backgrounds["title_no_icon"], -- title, title_night
fetchBackgroundAndLoop("title_no_icon"), -- title, title_night
0, 0, 0,
0.5, 0.5
)
@ -100,7 +100,7 @@ function TitleScene:render()
love.graphics.setFont(font_3x5_2)
love.graphics.setColor(1, 1, 1, self.snow_bg_opacity)
love.graphics.draw(
backgrounds["snow"],
fetchBackgroundAndLoop("snow"),
0, 0, 0,
0.5, 0.5
)

View File

@ -35,7 +35,7 @@ end
function TuningScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds["game_config"],
fetchBackgroundAndLoop("options_game"),
0, 0, 0,
0.5, 0.5
)

View File

@ -980,10 +980,10 @@ end
function GameMode:drawBackground()
local id = self:getBackground()
if type(id) == "number" then id = clamp(id, 0, #backgrounds) end
-- if type(id) == "number" then id = clamp(id, 0, #backgrounds) end
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(
backgrounds[id],
fetchBackgroundAndLoop(id),
0, 0, 0,
0.5, 0.5
)