TaggedEngine/src/main.lua

302 lines
8.8 KiB
Lua

local gamePath = love.filesystem.getSourceBaseDirectory() -- Assuming it's always in fused mode.
local mounted = love.filesystem.mount(gamePath, "") -- Mounting the game directory, should be accessible like if normal.
assert(mounted, "Couldn't mount the game directory.")
local state = require("modules.states.playstate")
local myMath = require("modules.math")
local myTypes = require("modules.types")
local files = require("modules.files")
local json = require("modules.json")
local logging = require("modules.logging")
require("modules.loveanimate") -- Start loveanimate
local songs = require("charts.songs")
curChar = "bf" --this needs to be global
local flip = false
local lastChange = 0
local curSong = songs[1]
local curIndex = 1
local evilCurIndex = 1
local curDiffList = songs[1].difficulties
local bfAtlas = love.animate.newTextureAtlas()
local picoAtlas
local curDiff = songs[1].difficulties[1]
local curDiffInd = 1
local diffIMG
local charIcon
local iconNum = math.random(1,3)
local curState = nil
local stateLoaded = false
local pressed = {false,false,false}
local bg
local logo
local gf
local freaky = love.audio.newSource("sounds/freakyMenu.ogg", "stream")
freaky:setVolume(0.25)
local charSwapSND = love.audio.newSource("sounds/CS_select.ogg", "stream")
charSwapSND:setVolume(0.25)
local left
local function setup()
bg = myTypes.Image("images/menuBG.png", 0)
bg.ui = false
bg.layer = -10
-- NO MORE GF
left = myTypes.Image("images/MenuLeft.png")
left.layer = 0
left.resize = myTypes.Vector2(2, 1)
local arrow = myTypes.Image("images/eventArrow.png")
arrow.position.y = 330
arrow.layer = 1
arrow.resize = myTypes.Vector2(.5,.5)
diffIMG = myTypes.Sprite("images/diff/diffList.png", "images/diff/diffList.json") --look there was a different plan going in
diffIMG:PlayAnimation(curDiff, 24, false)
diffIMG.position = myTypes.Vector2(200, 320)
diffIMG.layer = 2
charIcon = myTypes.Sprite("sprites/menu/charIcons.png", "sprites/menu/charIcons.json")
charIcon:PlayAnimation(curChar..iconNum, 24, false)
charIcon.position = myTypes.Vector2(175, 100)
charIcon.resize = myTypes.Vector2(0.25, 0.25) --this doesnt work and idk why
charIcon.layer = 2 --since they won't overlap this is ok i think
freaky:play()
if curChar == "bf" then
bfAtlas = love.animate.newTextureAtlas()
bfAtlas:load("sprites/charSelect/bfChill")
bfAtlas:play("bf cs idle")
logging.log(logging.dump(bfAtlas.timeline))
else
bfAtlas = love.animate.newTextureAtlas()
bfAtlas:load("sprites/charSelect/picoChill")
bfAtlas:play("pico cs idle")
end
end
local font = love.graphics.newFont("fonts/FridayNightFunkin-Regular.ttf", 40)
local gettingKey
local settings = json.parse(files.read_file("settings.json"))
local keybinds = settings.Keybinds
local scroll = love.audio.newSource("sounds/ui/scrollMenu.ogg", "static")
local confirm = love.audio.newSource("sounds/ui/confirmMenu.ogg", "static")
function love.update(dt)
if curState and curState.loaded then
if stateLoaded then
curState.update(dt)
else
stateLoaded = true -- skipping this update frame
curState.finish()
end
elseif not curState then
lastChange = lastChange + dt
if lastChange > .25 and bfAtlas.symbol == curChar.." slide in" then
bfAtlas:play(curChar.." cs idle")
if curChar == "pico" then
flip = true
end
end
bfAtlas:update(dt)
myTypes.render.cameraTarget = myTypes.Vector2(0,0)
myTypes.updateSprites(dt)
end
end
function love.draw()
if curState and stateLoaded then
curState.draw()
else
myTypes.drawSprites()
evilCurIndex = myMath.lerp(evilCurIndex, curIndex, .3)
for index, song in next, songs do
love.graphics.print({{0,0,0}, song.name}, font, 300 + (8 * (index - evilCurIndex)), love.graphics:getHeight()/2 + (50 * (index - evilCurIndex - .7)), 0, 1, 1, 200)
end
--love.graphics.print({{0,0,0}, curDiff}, font, 400, 660)
love.graphics.print(
{{0,0,0}, string.format("Left: %s, Down: %s, Up: %s, Right: %s \nDownscroll: %s",
keybinds[1],
keybinds[2],
keybinds[3],
keybinds[4],
settings.Downscroll
)})
love.graphics.print({{0,0,0}, "Press 1 to change LEFT \nPress 2 to change DOWN \nPress 3 to change UP \nPress 4 to change RIGHT \nPress 0 to toggle DOWNSCROLL \nPress P to SWAP CHARACTERS"}, 500, 0)
if bfAtlas.symbol == curChar.." slide in" then
bfAtlas:draw(curChar == "bf" and 695 or 690, curChar == "bf" and 315 or 320, 0, flip and -1 or 1, 1)
else
bfAtlas:draw(curChar == "bf" and 700 or 1150, curChar == "bf" and 300 or 190, 0, flip and -1 or 1, 1)
end
end
end
function run()
confirm:stop()
confirm:play()
myTypes.destroyAllSprites()
freaky:stop()
curState = state(curSong.name, curDiff)
curState.quit = function()
curState = nil
stateLoaded = false
myTypes.destroyAllSprites()
setup()
end
curState.restart = function()
curState = nil
stateLoaded = false
myTypes.destroyAllSprites()
run()
end
curState.load()
end
function love.keypressed(key, un, is)
if curState and stateLoaded then
curState.keypressed(key, un, is)
elseif not curState then
if not gettingKey then
if key == "return" then
run()
elseif key == "down" then
curIndex, curSong = next(songs, curIndex)
if not curSong then
curIndex, curSong = next(songs)
curDiffList = curSong.difficulties
else
curDiffList = curSong.difficulties
end
curDiffInd = 1
curDiff = curDiffList[1]
diffIMG:PlayAnimation(curDiff, 24, true)
scroll:stop()
scroll:play()
elseif key == "up" then --the solution was so stupid easy
if songs[curIndex - 1] then
curSong = songs[curIndex - 1]
curDiffList = songs[curIndex - 1].difficulties
curDiffInd = 1
curDiff = curDiffList[curDiffInd]
curIndex = curIndex - 1
else
curSong = songs[#songs]
curIndex = #songs
curDiffList = songs[curIndex].difficulties
curDiffInd = 1
curDiff = curDiffList[curDiffInd]
end
curDiffInd = 1
curDiff = curDiffList[1]
diffIMG:PlayAnimation(curDiff, 24, true)
scroll:stop()
scroll:play()
elseif key == "right" then
if curDiffList[curDiffInd + 1] then
curDiff = curDiffList[curDiffInd + 1]
curDiffInd = curDiffInd + 1
else
curDiff = curDiffList[1]
curDiffInd = 1
end
diffIMG:PlayAnimation(curDiff, 24, true)
scroll:stop()
scroll:play()
elseif key == "left" then
if curDiffList[curDiffInd - 1] then
curDiff = curDiffList[curDiffInd - 1]
curDiffInd = curDiffInd - 1
else
curDiff = curDiffList[#curDiffList]
curDiffInd = #curDiffList
end
diffIMG:PlayAnimation(curDiff, 24, true)
scroll:stop()
scroll:play()
elseif key == "p" then --changes character to/from pico hopefully
if curChar == "bf" then
songs = require("charts.picoSongs") --change which catalogue is available
curChar = "pico"
bfAtlas:stop()
bfAtlas:load("sprites/charSelect/picoChill")
bfAtlas:play("pico slide in")
-- flip = true
else
songs = require("charts.songs")
curChar = "bf"
bfAtlas:stop()
bfAtlas:load("sprites/charSelect/bfChill")
bfAtlas:play("bf slide in")
end
flip = false
--reset the index's nd shit
curSong = songs[1]
curIndex = 1
evilCurIndex = 1
curDiffInd = 1
curDiffList = songs[curIndex].difficulties
curDiff = curDiffList[1]
diffIMG:PlayAnimation(curDiff, 24, true)
iconNum = math.random(1,3)
charIcon:PlayAnimation(curChar..iconNum, 24, false)
charSwapSND:stop()
charSwapSND:play()
lastChange = 0
elseif tonumber(key) and tonumber(key) < 5 then
if key == "0" then
settings.Downscroll = not settings.Downscroll
files.write_file("settings.json", json.stringify(settings))
else
gettingKey = tonumber(key)
end
end
else
keybinds[gettingKey] = key
gettingKey = nil
files.write_file("settings.json", json.stringify(settings))
confirm:stop()
confirm:play()
end
end
end
love.window.setMode(1280, 720, { fullscreen = false , resizable = false})
function love.load()
setup()
end