2023-07-16 00:06:06 -05:00
|
|
|
named_backgrounds = {
|
|
|
|
"title", "title_no_icon", "title_night",
|
|
|
|
"snow", "options_input", "options_game"
|
|
|
|
}
|
2023-07-15 23:28:03 -05:00
|
|
|
current_playing_bgs = {}
|
|
|
|
extended_bgs = {}
|
2023-07-14 19:54:35 -05:00
|
|
|
image_formats = {".png", ".jpg"}
|
2023-07-15 23:28:03 -05:00
|
|
|
bgpath = "res/backgrounds/"
|
|
|
|
dir = love.filesystem.getDirectoryItems(bgpath)
|
2023-07-14 19:54:35 -05:00
|
|
|
|
2023-07-15 23:28:03 -05:00
|
|
|
local backgrounds = {}
|
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
local function loadExtendedBgs()
|
2023-07-15 23:28:03 -05:00
|
|
|
extended_bgs = require("res.backgrounds.extend_section_bg")
|
|
|
|
end
|
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
-- error handling for if there is no extend_section_bg
|
2023-07-15 23:28:03 -05:00
|
|
|
if pcall(loadExtendedBgs) then end
|
2023-07-14 19:54:35 -05:00
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
-- helper method to populate backgrounds
|
|
|
|
local function createBackgroundIfExists(name, file_name)
|
2023-07-14 19:54:35 -05:00
|
|
|
local format_index = 1
|
|
|
|
|
2023-07-15 23:28:03 -05:00
|
|
|
-- see if background is an extension of another background
|
2023-07-16 00:06:06 -05:00
|
|
|
if extended_bgs[file_name] ~= nil then
|
2023-07-15 23:28:03 -05:00
|
|
|
copy_bg = extended_bgs[file_name]
|
2023-07-16 00:06:06 -05:00
|
|
|
copy_bg = copy_bg / 100
|
2023-07-15 23:28:03 -05:00
|
|
|
backgrounds[name] = backgrounds[copy_bg]
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- try creating image backgrounds
|
2023-07-14 19:54:35 -05:00
|
|
|
while format_index <= #image_formats do
|
2023-07-15 23:28:03 -05:00
|
|
|
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
|
2023-07-14 19:54:35 -05:00
|
|
|
end
|
|
|
|
format_index = format_index + 1
|
|
|
|
end
|
|
|
|
|
2023-07-15 23:28:03 -05:00
|
|
|
-- try creating video background
|
2023-07-16 00:06:06 -05:00
|
|
|
if love.filesystem.getInfo(bgpath .. file_name .. ".ogv") then
|
2023-07-15 23:28:03 -05:00
|
|
|
for num, existing_file in pairs(dir) do
|
|
|
|
if existing_file == (file_name..".ogv") then
|
|
|
|
local tempBgPath = bgpath .. file_name .. ".ogv"
|
2023-07-16 00:06:06 -05:00
|
|
|
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
|
2023-07-15 23:28:03 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2023-07-14 19:54:35 -05:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
local function stopOtherBgs(bg)
|
2023-07-15 23:28:03 -05:00
|
|
|
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
|
|
|
|
|
2023-07-14 19:54:35 -05:00
|
|
|
function fetchBackgroundAndLoop(id)
|
|
|
|
bg = backgrounds[id]
|
|
|
|
|
|
|
|
if bg:typeOf("Video") and not bg:isPlaying() then
|
|
|
|
bg:rewind()
|
|
|
|
bg:play()
|
|
|
|
end
|
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
stopOtherBgs(bg)
|
2023-07-14 19:54:35 -05:00
|
|
|
|
|
|
|
return bg
|
|
|
|
end
|
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
-- create section backgrounds
|
2023-07-14 19:54:35 -05:00
|
|
|
local section = 0
|
|
|
|
while (createBackgroundIfExists(section, section*100)) do
|
|
|
|
section = section + 1
|
|
|
|
end
|
|
|
|
|
2023-07-16 00:06:06 -05:00
|
|
|
-- create named backgrounds
|
2023-07-14 19:54:35 -05:00
|
|
|
local nbgIndex = 1
|
|
|
|
while nbgIndex <= #named_backgrounds do
|
2023-07-16 00:06:06 -05:00
|
|
|
createBackgroundIfExists(
|
|
|
|
named_backgrounds[nbgIndex],
|
|
|
|
string.gsub(named_backgrounds[nbgIndex], "_", "-")
|
|
|
|
)
|
2023-07-14 19:54:35 -05:00
|
|
|
nbgIndex = nbgIndex + 1
|
2023-06-30 19:56:51 -05:00
|
|
|
end
|
|
|
|
|
2021-09-21 22:30:51 -05:00
|
|
|
-- in order, the colors are:
|
|
|
|
-- red, orange, yellow, green, cyan, blue
|
|
|
|
-- magenta (or purple), white, black
|
|
|
|
-- the next three don't have colors tied to them
|
|
|
|
-- F is used for lock flash
|
|
|
|
-- A is a garbage block
|
|
|
|
-- X is an invisible "block"
|
|
|
|
-- don't use these for piece colors when making a ruleset
|
|
|
|
-- all the others are fine to use
|
2019-05-22 22:57:34 -05:00
|
|
|
blocks = {
|
|
|
|
["2tie"] = {
|
2020-10-10 18:42:56 -05:00
|
|
|
R = love.graphics.newImage("res/img/s1.png"),
|
2020-10-10 21:12:22 -05:00
|
|
|
O = love.graphics.newImage("res/img/s3.png"),
|
2020-10-10 18:42:56 -05:00
|
|
|
Y = love.graphics.newImage("res/img/s7.png"),
|
|
|
|
G = love.graphics.newImage("res/img/s6.png"),
|
|
|
|
C = love.graphics.newImage("res/img/s2.png"),
|
2020-10-10 21:12:22 -05:00
|
|
|
B = love.graphics.newImage("res/img/s4.png"),
|
2020-10-10 18:42:56 -05:00
|
|
|
M = love.graphics.newImage("res/img/s5.png"),
|
2021-09-21 22:30:51 -05:00
|
|
|
W = love.graphics.newImage("res/img/s9.png"),
|
|
|
|
D = love.graphics.newImage("res/img/s8.png"),
|
2020-11-11 10:42:48 -06:00
|
|
|
F = love.graphics.newImage("res/img/s9.png"),
|
|
|
|
A = love.graphics.newImage("res/img/s8.png"),
|
2019-05-22 22:57:34 -05:00
|
|
|
X = love.graphics.newImage("res/img/s9.png"),
|
|
|
|
},
|
|
|
|
["bone"] = {
|
2020-10-10 18:42:56 -05:00
|
|
|
R = love.graphics.newImage("res/img/bone.png"),
|
2019-05-22 22:57:34 -05:00
|
|
|
O = love.graphics.newImage("res/img/bone.png"),
|
2020-10-10 18:42:56 -05:00
|
|
|
Y = love.graphics.newImage("res/img/bone.png"),
|
2019-05-22 22:57:34 -05:00
|
|
|
G = love.graphics.newImage("res/img/bone.png"),
|
2020-10-10 18:42:56 -05:00
|
|
|
C = love.graphics.newImage("res/img/bone.png"),
|
|
|
|
B = love.graphics.newImage("res/img/bone.png"),
|
|
|
|
M = love.graphics.newImage("res/img/bone.png"),
|
2021-09-21 22:30:51 -05:00
|
|
|
W = love.graphics.newImage("res/img/bone.png"),
|
|
|
|
D = love.graphics.newImage("res/img/bone.png"),
|
2020-11-11 10:42:48 -06:00
|
|
|
F = love.graphics.newImage("res/img/bone.png"),
|
|
|
|
A = love.graphics.newImage("res/img/bone.png"),
|
2019-05-22 22:57:34 -05:00
|
|
|
X = love.graphics.newImage("res/img/bone.png"),
|
2020-12-30 14:19:53 -06:00
|
|
|
},
|
|
|
|
["gem"] = {
|
|
|
|
R = love.graphics.newImage("res/img/gem1.png"),
|
|
|
|
O = love.graphics.newImage("res/img/gem3.png"),
|
|
|
|
Y = love.graphics.newImage("res/img/gem7.png"),
|
|
|
|
G = love.graphics.newImage("res/img/gem6.png"),
|
|
|
|
C = love.graphics.newImage("res/img/gem2.png"),
|
|
|
|
B = love.graphics.newImage("res/img/gem4.png"),
|
|
|
|
M = love.graphics.newImage("res/img/gem5.png"),
|
2021-09-21 22:30:51 -05:00
|
|
|
W = love.graphics.newImage("res/img/gem9.png"),
|
|
|
|
D = love.graphics.newImage("res/img/gem9.png"),
|
2020-12-30 14:19:53 -06:00
|
|
|
F = love.graphics.newImage("res/img/gem9.png"),
|
|
|
|
A = love.graphics.newImage("res/img/gem9.png"),
|
|
|
|
X = love.graphics.newImage("res/img/gem9.png"),
|
2021-01-14 15:28:18 -06:00
|
|
|
},
|
|
|
|
["square"] = {
|
2021-09-21 22:30:51 -05:00
|
|
|
W = love.graphics.newImage("res/img/squares.png"),
|
2021-01-14 15:28:18 -06:00
|
|
|
Y = love.graphics.newImage("res/img/squareg.png"),
|
2021-09-21 22:30:51 -05:00
|
|
|
F = love.graphics.newImage("res/img/squares.png"),
|
2021-01-14 15:28:18 -06:00
|
|
|
X = love.graphics.newImage("res/img/squares.png"),
|
2019-05-22 22:57:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-10 18:42:56 -05:00
|
|
|
ColourSchemes = {
|
2020-11-11 10:42:48 -06:00
|
|
|
Arika = {
|
|
|
|
I = "R",
|
|
|
|
L = "O",
|
|
|
|
J = "B",
|
|
|
|
S = "M",
|
|
|
|
Z = "G",
|
|
|
|
O = "Y",
|
|
|
|
T = "C",
|
|
|
|
},
|
|
|
|
TTC = {
|
|
|
|
I = "C",
|
|
|
|
L = "O",
|
|
|
|
J = "B",
|
|
|
|
S = "G",
|
|
|
|
Z = "R",
|
|
|
|
O = "Y",
|
|
|
|
T = "M",
|
2021-09-21 22:30:51 -05:00
|
|
|
}
|
2020-10-10 18:42:56 -05:00
|
|
|
}
|
|
|
|
|
2019-06-16 21:16:09 -05:00
|
|
|
for name, blockset in pairs(blocks) do
|
|
|
|
for shape, image in pairs(blockset) do
|
|
|
|
image:setFilter("nearest")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
misc_graphics = {
|
|
|
|
frame = love.graphics.newImage("res/img/frame.png"),
|
|
|
|
ready = love.graphics.newImage("res/img/ready.png"),
|
|
|
|
go = love.graphics.newImage("res/img/go.png"),
|
|
|
|
select_mode = love.graphics.newImage("res/img/select_mode.png"),
|
|
|
|
strike = love.graphics.newImage("res/img/strike.png"),
|
2021-10-16 23:34:30 -05:00
|
|
|
santa = love.graphics.newImage("res/img/santa.png"),
|
|
|
|
icon = love.graphics.newImage("res/img/cambridge_transparent.png")
|
2023-07-16 00:49:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
-- 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
|