diff --git a/src/main.rs b/src/main.rs index 8147798..f7a972d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,6 @@ use bevy::{input::system::exit_on_esc_system, prelude::*}; -use bevy_rapier3d::{ - physics::RapierPhysicsPlugin, - rapier::{dynamics::RigidBodyBuilder, geometry::ColliderBuilder}, -}; -use rake::{ - player::{Player, PlayerPlugin}, - world::WorldPlugin, -}; +use bevy_rapier3d::physics::RapierPhysicsPlugin; +use rake::{player::PlayerPlugin, world::WorldPlugin}; fn main() { App::build() @@ -23,23 +17,6 @@ fn main() { //.add_plugin(RapierRenderPlugin) .add_plugin(PlayerPlugin) .add_plugin(WorldPlugin) - .add_startup_system(init.system()) .add_system(exit_on_esc_system.system()) .run(); } - -fn init(commands: &mut Commands) { - let player = Player::create(); - commands - .spawn(LightBundle { - transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), - ..Default::default() - }) - .spawn(Camera3dBundle { - transform: Transform::from_translation(Vec3::new(0.0, 3.0, 3.0)), - ..Default::default() - }) - .with(player) - .with(RigidBodyBuilder::new_dynamic().translation(0.0, 3.0, 0.0)) - .with(ColliderBuilder::cylinder(1.0, 0.5).friction(0.0)); -} diff --git a/src/player.rs b/src/player.rs index 68cedd9..9328384 100644 --- a/src/player.rs +++ b/src/player.rs @@ -2,16 +2,19 @@ use bevy::{input::mouse::MouseMotion, math::clamp, prelude::*}; use bevy_rapier3d::{ na::Matrix3x1, physics::RigidBodyHandleComponent, - rapier::dynamics::{RigidBody, RigidBodySet}, + rapier::{ + dynamics::{RigidBody, RigidBodyBuilder, RigidBodySet}, + geometry::ColliderBuilder, + }, }; -pub struct Player { +struct Player { /// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) - pub pitch: f32, + pitch: f32, /// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) - pub yaw: f32, + yaw: f32, /// The current velocity of the FlyCamera. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) - pub velocity: Vec3, + velocity: Vec3, } const PLAYER_SPEED: f32 = 15.0; @@ -19,7 +22,7 @@ const PLAYER_FRICTION: f32 = 1.0; const MOUSE_SENSITIVITY: f32 = 6.0; impl Player { - pub fn create() -> Self { + fn create() -> Self { Self { pitch: 0.0, yaw: 0.0, @@ -143,6 +146,22 @@ impl Plugin for PlayerPlugin { app .init_resource::() .add_system(camera_movement_system.system()) - .add_system(mouse_motion_system.system()); + .add_system(mouse_motion_system.system()) + .add_startup_system(init_player.system()); } } + +fn init_player(commands: &mut Commands) { + commands + .spawn(Camera3dBundle { + transform: Transform::from_translation(Vec3::new(0.0, 3.0, 3.0)), + ..Default::default() + }) + .with(Player::create()) + .with( + RigidBodyBuilder::new_dynamic() + .translation(0.0, 3.0, 0.0) + .lock_rotations(), + ) + .with(ColliderBuilder::cylinder(1.0, 0.5).friction(0.0)); +} diff --git a/src/world.rs b/src/world.rs index 5f0b85d..22a521f 100644 --- a/src/world.rs +++ b/src/world.rs @@ -13,11 +13,11 @@ fn create_world( commands: &mut Commands, mut meshes: ResMut>, mut materials: ResMut>, - asset_server: Res + asset_server: Res, ) { + // some boxes to help with orientation let box_mesh = meshes.add(Mesh::from(shape::Cube { size: 0.25 })); let box_material = materials.add(Color::rgb(1.0, 0.2, 0.3).into()); - const AMOUNT: i32 = 6; for x in -(AMOUNT / 2)..(AMOUNT / 2) { for y in -(AMOUNT / 2)..(AMOUNT / 2) { @@ -32,6 +32,12 @@ fn create_world( } } + // a simple light + commands.spawn(LightBundle { + transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), + ..Default::default() + }); + // create a floor let floor_texture_handle = materials.add(asset_server.load("textures/blocks17floor2.png").into()); let rigid_body1 = RigidBodyBuilder::new_static();