From 2e5c34da3d4cdc291c788e187bd374492556e680 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 8 Jul 2024 14:18:50 -0500 Subject: [PATCH] Basic player character steering This is basically useless as an actual feature, but it was helpful to demonstrate that I'm beginning to understand how to do this stuff. --- src/birdoids_plugin.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/birdoids_plugin.rs b/src/birdoids_plugin.rs index be3f4268..8ff29a4d 100644 --- a/src/birdoids_plugin.rs +++ b/src/birdoids_plugin.rs @@ -1,5 +1,5 @@ -use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; +use bevy::{math::VectorSpace, prelude::*, sprite::MaterialMesh2dBundle}; const BACKGROUND_COLOR: Color = Color::srgb(0.4, 0.4, 0.4); @@ -20,7 +20,12 @@ impl Plugin for BoidsPlugin{ #[derive(Component)] struct Boid; -#[derive(Component, Deref)] +// It's a Boid, but with an extra component so the player +// can control it from the keyboard +#[derive(Component)] +struct PlayerBoid; + +#[derive(Component, Deref, DerefMut)] struct Velocity(Vec3); #[derive(Bundle)] @@ -80,6 +85,16 @@ fn spawn_boids( }, Boid )); + + commands.spawn(( + BoidBundle::new(Vec3::new(0.0, 0.0, 0.0)), + PlayerBoid, + MaterialMesh2dBundle { + mesh: meshes.add(Triangle2d::default()).into(), + material: materials.add(Color::srgb(1.0, 0.0, 0.0)), + ..default() + } + )); } fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>, time: Res