Commit 26a09ced authored by Rahix's avatar Rahix 🦀
Browse files

states: Add a "Game Over" state

Add a game over state where the player can choose to start a new game or
quit.
parent aa57da0c
use crate::gamestate;
use crate::states;
use crate::utils;
pub struct GameOverState {
gui_svg: web_sys::SvgElement,
}
impl GameOverState {
pub fn new() -> GameOverState {
GameOverState {
gui_svg: utils::get_element_by_id("game-over-ui").unwrap(),
}
}
}
impl gamestate::State for GameOverState {
fn init(&mut self, mut init: gamestate::StateInitializer) -> gamestate::Transition {
init.register_onclick("game-over-replay");
init.register_onclick("game-over-quit");
self.gui_svg
.style()
.set_property("display", "block")
.unwrap();
gamestate::Transition::Sleep
}
fn deinit(&mut self) {
self.gui_svg
.style()
.set_property("display", "none")
.unwrap();
}
fn event(&mut self, event: gamestate::Event) -> gamestate::Transition {
match event {
gamestate::Event::MouseClick {
target: "game-over-replay",
..
} => gamestate::Transition::push(states::HeavenState::new(None)),
gamestate::Event::MouseClick {
target: "game-over-quit",
..
} => gamestate::Transition::Pop,
event => {
crate::console_warn!("unknown event {:?}", event);
gamestate::Transition::Keep
}
}
}
}
mod game_over;
mod heaven;
mod ingame;
mod level_loading;
mod main_menu;
pub use game_over::GameOverState;
pub use heaven::HeavenState;
pub use ingame::InGameState;
pub use level_loading::LevelLoadingState;
......
......@@ -89,6 +89,21 @@
<text x="0" y="0">START SHIFT</text>
</g>
</svg>
<svg id="game-over-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: none">
<!-- GUI for the Game Over screen -->
<rect x="0" y="0" width="1920" height="1080" class="background" />
<text x="960" y="300" class="header">Game Over</text>
<g id="game-over-replay" transform="translate(960, 500)" class="big-button button-1">
<rect x="-350" y="-60" width="700" height="120" />
<text x="0" y="0">Start New Game</text>
</g>
<g id="game-over-quit" transform="translate(960, 650)" class="big-button button-3">
<rect x="-120" y="-60" width="240" height="120" />
<text x="0" y="0">Quit</text>
</g>
</svg>
<svg id="menu-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: block">
<!-- GUI for the main menu -->
<rect x="0" y="0" width="1920" height="1080" class="background" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment