diff --git a/resources/input.ron b/resources/input.ron index 8211c85..0876c3d 100644 --- a/resources/input.ron +++ b/resources/input.ron @@ -15,5 +15,23 @@ "SlowDown": [ [Key(Subtract)] ], + "CameraMoveUp": [ + [Key(Up)] + ], + "CameraMoveDown": [ + [Key(Down)] + ], + "CameraMoveLeft": [ + [Key(Left)] + ], + "CameraMoveRight": [ + [Key(Right)] + ], + "CameraMoveForward": [ + [Key(LShift), Key(Up)] + ], + "CameraMoveBackward": [ + [Key(LShift), Key(Down)] + ], }, ) diff --git a/src/states/main_game.rs b/src/states/main_game.rs index fdc6c9e..3b371bc 100644 --- a/src/states/main_game.rs +++ b/src/states/main_game.rs @@ -37,6 +37,11 @@ impl MainGameState { MainGameState { dispatcher: DispatcherBuilder::new() .with_pool(pool) + .with( + camera_movement::CameraMovementSystem::default(), + "camera_movement", + &[], + ) .with(perception::SpatialGridSystem, "spatial_grid", &[]) .with( perception::EntityDetectionSystem, diff --git a/src/systems/camera_movement.rs b/src/systems/camera_movement.rs new file mode 100644 index 0000000..1a87ac6 --- /dev/null +++ b/src/systems/camera_movement.rs @@ -0,0 +1,46 @@ +use amethyst::{ + core::{Named, Time, Transform}, + ecs::*, + input::InputHandler, + renderer::Camera, +}; + +#[derive(Default)] +pub struct CameraMovementSystem {} + +impl<'s> System<'s> for CameraMovementSystem { + type SystemData = ( + ReadStorage<'s, Camera>, + ReadStorage<'s, Named>, + WriteStorage<'s, Transform>, + Read<'s, InputHandler>, + Read<'s, Time>, + ); + + fn run(&mut self, (cameras, names, mut transforms, input_handler, time): Self::SystemData) { + let delta_time = time.delta_real_seconds(); + let move_factor = 12.0 * delta_time; + for (_, name, transform) in (&cameras, &names, &mut transforms).join() { + if name.name == "Main camera" { + if input_handler.action_is_down("CameraMoveUp").unwrap() { + transform.move_up(move_factor); + } + if input_handler.action_is_down("CameraMoveDown").unwrap() { + transform.move_down(move_factor); + } + if input_handler.action_is_down("CameraMoveLeft").unwrap() { + transform.move_left(move_factor); + } + if input_handler.action_is_down("CameraMoveRight").unwrap() { + transform.move_right(move_factor); + } + if input_handler.action_is_down("CameraMoveForward").unwrap() { + transform.move_forward(move_factor); + } + if input_handler.action_is_down("CameraMoveBackward").unwrap() { + transform.move_backward(move_factor); + } + } + } + } +} diff --git a/src/systems/mod.rs b/src/systems/mod.rs index a3e0557..86b3356 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -1,4 +1,5 @@ pub mod behaviors; +pub mod camera_movement; pub mod collision; pub mod combat; pub mod debug; diff --git a/src/systems/movement.rs b/src/systems/movement.rs index 8e62d58..c4f77ca 100644 --- a/src/systems/movement.rs +++ b/src/systems/movement.rs @@ -16,7 +16,6 @@ impl<'s> System<'s> for MovementSystem { if movement.velocity.magnitude() > movement.max_movement_speed { movement.velocity = movement.velocity.normalize() * movement.max_movement_speed; } - transform.translate_x(movement.velocity.x * delta_time); transform.translate_y(movement.velocity.y * delta_time); }