added game over + victory screens
This commit is contained in:
@@ -2,6 +2,8 @@ local LoveNode = require 'src.utils.love_node'
|
||||
local MainMenu = require 'src.core.states.main_menu'
|
||||
local Game = require 'src.core.states.game'
|
||||
local PauseMenu = require 'src.core.states.pause_menu'
|
||||
local GameOver = require 'src.core.states.gameover'
|
||||
local Victory = require 'src.core.states.victory'
|
||||
|
||||
local GameCore = {}
|
||||
GameCore.__index = GameCore
|
||||
@@ -13,8 +15,10 @@ function GameCore.new()
|
||||
self.stateStack = {}
|
||||
self.states = {
|
||||
mainmenu = MainMenu.new(self),
|
||||
game = Game.new(self, 8, 10),
|
||||
pausemenu = PauseMenu.new(self)
|
||||
game = Game.new(self, 19, 10),
|
||||
pausemenu = PauseMenu.new(self),
|
||||
gameover = GameOver.new(self),
|
||||
victory = Victory.new(self)
|
||||
}
|
||||
self:pushState(self.states.mainmenu)
|
||||
|
||||
@@ -42,14 +46,14 @@ function GameCore:resize(w, h)
|
||||
end
|
||||
end
|
||||
|
||||
function GameCore:switchState(newState)
|
||||
function GameCore:switchState(newState, ...)
|
||||
self:popState()
|
||||
self:pushState(newState)
|
||||
self:pushState(newState, ...)
|
||||
end
|
||||
|
||||
function GameCore:pushState(newState)
|
||||
function GameCore:pushState(newState, ...)
|
||||
table.insert(self.stateStack, newState)
|
||||
newState:enter()
|
||||
newState:enter(...)
|
||||
end
|
||||
|
||||
function GameCore:popState()
|
||||
|
||||
@@ -166,7 +166,7 @@ function Game:resize(w, h)
|
||||
end
|
||||
|
||||
function Game:failLevel()
|
||||
self.core:switchState(self.core.states.mainmenu)
|
||||
self.core:switchState(self.core.states.gameover)
|
||||
end
|
||||
|
||||
function Game:nextLevel()
|
||||
|
||||
46
src/core/states/gameover.lua
Normal file
46
src/core/states/gameover.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local Menu = require 'src.utils.menu'
|
||||
local component = require 'packages.badr'
|
||||
local button = require 'src.display.components.button'
|
||||
local label = require 'src.display.components.label'
|
||||
|
||||
local GameOver = {}
|
||||
GameOver.__index = GameOver
|
||||
|
||||
function GameOver.new(core)
|
||||
setmetatable(GameOver, { __index = Menu })
|
||||
local self = setmetatable(Menu.new(core), GameOver)
|
||||
|
||||
self:_initializeScreens()
|
||||
self:_pushScreen(self.screens.root)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GameOver:_initializeScreens()
|
||||
self.screens.root = self:_createRoot()
|
||||
end
|
||||
|
||||
-- Screens
|
||||
|
||||
function GameOver:_createRoot()
|
||||
local root = component { column = true, gap = 10 }
|
||||
+ label { text = 'Game Over' }
|
||||
+ button {
|
||||
text = 'Retry',
|
||||
width = 200,
|
||||
onClick = function() self.core:switchState(self.core.states.mainmenu) end
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit to desktop',
|
||||
width = 200,
|
||||
onClick = function() love.event.quit() end
|
||||
}
|
||||
root:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - root.width * 0.5,
|
||||
love.graphics.getHeight() * 0.5 - root.height * 0.5
|
||||
)
|
||||
|
||||
return root
|
||||
end
|
||||
|
||||
return GameOver
|
||||
46
src/core/states/victory.lua
Normal file
46
src/core/states/victory.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local Menu = require 'src.utils.menu'
|
||||
local component = require 'packages.badr'
|
||||
local button = require 'src.display.components.button'
|
||||
local label = require 'src.display.components.label'
|
||||
|
||||
local Victory = {}
|
||||
Victory.__index = Victory
|
||||
|
||||
function Victory.new(core)
|
||||
setmetatable(Victory, { __index = Menu })
|
||||
local self = setmetatable(Menu.new(core), Victory)
|
||||
|
||||
self:_initializeScreens()
|
||||
self:_pushScreen(self.screens.root)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Victory:_initializeScreens()
|
||||
self.screens.root = self:_createRoot()
|
||||
end
|
||||
|
||||
-- Screens
|
||||
|
||||
function Victory:_createRoot()
|
||||
local root = component { column = true, gap = 10 }
|
||||
+ label { text = 'You win' }
|
||||
+ button {
|
||||
text = 'Play again',
|
||||
width = 200,
|
||||
onClick = function() self.core:switchState(self.core.states.mainmenu) end
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit to desktop',
|
||||
width = 200,
|
||||
onClick = function() love.event.quit() end
|
||||
}
|
||||
root:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - root.width * 0.5,
|
||||
love.graphics.getHeight() * 0.5 - root.height * 0.5
|
||||
)
|
||||
|
||||
return root
|
||||
end
|
||||
|
||||
return Victory
|
||||
Reference in New Issue
Block a user