Commit 94fc5be2 authored by Rahix's avatar Rahix 🦀
Browse files

Don't return to heaven immediately

Show a banner message that a return to heaven is imminent and count down
for 3 seconds before going back to heaven.  This makes the game flow
a bit smoother as it provides an indication to the player that the
challenge is completed now.
parent 381ac328
pub struct GameManager { pub struct GameManager {
return_to_heaven: bool, pub return_timeout: Option<f64>,
pub return_timestamp: Option<f64>,
} }
impl GameManager { impl GameManager {
pub fn new() -> GameManager { pub fn new() -> GameManager {
GameManager { GameManager {
return_to_heaven: false, return_timeout: None,
return_timestamp: None,
} }
} }
pub fn request_return_to_heaven(&mut self) { pub fn request_return_to_heaven(&mut self) {
self.return_to_heaven = true; self.return_timeout.get_or_insert(0.0);
} }
pub fn wants_return_to_heaven(&self) -> bool { pub fn wants_return_to_heaven(&self) -> bool {
self.return_to_heaven self.return_timeout.map_or(false, |t| t >= 3.0)
} }
} }
...@@ -59,6 +59,7 @@ impl InGameState { ...@@ -59,6 +59,7 @@ impl InGameState {
schedule_builder schedule_builder
.flush() .flush()
.add_thread_local(systems::update_game_manager_system())
.add_thread_local(systems::move_camera_to_player_system()) .add_thread_local(systems::move_camera_to_player_system())
.add_thread_local(systems::camera_system()) .add_thread_local(systems::camera_system())
.add_thread_local(systems::update_sanity_bar_system(sanity_bar)) .add_thread_local(systems::update_sanity_bar_system(sanity_bar))
......
use crate::resources;
use crate::utils;
#[legion::system]
pub fn update_game_manager(
#[resource] clock: &resources::Clock,
#[resource] game_manager: &mut resources::GameManager,
) {
if let Some(timeout) = game_manager.return_timeout.as_mut() {
if game_manager.return_timestamp.is_none() {
utils::get_element_by_id::<web_sys::SvgElement>("ingame-return-to-heaven")
.unwrap()
.style()
.set_property("display", "block")
.unwrap();
}
let now = clock.wall_time();
let timestamp = *game_manager.return_timestamp.get_or_insert(now);
*timeout = now - timestamp;
utils::get_element_by_id::<web_sys::Element>("ingame-return-secs")
.unwrap()
.set_inner_html(&format!("{:.0}", (3.0 - *timeout).ceil()));
if game_manager.wants_return_to_heaven() {
utils::get_element_by_id::<web_sys::SvgElement>("ingame-return-to-heaven")
.unwrap()
.style()
.set_property("display", "none")
.unwrap();
}
}
}
mod camera; mod camera;
mod draw_colliders; mod draw_colliders;
mod game_manager;
mod level; mod level;
mod moving; mod moving;
mod player; mod player;
...@@ -8,6 +9,7 @@ mod tmp_stationary_obstacles; ...@@ -8,6 +9,7 @@ mod tmp_stationary_obstacles;
pub use camera::camera_system; pub use camera::camera_system;
pub use draw_colliders::draw_debug_colliders_system; pub use draw_colliders::draw_debug_colliders_system;
pub use game_manager::update_game_manager_system;
pub use level::draw_level_layer_system; pub use level::draw_level_layer_system;
pub use moving::{move_camera_to_player_system, move_movable_system}; pub use moving::{move_camera_to_player_system, move_movable_system};
pub use player::{sanity_goes_up_and_down_system, update_sanity_bar_system}; pub use player::{sanity_goes_up_and_down_system, update_sanity_bar_system};
......
...@@ -14,6 +14,20 @@ ...@@ -14,6 +14,20 @@
<text x="960" y="80" class="sanity">SANITY</text> <text x="960" y="80" class="sanity">SANITY</text>
<rect x="460" y="100" width="600" height="40" class="sanity-amount" id="sanity-amount" /> <rect x="460" y="100" width="600" height="40" class="sanity-amount" id="sanity-amount" />
<rect x="460" y="100" width="1000" height="40" class="sanity-outline" /> <rect x="460" y="100" width="1000" height="40" class="sanity-outline" />
<g id="ingame-return-to-heaven" style="display: none">
<defs>
<filter id="blur-back-to-heaven">
<feGaussianBlur in="SourceGraphic" stdDeviation="15" />
</filter>
</defs>
<rect x="160" y="190" width="1600" height="160" class="overlay-backdrop" filter="url(#blur-back-to-heaven)" />
<text x="960" y="300" class="header">
Returning to HEAVEN in
<tspan id="ingame-return-secs">3</tspan>
...
</text>
</g>
</svg> </svg>
<svg id="heaven-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: none"> <svg id="heaven-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: none">
<!-- GUI for the "heaven" --> <!-- GUI for the "heaven" -->
......
...@@ -55,6 +55,10 @@ div.game { ...@@ -55,6 +55,10 @@ div.game {
text-anchor: middle; text-anchor: middle;
} }
rect.overlay-backdrop {
fill: transparentize($primary1-shade3, 0.3);
}
text.footer { text.footer {
fill: $primary3-shade1; fill: $primary3-shade1;
font-family: "Montserrat"; font-family: "Montserrat";
......
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