Playing with the Bevy game engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
entevsbaer/src/main.rs

65 lines
1.7 KiB

11 months ago
use bevy::{
prelude::*,
app::AppExit,
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
};
use heron::prelude::*;
11 months ago
mod input;
11 months ago
mod camera;
mod map;
mod player;
11 months ago
mod off_map;
11 months ago
mod enemy;
11 months ago
#[derive(PhysicsLayer)]
pub enum Layer {
Map,
Player,
11 months ago
Projectile,
11 months ago
}
fn main() {
App::new()
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugins(DefaultPlugins)
.add_plugin(PhysicsPlugin::default())
.insert_resource(Gravity::from(Vec3::new(0.0, -9.81, 0.0)))
.insert_resource(ClearColor(Color::rgb(0.7, 0.7, 1.0)))
11 months ago
.add_startup_system(input::setup)
.add_system(input::handle.label("input"))
11 months ago
.add_startup_system(camera::setup)
.add_system(camera::track_players)
.add_startup_system(map::setup)
.add_system(map::build)
.add_system(map::collide)
11 months ago
.add_system(player::spawn_player)
.add_system(player::input.after("input"))
11 months ago
.add_system(off_map::check)
11 months ago
.add_system(enemy::walk)
11 months ago
.add_system(exit_on_escape)
// .add_system(log_collisions)
11 months ago
.run();
}
fn exit_on_escape(keyboard_input: Res<Input<KeyCode>>, mut exit: EventWriter<AppExit>) {
if keyboard_input.pressed(KeyCode::Escape) {
exit.send(AppExit);
}
}
fn log_collisions(mut events: EventReader<CollisionEvent>) {
for event in events.iter() {
match event {
CollisionEvent::Started(d1, d2) => {
println!("Collision started between {:?} and {:?}", d1, d2)
}
CollisionEvent::Stopped(d1, d2) => {
println!("Collision stopped between {:?} and {:?}", d1, d2)
}
}
}
}