diff --git a/src/main.rs b/src/main.rs index d8d130b..98c9433 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ fn main() -> amethyst::Result<()> { //amethyst::start_logger(Default::default()); // Gets the root directory of the application - let mut app_root = PathBuf::from_str("/home/mrh/source/amethyst-starter-2d/")?; + let mut app_root = PathBuf::from_str("/home/mrh/source/flappy-bird-rust/")?; // join on the resources path, and the config. let resources = app_root.join("resources"); diff --git a/src/state.rs b/src/state.rs index 7bed6aa..faf627d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -12,9 +12,9 @@ use amethyst::{ use log::info; use crate::components::*; use std::collections::HashMap; +use crate::systems::BirbGravity; pub struct MyState; - impl SimpleState for MyState { // On start will run when this state is initialized. For more @@ -36,6 +36,7 @@ impl SimpleState for MyState { // Load our sprites and display them let sprites = load_sprites(world); init_sprites(world, &sprites, &dimensions); + } fn handle_event( @@ -50,14 +51,9 @@ impl SimpleState for MyState { return Trans::Quit; } - // Listen to any key events - if let Some(event) = get_key(&event) { - // info!("handling key event: {:?}", event); + if is_key_down(&event, VirtualKeyCode::P) { + return Trans::Push(Box::new(PausedState)); } - - // If you're looking for a more sophisticated event handling solution, - // including key bindings and gamepad support, please have a look at - // https://book.amethyst.rs/stable/pong-tutorial/pong-tutorial-03.html#capturing-user-input } // Keep going @@ -196,3 +192,36 @@ fn init_sprites(world: &mut World, sprites: &HashMap, dime .build(); } + + +pub struct PausedState; +impl SimpleState for PausedState { + + fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { + let world = data.world; + let dimensions = (*world.read_resource::()).clone(); + + let storage = world.read_storage::(); + } + + fn handle_event( + &mut self, + mut _data: StateData<'_, GameData<'_, '_>>, + event: StateEvent, + ) -> SimpleTrans { + + if let StateEvent::Window(event) = &event { + // Check if the window should be closed + if is_key_down(&event, VirtualKeyCode::Space) { + return Trans::Pop; + } + } + + // Keep going + Trans::None + } + + fn update(&mut self, data: &mut StateData<'_, GameData<'_, '_>>) -> SimpleTrans { + Trans::None + } +} \ No newline at end of file diff --git a/src/systems.rs b/src/systems.rs index d3796e9..bec589c 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -53,9 +53,9 @@ impl<'a> System<'a> for BirbGravity { for (mut transform, mut object) in (&mut transforms, &mut scrolling).join() { if input.action_is_down("flap").expect("No action") { - object.vertical_speed = 500.0; + object.vertical_speed = 600.0; } - object.vertical_speed -= 1000.0 * time.delta_seconds(); + object.vertical_speed -= 1500.0 * time.delta_seconds(); transform.prepend_translation_y(object.vertical_speed * time.delta_seconds()); } }