Commit a623d2ae authored by Simon Goller's avatar Simon Goller
Browse files

Let level move and automatically return to heaven

parent fee74b6a
......@@ -25,12 +25,11 @@ impl InGameState {
let world = legion::World::default();
let schedule = legion::Schedule::builder()
.add_system(systems::moving_system())
.add_thread_local(systems::draw_level_layer_system(background))
.add_thread_local(systems::draw_level_layer_system(foreground))
.build();
crate::console_log!("Ingame state is ready");
InGameState {
gui_svg: utils::get_element_by_id("ingame-ui").unwrap(),
world,
......@@ -47,12 +46,6 @@ impl state::State for InGameState {
.set_property("display", "block")
.unwrap();
let rendering = resources::Rendering::new("game-canvas").unwrap();
rendering.set_fill_style(&resources::Color::new_rgb(0.0625, 0.06, 0.125));
rendering.fill_rect(0.0, 0.0, 1920.0, 1080.0);
crate::console_log!("Ingame state initialized ");
state::Transition::Loop
}
......@@ -64,7 +57,20 @@ impl state::State for InGameState {
}
fn update(&mut self) -> state::Transition {
{
let rendering = self.resources.get::<resources::Rendering>().unwrap();
rendering.set_fill_style(&resources::Color::new_rgb(0.0625, 0.06, 0.125));
rendering.fill_rect(0.0, 0.0, 1920.0, 1080.0);
}
self.schedule.execute(&mut self.world, &mut self.resources);
state::Transition::Loop
let done = {
let camera = self.resources.get::<resources::Camera>().unwrap();
camera.position.x > 50.0
};
if done {
state::Transition::Pop
} else {
state::Transition::Loop
}
}
}
......@@ -6,7 +6,7 @@ pub fn draw_level_layer(
#[resource] rendering: &resources::Rendering,
#[resource] camera: &resources::Camera,
) {
let pos = camera.draw_coordinate();
let pos = -camera.position + camera.size / 2.0;
match rendering.draw_image(*handle, pos.x, pos.y) {
Ok(_) => {}
Err(err) => crate::console_log!("Error drawing level layer: {}", err),
......
mod level;
mod moving;
pub use level::draw_level_layer_system;
pub use moving::moving_system;
use crate::resources;
#[legion::system]
pub fn moving(#[resource] camera: &mut resources::Camera) {
camera.position.x += 0.1;
}
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