From 01f4bd8d6fc961e82fbe809d2945a603ec14099b Mon Sep 17 00:00:00 2001 From: Madiwka Date: Thu, 20 May 2021 12:04:45 +0000 Subject: [PATCH] added pause functionality and music toggling --- levels/levelgeneral.lua | 17 ++++++++++++++--- main.lua | 1 + readme.md | 2 ++ src/buttonClutter.lua | 7 ++++++- src/dependencies.lua | 1 + src/musicController.lua | 42 ++++++++++++++++++++++++++++++----------- src/pauseMenu.lua | 38 +++++++++++++++++++++++++++++++++++++ src/stateMachine.lua | 7 +++---- 8 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 src/pauseMenu.lua diff --git a/levels/levelgeneral.lua b/levels/levelgeneral.lua index ff952e8..09f3db9 100644 --- a/levels/levelgeneral.lua +++ b/levels/levelgeneral.lua @@ -5,7 +5,16 @@ local thrusterMax = 0 local animationComplete = false local frame = 0 asteroidImage = love.graphics.newImage("entities/planet/asteroid.png") +function love.keyreleased(key) + if key == "escape" and gameStatus == "play" then + if pauseStatus then + pauseStatus = false + else pauseStatus = true + end + end + end function levelgeneral.update(dt) + if not pauseStatus then if not levelLoaded then level = require("levels/level" .. currentLevel) level.load() @@ -63,7 +72,7 @@ else camera:follow(VCAM.x, VCAM.y) end levelgeneral.GUIControl() - +end end function levelgeneral.draw() @@ -129,10 +138,12 @@ function levelgeneral.draw() love.graphics.rectangle("fill",0, WINDOW_HEIGHT-50, firstShip.fuel/2, n) love.graphics.setColor(1,1,1,1) guimenu:butt(playbutts, WINDOW_WIDTH, WINDOW_HEIGHT, 1100, WINDOW_HEIGHT-50, 40, WINDOW_WIDTH/3) - love.keyboard.mouseisReleased = false end end - + if pauseStatus then + drawPauseMenu() + love.keyboard.mouseisReleased = false + end diff --git a/main.lua b/main.lua index b9c46fd..609a4c4 100644 --- a/main.lua +++ b/main.lua @@ -39,6 +39,7 @@ function love.load() print(love.filesystem.areSymlinksEnabled()) print(love.filesystem.createDirectory('.')) love.filesystem.newFile("File") + pauseMake() testwalls = love.filesystem.load("save") if testwalls ~= nil then saveData = love.filesystem.load("save")() diff --git a/readme.md b/readme.md index f5c382b..1dabd32 100644 --- a/readme.md +++ b/readme.md @@ -27,3 +27,5 @@ If you're on arch, install the prerequisites with: Changelog: - Changed practice scoring system - Fixed bug with cannon timers not resetting +- Toggle music button added +- Added the pause menu diff --git a/src/buttonClutter.lua b/src/buttonClutter.lua index 1e3db0b..ba833cc 100644 --- a/src/buttonClutter.lua +++ b/src/buttonClutter.lua @@ -16,8 +16,13 @@ function buttonClutter() DIFFERENCE_Y = myscreen.d OFFSET_X = myscreen.e OFFSET_Y = myscreen.f - end + end)) + table.insert(buttons, menu:addButton("Toggle Music", +function() + toggleMusic() +end )) + table.insert(buttons, menu:addButton("Quit", function() love.event.quit() diff --git a/src/dependencies.lua b/src/dependencies.lua index 77ede3a..57fa391 100644 --- a/src/dependencies.lua +++ b/src/dependencies.lua @@ -8,6 +8,7 @@ require 'entities/planet/planet' require 'src/buttonClutter' require 'entities/explosion/explosion' require 'src/GUI' +require 'src/pauseMenu' require 'src/stateMachine' require 'entities/base/base' require 'entities/camera/VCAM' diff --git a/src/musicController.lua b/src/musicController.lua index f023127..5ba811b 100644 --- a/src/musicController.lua +++ b/src/musicController.lua @@ -12,41 +12,61 @@ music = { } mute = false function musicController(orders, toggling) - if (orders == 'norm' and not mute and not reachedGoal) then + if (orders == 'norm' and not reachedGoal) then if (gameState == 'menu' or gameState == "selectlv") then music['menu']:play() music["play"]:play() - music["play"]:setVolume(0) - music["menu"]:setVolume(1) + if mute then + music["menu"]:setVolume(0) + music["play"]:setVolume(0) + else + --print("music") + music["play"]:setVolume(0) + music["menu"]:setVolume(1) + end elseif gameStatus == 'play' then music["play"]:play() + if mute then + music["menu"]:setVolume(0) + music["play"]:setVolume(0) + else music["play"]:setVolume(0.8) music["menu"]:setVolume(0.2) + end elseif gameStatus == 'setup' then music['menu']:play() music["play"]:play() + if mute then + music["menu"]:setVolume(0) + music["play"]:setVolume(0) + else music["play"]:setVolume(0.6) music["menu"]:setVolume(1) - end - elseif orders == "mute" then - if toggling == 1 then - mute = true - else - mute = false + end end elseif orders == "click" then -- print("entities/camera/button0" .. math.random(1, 5)..".mp3.flac") local tempClick = love.audio.newSource("entities/camera/button0" .. math.random(1, 5)..".mp3.flac", "static") + tempClick:stop() tempClick:play() end end function stopSounds() for i, sound in ipairs(sounds) do sound[i]:stop() - print("stopping sounds") + --print("stopping sounds") end end function stopMusic() music["play"]:setVolume(0) music["menu"]:setVolume(0) -end \ No newline at end of file +end +function toggleMusic() + if mute then + mute = false + else + mute = true + --print("switch") + end + +end \ No newline at end of file diff --git a/src/pauseMenu.lua b/src/pauseMenu.lua new file mode 100644 index 0000000..6317f98 --- /dev/null +++ b/src/pauseMenu.lua @@ -0,0 +1,38 @@ +pauseStatus = false +pauseMenu = {} +function pauseMake() + table.insert(pauseMenu, menu:addButton("Resume", +function() + pauseStatus = false +end +)) +table.insert(pauseMenu, menu:addButton("Main Menu", +function() + pauseStatus = false + goBack() +end +)) +table.insert(pauseMenu, menu:addButton("Toggle Fullscreen", +function() + myscreen:toggle(WINDOW_HEIGHT, WINDOW_WIDTH) + DIFFERENCE_X = myscreen.c + DIFFERENCE_Y = myscreen.d + OFFSET_X = myscreen.e + OFFSET_Y = myscreen.f +end +)) +table.insert(pauseMenu, menu:addButton("Toggle Music", +function() + toggleMusic() +end +)) +table.insert(pauseMenu, menu:addButton("Quit", +function() + love.event.quit() +end +)) +end +function drawPauseMenu() + -- print("draw") + menu:butt(pauseMenu, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 40, WINDOW_WIDTH/3) +end \ No newline at end of file diff --git a/src/stateMachine.lua b/src/stateMachine.lua index 7e03f7e..dee25ef 100644 --- a/src/stateMachine.lua +++ b/src/stateMachine.lua @@ -3,13 +3,12 @@ print("levels/"..gameState) function stateUpdate(dt) state = require("levels/"..gameState) state.update(dt) - if love.keyboard.isDown('escape') then - love.event.quit() - end musicController("norm") end - +function goBack() + state.goBack() +end function stateDraw() state.draw() end \ No newline at end of file