|
|
@ -12,9 +12,9 @@ use amethyst::{
|
|
|
|
use log::info;
|
|
|
|
use log::info;
|
|
|
|
use crate::components::*;
|
|
|
|
use crate::components::*;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use crate::systems::BirbGravity;
|
|
|
|
|
|
|
|
|
|
|
|
pub struct MyState;
|
|
|
|
pub struct MyState;
|
|
|
|
|
|
|
|
|
|
|
|
impl SimpleState for MyState {
|
|
|
|
impl SimpleState for MyState {
|
|
|
|
|
|
|
|
|
|
|
|
// On start will run when this state is initialized. For more
|
|
|
|
// 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
|
|
|
|
// Load our sprites and display them
|
|
|
|
let sprites = load_sprites(world);
|
|
|
|
let sprites = load_sprites(world);
|
|
|
|
init_sprites(world, &sprites, &dimensions);
|
|
|
|
init_sprites(world, &sprites, &dimensions);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_event(
|
|
|
|
fn handle_event(
|
|
|
@ -50,14 +51,9 @@ impl SimpleState for MyState {
|
|
|
|
return Trans::Quit;
|
|
|
|
return Trans::Quit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Listen to any key events
|
|
|
|
if is_key_down(&event, VirtualKeyCode::P) {
|
|
|
|
if let Some(event) = get_key(&event) {
|
|
|
|
return Trans::Push(Box::new(PausedState));
|
|
|
|
// info!("handling key event: {:?}", event);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// Keep going
|
|
|
@ -196,3 +192,36 @@ fn init_sprites(world: &mut World, sprites: &HashMap<String, SpriteRender>, dime
|
|
|
|
.build();
|
|
|
|
.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::<ScreenDimensions>()).clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let storage = world.read_storage::<BirbGravity>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|