Browse Source

added pause functionality and music toggling

tags/8.1
Madiwka 3 years ago
parent
commit
01f4bd8d6f
8 changed files with 96 additions and 19 deletions
  1. +14
    -3
      levels/levelgeneral.lua
  2. +1
    -0
      main.lua
  3. +2
    -0
      readme.md
  4. +6
    -1
      src/buttonClutter.lua
  5. +1
    -0
      src/dependencies.lua
  6. +31
    -11
      src/musicController.lua
  7. +38
    -0
      src/pauseMenu.lua
  8. +3
    -4
      src/stateMachine.lua

+ 14
- 3
levels/levelgeneral.lua View File

@@ -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


+ 1
- 0
main.lua View File

@@ -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")()


+ 2
- 0
readme.md View File

@@ -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

+ 6
- 1
src/buttonClutter.lua View File

@@ -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()


+ 1
- 0
src/dependencies.lua View File

@@ -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'


+ 31
- 11
src/musicController.lua View File

@@ -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
end
function toggleMusic()
if mute then
mute = false
else
mute = true
--print("switch")
end
end

+ 38
- 0
src/pauseMenu.lua View File

@@ -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

+ 3
- 4
src/stateMachine.lua View File

@@ -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

Loading…
Cancel
Save