Commit d0e87714 authored by Rahix's avatar Rahix 🦀
Browse files

Use Game-Over state when player goes insane

When player sanity reaches zero, transition to the "Game Over" state via
a new GameManager API.
parent 26a09ced
......@@ -142,6 +142,6 @@ pub fn update_bottle_shift(
.unwrap();
player.collected_hours += *hours_to_award as u32;
*hours_to_award = 0;
game_manager.request_return_to_heaven(false);
game_manager.request_return_to_heaven();
}
}
......@@ -139,6 +139,6 @@ pub fn update_network_switch_shift(
.unwrap();
player.collected_hours += *hours_to_award as u32;
*hours_to_award = 0;
game_manager.request_return_to_heaven(false);
game_manager.request_return_to_heaven();
}
}
......@@ -11,9 +11,4 @@ impl Player {
collected_hours: 0,
}
}
pub fn reset(&mut self) {
self.sanity = 1.0;
self.collected_hours = 0;
}
}
......@@ -13,12 +13,19 @@ impl GameManager {
}
}
pub fn request_return_to_heaven(&mut self, game_over: bool) {
self.game_over = game_over;
pub fn request_return_to_heaven(&mut self) {
self.return_timeout.get_or_insert(0.0);
}
pub fn request_game_over(&mut self) {
self.game_over = true;
}
pub fn wants_return_to_heaven(&self) -> bool {
self.return_timeout.map_or(false, |t| t >= 3.0)
}
pub fn wants_game_over(&self) -> bool {
self.game_over
}
}
......@@ -166,13 +166,12 @@ impl gamestate::State for InGameState {
let game_manager = self.resources.get::<resources::GameManager>().unwrap();
if game_manager.wants_return_to_heaven() {
let player_ent = self.resources.get::<resources::Player>().unwrap().0.clone();
let player = <&mut components::Player>::query()
.get_mut(&mut self.world, player_ent)
let player = <&components::Player>::query()
.get(&self.world, player_ent)
.unwrap();
if game_manager.game_over {
player.reset();
}
gamestate::Transition::replace(states::HeavenState::new(Some(player.clone())))
} else if game_manager.wants_game_over() {
gamestate::Transition::replace(states::GameOverState::new())
} else {
gamestate::Transition::Loop
}
......
......@@ -38,7 +38,6 @@ pub fn player_sanity_check(
let player = players.get_mut(world, player.0).unwrap();
if player.sanity <= 0.0 {
// TODO: Game Over Screen
game_manager.request_return_to_heaven(true);
game_manager.request_game_over();
}
}
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