This repository has been archived by the owner on Apr 18, 2022. It is now read-only.
/
main.rs
62 lines (51 loc) · 2 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Demonstrates how to use the fly camera
extern crate amethyst;
use amethyst::{
assets::{PrefabLoader, PrefabLoaderSystem, RonFormat},
controls::FlyControlBundle,
core::transform::TransformBundle,
input::InputBundle,
prelude::*,
renderer::{DrawShaded, PosNormTex},
utils::{application_root_dir, scene::BasicScenePrefab},
Error,
};
type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;
struct ExampleState;
impl SimpleState for ExampleState {
fn on_start(&mut self, data: StateData<GameData>) {
let prefab_handle = data.world.exec(|loader: PrefabLoader<MyPrefabData>| {
loader.load("prefab/fly_camera.ron", RonFormat, (), ())
});
data.world
.create_entity()
.named("Fly Camera Scene")
.with(prefab_handle)
.build();
}
}
fn main() -> Result<(), Error> {
amethyst::start_logger(Default::default());
let app_root = application_root_dir();
let resources_directory = format!("{}/examples/assets", app_root);
let display_config_path = format!(
"{}/examples/fly_camera/resources/display_config.ron",
app_root
);
let key_bindings_path = format!("{}/examples/fly_camera/resources/input.ron", app_root);
let game_data = GameDataBuilder::default()
.with(PrefabLoaderSystem::<MyPrefabData>::default(), "", &[])
.with_bundle(
FlyControlBundle::<String, String>::new(
Some(String::from("move_x")),
Some(String::from("move_y")),
Some(String::from("move_z")),
).with_sensitivity(0.1, 0.1),
)?.with_bundle(TransformBundle::new().with_dep(&["fly_movement"]))?
.with_bundle(
InputBundle::<String, String>::new().with_bindings_from_file(&key_bindings_path)?,
)?.with_basic_renderer(display_config_path, DrawShaded::<PosNormTex>::new(), false)?;
let mut game = Application::build(resources_directory, ExampleState)?.build(game_data)?;
game.run();
Ok(())
}