mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-21 15:39:02 -06:00
Compare commits
6 Commits
7199aa7ef6
...
1556b247fe
Author | SHA1 | Date | |
---|---|---|---|
|
1556b247fe | ||
|
23d9feb357 | ||
|
c693871621 | ||
|
2ba3611c56 | ||
|
602e7105ab | ||
|
4478c07acf |
@ -1,17 +1,105 @@
|
|||||||
backgrounds = {
|
named_backgrounds = {
|
||||||
title = love.graphics.newImage("res/backgrounds/title.png"),
|
"title", "title_no_icon", "title_night",
|
||||||
title_no_icon = love.graphics.newImage("res/backgrounds/title-no-icon.jpg"),
|
"snow", "options_input", "options_game"
|
||||||
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"),
|
|
||||||
}
|
}
|
||||||
|
current_playing_bgs = {}
|
||||||
|
extended_bgs = {}
|
||||||
|
image_formats = {".png", ".jpg"}
|
||||||
|
bgpath = "res/backgrounds/"
|
||||||
|
dir = love.filesystem.getDirectoryItems(bgpath)
|
||||||
|
|
||||||
local i = 0
|
local backgrounds = {}
|
||||||
local bgpath = "res/backgrounds/%d.png"
|
|
||||||
while love.filesystem.getInfo(bgpath:format(i*100)) do
|
local function loadExtendedBgs()
|
||||||
backgrounds[i] = love.graphics.newImage(bgpath:format(i*100))
|
extended_bgs = require("res.backgrounds.extend_section_bg")
|
||||||
i = i + 1
|
end
|
||||||
|
|
||||||
|
-- error handling for if there is no extend_section_bg
|
||||||
|
if pcall(loadExtendedBgs) then end
|
||||||
|
|
||||||
|
-- helper method to populate backgrounds
|
||||||
|
local function createBackgroundIfExists(name, file_name)
|
||||||
|
local format_index = 1
|
||||||
|
|
||||||
|
-- see if background is an extension of another background
|
||||||
|
if extended_bgs[file_name] ~= nil then
|
||||||
|
copy_bg = extended_bgs[file_name]
|
||||||
|
copy_bg = copy_bg / 100
|
||||||
|
backgrounds[name] = backgrounds[copy_bg]
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- try creating image backgrounds
|
||||||
|
while format_index <= #image_formats do
|
||||||
|
for num, existing_file in pairs(dir) do
|
||||||
|
if existing_file == (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
|
||||||
|
end
|
||||||
|
format_index = format_index + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- try creating video background
|
||||||
|
if love.filesystem.getInfo(bgpath .. file_name .. ".ogv") then
|
||||||
|
for num, existing_file in pairs(dir) do
|
||||||
|
if existing_file == (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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function stopOtherBgs(bg)
|
||||||
|
if #current_playing_bgs == 0 and bg:typeOf("Video") then
|
||||||
|
current_playing_bgs[#current_playing_bgs+1] = bg
|
||||||
|
end
|
||||||
|
|
||||||
|
if #current_playing_bgs >= 1 then
|
||||||
|
while current_playing_bgs[1] ~= bg and #current_playing_bgs >= 1 do
|
||||||
|
current_playing_bgs[1]:pause()
|
||||||
|
current_playing_bgs[1]:rewind()
|
||||||
|
table.remove(current_playing_bgs, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function fetchBackgroundAndLoop(id)
|
||||||
|
bg = backgrounds[id]
|
||||||
|
|
||||||
|
if bg:typeOf("Video") and not bg:isPlaying() then
|
||||||
|
bg:rewind()
|
||||||
|
bg:play()
|
||||||
|
end
|
||||||
|
|
||||||
|
stopOtherBgs(bg)
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
-- in order, the colors are:
|
-- in order, the colors are:
|
||||||
|
14
res/backgrounds/extend_section_bg.lua
Normal file
14
res/backgrounds/extend_section_bg.lua
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
-- ex: extend_section_bg[100] = 0
|
||||||
|
-- extend_section_bg[200] = 0
|
||||||
|
-- the video background associated with section 0 will continue playing into 100 and 200 without restarting.
|
||||||
|
-- will also cause any existing level 100, 200 backgrounds specified to NOT render.
|
||||||
|
|
||||||
|
-- please also note that you cannot currently extend any "named" backgrounds, such as "title" and "options-input"
|
||||||
|
|
||||||
|
extend_section_bg = {}
|
||||||
|
|
||||||
|
-- extend_section_bg[100] = 0
|
||||||
|
-- extend_section_bg[200] = 0
|
||||||
|
-- remove the dashes
|
||||||
|
|
||||||
|
return extend_section_bg
|
@ -31,7 +31,7 @@ function CreditsScene:render()
|
|||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds[19],
|
fetchBackgroundAndLoop(id),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -46,7 +46,7 @@ end
|
|||||||
function ConfigScene:render()
|
function ConfigScene:render()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["game_config"],
|
fetchBackgroundAndLoop("options_game"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ function ConfigScene:update() end
|
|||||||
function ConfigScene:render()
|
function ConfigScene:render()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["input_config"],
|
fetchBackgroundAndLoop("options_input"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -46,7 +46,7 @@ end
|
|||||||
function KeyConfigScene:render()
|
function KeyConfigScene:render()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["input_config"],
|
fetchBackgroundAndLoop("input_config"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -59,7 +59,7 @@ end
|
|||||||
|
|
||||||
function ModeSelectScene:render()
|
function ModeSelectScene:render()
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds[0],
|
fetchBackgroundAndLoop(0),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -14,8 +14,12 @@ function ReplaySelectScene:new()
|
|||||||
replay_file_list = love.filesystem.getDirectoryItems("replays")
|
replay_file_list = love.filesystem.getDirectoryItems("replays")
|
||||||
for i=1,#replay_file_list do
|
for i=1,#replay_file_list do
|
||||||
local data = love.filesystem.read("replays/"..replay_file_list[i])
|
local data = love.filesystem.read("replays/"..replay_file_list[i])
|
||||||
local new_replay = binser.deserialize(data)[1]
|
local success, new_replay = pcall(
|
||||||
replays[#replays + 1] = new_replay
|
function() return binser.deserialize(data)[1] end
|
||||||
|
)
|
||||||
|
if success then
|
||||||
|
replays[#replays + 1] = new_replay
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.sort(replays, function(a, b)
|
table.sort(replays, function(a, b)
|
||||||
return a["timestamp"] > b["timestamp"]
|
return a["timestamp"] > b["timestamp"]
|
||||||
@ -75,7 +79,7 @@ end
|
|||||||
|
|
||||||
function ReplaySelectScene:render()
|
function ReplaySelectScene:render()
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds[0],
|
fetchBackgroundAndLoop(0),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ function SettingsScene:update() end
|
|||||||
function SettingsScene:render()
|
function SettingsScene:render()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["game_config"],
|
fetchBackgroundAndLoop("options_game"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -47,7 +47,7 @@ end
|
|||||||
function StickConfigScene:render()
|
function StickConfigScene:render()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["input_config"],
|
fetchBackgroundAndLoop("options_input"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -74,7 +74,7 @@ function TitleScene:render()
|
|||||||
love.graphics.setFont(font_3x5_4)
|
love.graphics.setFont(font_3x5_4)
|
||||||
love.graphics.setColor(1, 1, 1, 1 - self.snow_bg_opacity)
|
love.graphics.setColor(1, 1, 1, 1 - self.snow_bg_opacity)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["title_no_icon"], -- title, title_night
|
fetchBackgroundAndLoop("title_no_icon"), -- title, title_night
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
@ -100,7 +100,7 @@ function TitleScene:render()
|
|||||||
love.graphics.setFont(font_3x5_2)
|
love.graphics.setFont(font_3x5_2)
|
||||||
love.graphics.setColor(1, 1, 1, self.snow_bg_opacity)
|
love.graphics.setColor(1, 1, 1, self.snow_bg_opacity)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["snow"],
|
fetchBackgroundAndLoop("snow"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -35,7 +35,7 @@ end
|
|||||||
function TuningScene:render()
|
function TuningScene:render()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds["game_config"],
|
fetchBackgroundAndLoop("options_game"),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
@ -980,10 +980,10 @@ end
|
|||||||
|
|
||||||
function GameMode:drawBackground()
|
function GameMode:drawBackground()
|
||||||
local id = self:getBackground()
|
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.setColor(1, 1, 1, 1)
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
backgrounds[id],
|
fetchBackgroundAndLoop(id),
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0.5, 0.5
|
0.5, 0.5
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user