Skip to content

Commit

Permalink
Camera now movable in GUI!
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmayhew committed Nov 27, 2019
1 parent 92f931f commit a942562
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
25 changes: 25 additions & 0 deletions config/keybindings.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(
axes: {

},
actions: {
"CameraMoveUp": [
[Key(Up)]
],
"CameraMoveDown": [
[Key(Down)]
],
"CameraMoveLeft": [
[Key(Left)]
],
"CameraMoveRight": [
[Key(Right)]
],
"CameraMoveForward": [
[Key(LShift)]
],
"CameraMoveBackward": [
[Key(RShift)]
],
},
)
17 changes: 17 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use amethyst::{
core::transform::{Transform, TransformBundle},
//Component is used to attach structs to entities in the game
ecs::prelude::{Component, DenseVecStorage, Dispatcher},
input::{InputBundle, StringBindings},
prelude::*,
//renderer is used to display a window
renderer::{
Expand Down Expand Up @@ -114,6 +115,7 @@ fn initialise_camera(world: &mut World) {

world
.create_entity()
.named("Main camera")
.with(Camera::standard_3d(ARENA_WIDTH, ARENA_HEIGHT))
.with(transform)
.build();
Expand Down Expand Up @@ -146,6 +148,16 @@ impl SimpleState for GameplayState {

self.dispatcher.setup(&mut world);
}

fn update(&mut self, data: &mut StateData<GameData>) -> SimpleTrans {
println!("update SimpleState");

self.dispatcher.dispatch(&data.world);

//data.data.update(&data.world);

Trans::None
}
}

fn main() -> amethyst::Result<()> {
Expand All @@ -154,6 +166,10 @@ fn main() -> amethyst::Result<()> {
let app_root = application_root_dir()?;
let display_config_path = app_root.join("config").join("display.ron");

let binding_path = app_root.join("config").join("keybindings.ron");
let input_bundle = InputBundle::<StringBindings>::new()
.with_bindings_from_file(binding_path)?;

let game_data = GameDataBuilder::default()
.with_bundle(
RenderingBundle::<DefaultBackend>::new()
Expand All @@ -165,6 +181,7 @@ fn main() -> amethyst::Result<()> {
// RenderFlat2D plugin is used to render entities with a `SpriteRender` component.
.with_plugin(RenderFlat2D::default()),
)?
.with_bundle(input_bundle)?
// Add the transform bundle which handles tracking entity positions
// TODO: The manual says to add this instead of running world.register::<LifeForm>(); inside impl SimpleState for GameplayState
// However this doesnt seem to work as described, maybe try removing it?
Expand Down

0 comments on commit a942562

Please sign in to comment.