From 94bac4afaac600df0bdade6f205ab089fe3aec4a Mon Sep 17 00:00:00 2001 From: entar Date: Sat, 31 May 2025 14:52:15 +0700 Subject: [PATCH] Added screen bopping (screen zoom) and return to menu (esc or song end) --- .vscode/settings.json | 3 ++- main.lua | 11 ++++++---- modules/states/playstate.lua | 42 ++++++++++++++++++++++++++++-------- modules/types.lua | 19 ++++++++++++++++ settings.json | 2 +- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index dd7c74f..857a588 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "Lua.diagnostics.disable": [ - "different-requires" + "different-requires", + "need-check-nil" ] } \ No newline at end of file diff --git a/main.lua b/main.lua index 061b560..2c27b3e 100644 --- a/main.lua +++ b/main.lua @@ -23,9 +23,7 @@ local pressed = {false,false,false} -- break -- end -local gf = myTypes.Sprite("sprites/GF_assets.png", "sprites/GF_assets.json") -gf.position = myTypes.Vector2(30, 30) -gf:PlayAnimation("GF Dancing Beat", 24, true) +local gf function love.update(dt) if curState and curState.loaded then @@ -37,8 +35,11 @@ function love.update(dt) end elseif not curState then if love.keyboard.isDown("return") then - gf:Destroy() curState = state(curSong, curDiff) + curState.quit = function() + curState = nil + myTypes.destroyAllSprites() + end curState.load() elseif love.keyboard.isDown("down") and not pressed[1] then curSong = next(songs, curSong) @@ -87,3 +88,5 @@ function love.draw() love.graphics.print(string.format("Song: %s, Difficulty: %s, List: %s", curSong, curDiff, logging.dump(curDiffList)), love.graphics.newFont(15, "light"), love.graphics:getWidth()/2, love.graphics:getHeight()/2 + 150, 0, 1, 1, 200) end end + +love.window.setMode(1280, 720, { fullscreen = false , resizable = true}) \ No newline at end of file diff --git a/modules/states/playstate.lua b/modules/states/playstate.lua index 055a4bc..ce3a907 100644 --- a/modules/states/playstate.lua +++ b/modules/states/playstate.lua @@ -66,6 +66,21 @@ return function(songName, songDifficulty) local keyBinds = {} + local function quit() + inst:stop() + inst:release() + + voices:stop() + voices:release() + + miss:stop() + miss:release() + + state.quit() + end + + local zoom = 1 + local function checkNote(dir) if pressed[dir] or holded[dir] then pressed[dir] = false @@ -107,7 +122,7 @@ return function(songName, songDifficulty) beat = conductor:getBeatRounded(elapsed) if beat ~= oldBeat then - if beat % 2 == 0 then + if beat % 2 == 0 then -- gf:PlayAnimation("BF NOTE LEFT", 30, false) for name, character in next, characters do if not character.singing then @@ -120,7 +135,10 @@ return function(songName, songDifficulty) end end end - end + if beat % 4 == 0 then + zoom = zoom + .1 + end + end end local section = chart.notes[math.floor(step / 16) + 1] @@ -158,6 +176,10 @@ return function(songName, songDifficulty) pressed[4] = false end + if love.keyboard.isDown("escape") then + state.quit() + end + for index, note in next, notes do if note.position - conductor.songPosition < 0 then if note.mustPress then @@ -214,25 +236,27 @@ return function(songName, songDifficulty) end if not inst:isPlaying() then - love.event.quit() + state.quit() end + + zoom = myMath.lerp(zoom, 1, .05) end local mainCanvas = love.graphics.newCanvas(1920, 1080) function state.draw() - love.graphics.setCanvas(mainCanvas) + love.graphics.setCanvas(mainCanvas) - love.graphics.clear() + love.graphics.clear() - love.graphics.circle("fill", 960, 59, 50000) + love.graphics.circle("fill", 960, 59, 50000) - myTypes.drawSprites() + myTypes.drawSprites() - love.graphics.setCanvas() + love.graphics.setCanvas() - love.graphics.draw(mainCanvas, 0, 0, 0, (love.graphics:getHeight() / 1080) * (4/3), love.graphics:getHeight() / 1080) + love.graphics.draw(mainCanvas, (love.graphics:getHeight() * (4/3) - (love.graphics:getHeight()* (4/3)) * zoom) / 2, (love.graphics:getHeight()- love.graphics:getHeight() * zoom) / 2, 0, ((love.graphics:getHeight() / 1080) * (4/3)) * zoom, (love.graphics:getHeight() / 1080) * zoom) end diff --git a/modules/types.lua b/modules/types.lua index 902fb93..73aaec4 100644 --- a/modules/types.lua +++ b/modules/types.lua @@ -32,6 +32,10 @@ function Vector2:Add(addVector2) return module.Vector2(self.x + addVector2.x, self.y + addVector2.y) end +function Vector2:Mul(num) + return module.Vector2(self.x * num, self.y * num) +end + function module.Vector2(x, y) return setmetatable({x = x or 0, y = y or 0}, Vector2) end @@ -105,6 +109,11 @@ function Sprite:Destroy() for index, rect in next, Rects do if rect == self then table.remove(Rects, index) + -- for name, animation in next, rect.quads do + -- for index, quad in next, animation do + -- quad:release() + -- end + -- end end end self = nil @@ -112,6 +121,11 @@ function Sprite:Destroy() for index, sprite in next, Sprites do if sprite == self then table.remove(Sprites, index) + -- for name, animation in next, sprite.quads do + -- for index, quad in next, animation do + -- quad:release() + -- end + -- end end end self = nil @@ -254,4 +268,9 @@ module.note = noteclass.note characterclass.myTypes = module module.character = characterclass.character +function module.destroyAllSprites() + Sprites = {} + Rects = {} +end + return module diff --git a/settings.json b/settings.json index 4015627..e9e081a 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,5 @@ { "Keybinds": [ - "d", "f", "j", "k" + "a", "s", "up", "right" ] } \ No newline at end of file