Commit 0001f127 authored by Rahix's avatar Rahix 🦀
Browse files

Merge 'Don't return to heaven immediately'

See merge request !33
parents 3947622b a530f5e1
......@@ -103,7 +103,7 @@ pub fn collect_bottledrops(
#[legion::system]
#[write_component(components::Player)]
pub fn update_bottle_shift(
#[state] hours_to_award: &usize,
#[state] hours_to_award: &mut usize,
world: &mut legion::world::SubWorld,
#[resource] player: &mut resources::Player,
#[resource] bottle_angel_state: &mut BottleAngelState,
......@@ -116,6 +116,7 @@ pub fn update_bottle_shift(
.get_mut(world, player.0)
.unwrap();
player.collected_hours += *hours_to_award as u32;
*hours_to_award = 0;
game_manager.request_return_to_heaven();
}
}
......@@ -32,7 +32,6 @@ impl Clock {
let timestamp = timestamp / 1000.0;
self.frame_delta = self.max_delta.min((timestamp - self.last_tick) as f32);
self.last_tick = timestamp;
crate::console_log!("Frame delta: {}", self.frame_delta());
}
pub fn wall_time(&self) -> f64 {
......
pub struct GameManager {
return_to_heaven: bool,
pub return_timeout: Option<f64>,
pub return_timestamp: Option<f64>,
}
impl GameManager {
pub fn new() -> GameManager {
GameManager {
return_to_heaven: false,
return_timeout: None,
return_timestamp: None,
}
}
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 {
self.return_to_heaven
self.return_timeout.map_or(false, |t| t >= 3.0)
}
}
......@@ -59,6 +59,7 @@ impl InGameState {
schedule_builder
.flush()
.add_thread_local(systems::update_game_manager_system())
.add_thread_local(systems::move_camera_to_player_system())
.add_thread_local(systems::camera_system())
.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 draw_colliders;
mod game_manager;
mod level;
mod moving;
mod player;
......@@ -8,6 +9,7 @@ mod tmp_stationary_obstacles;
pub use camera::camera_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 moving::{move_camera_to_player_system, move_movable_system};
pub use player::{sanity_goes_up_and_down_system, update_sanity_bar_system};
......
......@@ -14,6 +14,20 @@
<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="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 id="heaven-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: none">
<!-- GUI for the "heaven" -->
......
......@@ -55,6 +55,10 @@ div.game {
text-anchor: middle;
}
rect.overlay-backdrop {
fill: transparentize($primary1-shade3, 0.3);
}
text.footer {
fill: $primary3-shade1;
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