Skip to content

Commit

Permalink
added pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Apr 2, 2013
1 parent 7a50871 commit b978ef9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 48 deletions.
Binary file modified bin/lava-temple.love
Binary file not shown.
7 changes: 6 additions & 1 deletion bundle.sh
@@ -1,3 +1,4 @@
#!/bin/bash
# LÖVE Boilerplate - A template for the LÖVE framework (love2d)

# Bundle file
Expand Down Expand Up @@ -39,4 +40,8 @@ rm bin/$current_dir.love
zip -r bin/$current_dir.love *

# Start the love app
/Applications/love0.8.0.app/Contents/MacOS/love bin/$current_dir.love
unamestr=`uname`
if [ "$unamestr" == 'Linux' ];
then /usr/bin/love bin/$current_dir.love
else /Applications/love0.8.0.app/Contents/MacOS/love bin/$current_dir.love
fi
97 changes: 51 additions & 46 deletions lib/states/game.lua
Expand Up @@ -3,22 +3,23 @@ game = Gamestate.new()
function game:init()
game_font = love.graphics.newFont("media/fonts/PressStart2P.ttf", 40)
love.graphics.setFont(game_font)
hud = Hud:new()
sfx = Sfx:new()
camera = Camera:new(0, 0)
pause = false
hud = Hud:new()
sfx = Sfx:new()
camera = Camera:new(0, 0)
paused = false
game_started = true

sfx:setLooping("lava", true)
sfx:play("lava")

sfx:setLooping("background", true)
sfx:play("background")

game_started = true
end

function game:enter(previous)
world = World:new("one")
if previous == main_menu then
world = World:new("one")
end
end

function game:shakeScreen(dt)
Expand All @@ -40,55 +41,59 @@ end

function game:gameover()
-- TODO : DRAW GAMEOVER
-- light.luminosity = 0
-- light.luminosity = 0
end

function game:update(dt)
Timer.update(dt)

-- world holds all players, players are accessed via player and second_player
-- global variables right now
for index, player in pairs(world.players) do
player:update(dt)
end

world:update(dt)
player.light:update(dt)
effects:update(dt)

-- Send player data to server in multiplayer and update the client
if client and player then
client:syncPlayerDataWithServer()
client:syncLavaDataWithServer()
client:update(dt)
if world then
Timer.update(dt)

-- world holds all players, players are accessed via player and second_player
-- global variables right now
for index, player in pairs(world.players) do
player:update(dt)
end

world:update(dt)
player.light:update(dt)
effects:update(dt)

-- Send player data to server in multiplayer and update the client
if client and player then
client:syncPlayerDataWithServer()
client:syncLavaDataWithServer()
client:update(dt)
end

-- Move the camera with the player, but only on the y-axis
camera:setPosition(0, player:getY() - 500)

-- Game is over if all player lives are gone
if player:getLives() <= 0 then self:gameover() end

-- Shake the screen (the closer the lava, the stronger it shakes)
if lava and player then self:shakeScreen(dt) end
end

-- Move the camera with the player, but only on the y-axis
camera:setPosition(0, player:getY() - 500)

-- Game is over if all player lives are gone
if player:getLives() <= 0 then self:gameover() end

-- Shake the screen (the closer the lava, the stronger it shakes)
if lava and player then self:shakeScreen(dt) end
end

function game:draw()
camera:set()
self:drawScreenShake()
camera:drawLayers()
world:draw()
effects:draw()
player.light:draw()
hud:drawRelativeMessages()
camera:unset()
hud:draw()
if world then
camera:set()
self:drawScreenShake()
camera:drawLayers()
world:draw()
effects:draw()
player.light:draw()
hud:drawRelativeMessages()
camera:unset()
hud:draw()
end
end

function game:keypressed(key, code)
if key == "f" then
love.graphics.setMode(1440, 900, false, true, 0)
love.graphics.toggleFullscreen()
if key == "escape" then
paused = not paused
Gamestate.switch(pause_menu)
elseif key == "s" then
game_started = not game_started
end
Expand Down
2 changes: 1 addition & 1 deletion lib/states/main_menu.lua
Expand Up @@ -51,7 +51,7 @@ function main_menu:update(dt)
gui.Input{info = host_input, size = {300}}

gui.Label{text = "Your multiplayer name", size = {70}}
gui.Input{info = id_input, size = {300}}
gui.Input{info = id_input, size = {300}}

gui.group.pop{}
end
Expand Down
44 changes: 44 additions & 0 deletions lib/states/pause_menu.lua
@@ -0,0 +1,44 @@
pause_menu = Gamestate.new()

function pause_menu:init()
-- group defaults
gui.group.default.size[1] = 150
gui.group.default.size[2] = 25
gui.group.default.spacing = 5
end

function pause_menu:enter(previous)

end

function pause_menu:update(dt)
gui.group.push{grow = "down", pos = {(love.graphics.getWidth() / 2) - 130, 200}}

if gui.Button{text = "Resume"} then
Gamestate.switch(game)
end

if gui.Button{text = "Fullscreen"} then
love.graphics.setMode(1680, 1050, false, true, 0)
love.graphics.toggleFullscreen()
end

if gui.Button{text = "Main Menu"} then
Gamestate.switch(main_menu)
end

gui.group.pop{}
end

function pause_menu:draw()
game:draw()
gui.core.draw()
end

function pause_menu:keypressed(key, code)
gui.keyboard.pressed(key, code)
if key == "escape" then
paused = not paused
Gamestate.switch(game)
end
end
1 change: 1 addition & 0 deletions main.lua
Expand Up @@ -33,6 +33,7 @@ require("lib.entities.chest")
Gamestate = require('lib.vendor.hump.gamestate')
require("lib.states.game")
require("lib.states.main_menu")
require("lib.states.pause_menu")
require("lib.states.game_server")

--timer
Expand Down

0 comments on commit b978ef9

Please sign in to comment.