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

resources: Add GameManager

The GameManager provides a way for systems to schedule a transition back
to the heaven.
parent 96901f6e
pub struct GameManager {
return_to_heaven: bool,
}
impl GameManager {
pub fn new() -> GameManager {
GameManager {
return_to_heaven: false,
}
}
pub fn request_return_to_heaven(&mut self) {
self.return_to_heaven = true;
}
pub fn wants_return_to_heaven(&self) -> bool {
self.return_to_heaven
}
}
mod camera;
mod clock;
mod game_manager;
mod player;
mod rendering;
pub use camera::Camera;
pub use clock::Clock;
pub use game_manager::GameManager;
pub use player::Player;
pub use rendering::Color;
pub use rendering::ImageHandle;
......
......@@ -5,6 +5,7 @@ use crate::components;
use crate::entities;
use crate::gamestate;
use crate::resources;
use crate::states;
use crate::svg_loader;
use crate::systems;
use crate::utils;
......@@ -40,6 +41,7 @@ impl InGameState {
let player = entities::create_player(&mut world, &resources, &level, player);
resources.insert(resources::Player(player));
resources.insert(resources::GameManager::new());
level.apply_colliders(&mut world);
let mut schedule_builder = legion::Schedule::builder();
......@@ -122,6 +124,8 @@ impl gamestate::State for InGameState {
}
fn update(&mut self) -> gamestate::Transition {
use legion::IntoQuery;
{
let rendering = self.resources.get::<resources::Rendering>().unwrap();
rendering.set_transform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
......@@ -129,6 +133,20 @@ impl gamestate::State for InGameState {
rendering.fill_rect(0.0, 0.0, 1920.0, 1080.0);
}
self.schedule.execute(&mut self.world, &mut self.resources);
gamestate::Transition::Loop
if self
.resources
.get::<resources::GameManager>()
.unwrap()
.wants_return_to_heaven()
{
let player_ent = self.resources.get::<resources::Player>().unwrap().0.clone();
let player = <&components::Player>::query()
.get(&self.world, player_ent)
.unwrap();
gamestate::Transition::replace(states::HeavenState::new(Some(player.clone())))
} else {
gamestate::Transition::Loop
}
}
}
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