This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add camera movement when using the arrow keys. (#75)
* Add camera movement
- Loading branch information
Showing
5 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String>>, | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod behaviors; | ||
pub mod camera_movement; | ||
pub mod collision; | ||
pub mod combat; | ||
pub mod debug; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters