lol
This commit is contained in:
6436
Cargo.lock
generated
6436
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -8,4 +8,3 @@ bevy = { version="0.15.3", features = ["jpeg"]}
|
||||
bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] }
|
||||
bevy_egui = "0.33.0"
|
||||
bevy_rapier3d = "0.29.0"
|
||||
bevy_xpbd_3d = "0.5.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::{gltf::GltfMesh, math::Vec3A, prelude::*, render::mesh::MeshAabb};
|
||||
use bevy_rapier3d::prelude::{Collider, RigidBody};
|
||||
|
||||
use crate::{GameState, asset_loading::GltfAssets};
|
||||
|
||||
@@ -18,11 +19,22 @@ fn spawn(mut commands: Commands, models: Res<Assets<Gltf>>, gltf_assets: Res<Glt
|
||||
let hammer = models.get(hammer).unwrap();
|
||||
let asset = hammer.default_scene.as_ref().unwrap();
|
||||
// hammer
|
||||
commands.spawn((
|
||||
Transform::from_xyz(0.0, 1.0, 0.0).with_scale(Vec3::splat(0.1)),
|
||||
Interact,
|
||||
SceneRoot(asset.clone()),
|
||||
));
|
||||
commands
|
||||
.spawn((
|
||||
Transform::from_xyz(0.0, 100.0, 0.0).with_scale(Vec3::splat(0.1)),
|
||||
Interact,
|
||||
RigidBody::Dynamic,
|
||||
SceneRoot(asset.clone()),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn(Collider::cuboid(0.8, 10f32, 0.8))
|
||||
.insert(Transform::from_xyz(0.0, -5.0, 0.0));
|
||||
parent
|
||||
.spawn(Collider::cuboid(1.0, 1.0, 4.5))
|
||||
// Position the collider relative to the rigid-body.
|
||||
.insert(Transform::from_xyz(0.0, 4.2, 1.0));
|
||||
});
|
||||
|
||||
//tools
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ fn main() {
|
||||
bevy_plugin::plugin,
|
||||
asset_loading::plugin,
|
||||
main_menu::plugin,
|
||||
physics::plugin,
|
||||
level_instantiation::map_plugin,
|
||||
player::plugin,
|
||||
interaction::plugin,
|
||||
@@ -54,10 +53,7 @@ fn setup(
|
||||
MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
));
|
||||
commands.spawn((
|
||||
RigidBody::Fixed,
|
||||
Collider::cylinder(0.1, 4.0)
|
||||
));
|
||||
commands.spawn((RigidBody::Fixed, Collider::cylinder(0.1, 4.0)));
|
||||
// cube
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
|
||||
@@ -6,6 +6,21 @@ use bevy_rapier3d::prelude::*;
|
||||
|
||||
use crate::GameState;
|
||||
|
||||
mod toolbar;
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(toolbar::plugin)
|
||||
.add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor))
|
||||
.add_systems(
|
||||
Update,
|
||||
(move_camera, handle_input).run_if(in_state(GameState::Playing)),
|
||||
)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
apply_player_movement.run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
pub struct Player;
|
||||
|
||||
@@ -25,18 +40,6 @@ pub struct PlayerInput {
|
||||
movement_direction: Vec3,
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor))
|
||||
.add_systems(
|
||||
Update,
|
||||
(move_camera, handle_input).run_if(in_state(GameState::Playing)),
|
||||
)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
apply_player_movement.run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
}
|
||||
|
||||
/// used by the view model camera and the player's arm.
|
||||
const STATIC_LAYER: usize = 1;
|
||||
|
||||
@@ -54,7 +57,7 @@ pub fn init_player(
|
||||
PlayerAction::default(),
|
||||
CameraSensitivity::default(),
|
||||
PlayerInput::default(),
|
||||
|
||||
toolbar::Item::none(),
|
||||
// rapier
|
||||
RigidBody::Dynamic,
|
||||
Collider::capsule(Vec3::new(0.0, -0.5, 0.0), Vec3::new(0.0, 0.5, 0.0), 0.5),
|
||||
@@ -64,10 +67,9 @@ pub fn init_player(
|
||||
linear_damping: 6.0,
|
||||
angular_damping: 1.0,
|
||||
},
|
||||
|
||||
GravityScale(3.0),
|
||||
Transform::from_xyz(0.0, 1.0, 0.0),
|
||||
GlobalTransform::default(),
|
||||
Visibility::default(),
|
||||
InheritedVisibility::default(),
|
||||
ViewVisibility::default(),
|
||||
))
|
||||
@@ -161,7 +163,7 @@ pub fn handle_input(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut query: Query<(&Transform, &mut PlayerInput, &mut PlayerAction), With<Player>>,
|
||||
) {
|
||||
for (transform, mut input) in query.iter_mut() {
|
||||
for (transform, mut input, mut action) in query.iter_mut() {
|
||||
let forward = transform.forward();
|
||||
let right = transform.right();
|
||||
let mut movement_direction = Vec3::ZERO;
|
||||
@@ -187,15 +189,12 @@ pub fn handle_input(
|
||||
if keyboard_input.pressed(KeyCode::KeyE) {
|
||||
*action = PlayerAction::Interact
|
||||
}
|
||||
velocity.0 = input.normalize_or_zero() * SPEED;
|
||||
|
||||
input.movement_direction = movement_direction.normalize_or_zero();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_player_movement(
|
||||
mut player_query: Query<(&PlayerInput, &mut Velocity), With<Player>>,
|
||||
) {
|
||||
pub fn apply_player_movement(mut player_query: Query<(&PlayerInput, &mut Velocity), With<Player>>) {
|
||||
const SPEED: f32 = 3.0;
|
||||
const JUMP_FORCE: f32 = 4.0;
|
||||
|
||||
|
||||
21
src/player/toolbar.rs
Normal file
21
src/player/toolbar.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use bevy::prelude::*;
|
||||
use std::default::Default;
|
||||
|
||||
use crate::GameState;
|
||||
|
||||
use super::Player;
|
||||
|
||||
#[derive(Component, Default, Debug)]
|
||||
pub struct Item(Option<Entity>);
|
||||
|
||||
impl Item {
|
||||
pub fn none() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_systems(Update, show_toolbar.run_if(in_state(GameState::Playing)));
|
||||
}
|
||||
|
||||
fn show_toolbar(player_tool_query: Query<&Item, With<Player>>) {}
|
||||
Reference in New Issue
Block a user