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

Merge 'Add dedicated WinState/WinScreen'

Closes #24

See merge request !44
parents ba9e0b92 9a968e89
......@@ -76,7 +76,11 @@ impl gamestate::State for HeavenState {
.style()
.set_property("display", "block")
.unwrap();
gamestate::Transition::Loop
if self.player.collected_hours >= 30 {
gamestate::Transition::replace(states::WinState::new(Some(self.player.clone())))
} else {
gamestate::Transition::Loop
}
}
fn deinit(&mut self) {
......
......@@ -166,7 +166,7 @@ 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 = <&components::Player>::query()
let player: &components::Player = <&components::Player>::query()
.get(&self.world, player_ent)
.unwrap();
gamestate::Transition::replace(states::HeavenState::new(Some(player.clone())))
......
......@@ -3,9 +3,11 @@ mod heaven;
mod ingame;
mod level_loading;
mod main_menu;
mod win;
pub use game_over::GameOverState;
pub use heaven::HeavenState;
pub use ingame::InGameState;
pub use level_loading::LevelLoadingState;
pub use main_menu::MainMenuState;
pub use win::WinState;
use crate::colors;
use crate::components;
use crate::gamestate;
use crate::resources;
use crate::utils;
pub struct WinState {
gui_svg: web_sys::SvgElement,
node_world: legion::World,
resources: legion::Resources,
node_schedule: legion::Schedule,
}
impl WinState {
pub fn new(_player: Option<components::Player>) -> WinState {
let (node_world, resources, node_schedule) = init_orbiting_nodes();
WinState {
gui_svg: utils::get_element_by_id("win-ui").unwrap(),
node_world,
resources,
node_schedule,
}
}
}
impl gamestate::State for WinState {
fn init(&mut self, mut _init: gamestate::StateInitializer) -> gamestate::Transition {
self.gui_svg
.style()
.set_property("display", "block")
.unwrap();
gamestate::Transition::Loop
}
fn deinit(&mut self) {
self.gui_svg
.style()
.set_property("display", "none")
.unwrap();
}
fn update(&mut self, timestamp: f64) -> gamestate::Transition {
self.resources
.get_mut::<resources::Clock>()
.unwrap()
.update(timestamp);
{
let rendering = self.resources.get_mut::<resources::Rendering>().unwrap();
rendering.set_fill_style(&colors::BACKGROUND);
rendering.fill_rect(0.0, 0.0, 1920.0, 1080.0);
}
self.node_schedule
.execute(&mut self.node_world, &mut self.resources);
gamestate::Transition::Loop
}
fn event(&mut self, event: gamestate::Event) -> gamestate::Transition {
match event {
event => {
crate::console_log!("unknown event {:?}", event);
gamestate::Transition::Keep
}
}
}
}
fn init_orbiting_nodes() -> (legion::World, legion::Resources, legion::Schedule) {
let mut resources = legion::Resources::default();
resources.insert(resources::Clock::new());
resources.insert(resources::Rendering::new("game-canvas").unwrap());
let mut node_world = legion::World::default();
let n0 = node_world.push((
components::Node::new(),
components::Position::new(800.0, 340.0),
components::OrbitBody::new(5.0, 10.0),
components::Gravity,
));
let n1 = node_world.push((
components::Node::new(),
components::Position::new(120.0, 300.0),
components::OrbitBody::new(5.0, -5.0),
components::Gravity,
));
let n2 = node_world.push((
components::Node::new(),
components::Position::new(700.0, 740.0),
components::OrbitBody::new(8.0, -4.0),
components::Gravity,
));
let n3 = node_world.push((
components::Node::new(),
components::Position::new(340.0, 290.0),
components::OrbitBody::new(10.0, 0.0),
components::Gravity,
));
let n4 = node_world.push((
components::Node::new(),
components::Position::new(300.0, 400.0),
components::OrbitBody::new(0.0, 10.0),
components::Gravity,
));
node_world.push((components::Edge::new(n0, n1),));
node_world.push((components::Edge::new(n1, n2),));
node_world.push((components::Edge::new(n0, n2),));
node_world.push((components::Edge::new(n2, n3),));
node_world.push((components::Edge::new(n3, n4),));
node_world.push((components::Edge::new(n0, n4),));
node_world.push((components::TheSun, components::Position::new(600.0, 540.0)));
let node_schedule = legion::Schedule::builder()
.add_system(components::update_gravity_system())
.add_system(components::update_movement_system())
.add_thread_local(components::update_nodes_system())
.flush()
.add_thread_local(components::draw_edges_system())
.add_thread_local(components::draw_nodes_system())
.add_thread_local(components::draw_thesun_system())
.build();
(node_world, resources, node_schedule)
}
......@@ -105,6 +105,11 @@
<rect x="-120" y="-60" width="240" height="120" />
<text x="0" y="0">Quit</text>
</g>
</svg>
<svg id="win-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: none">
<!-- GUI for the WIN screen -->
<rect x="0" y="0" width="1920" height="1080" class="transparent-background" />
<text x="960" y="140" class="header">You have won!</text>
</svg>
<svg id="menu-ui" class="game-gui" viewBox="0 0 1920 1080" style="display: block">
<!-- GUI for the main menu -->
......
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