Compare commits
No commits in common. "0009a83b1d9179313be6ea8203f218f13fdca42c" and "0803b9d61194598fdbb54a023596bf3d12557745" have entirely different histories.
0009a83b1d
...
0803b9d611
|
@ -19,7 +19,7 @@ pub fn build_boid_mesh(mut meshes: ResMut<Assets<Mesh>>, mut boid_mesh: ResMut<B
|
||||||
pub fn make_boid_mesh() -> Mesh {
|
pub fn make_boid_mesh() -> Mesh {
|
||||||
const TRIANGLE_HEIGHT: f32 = 10.;
|
const TRIANGLE_HEIGHT: f32 = 10.;
|
||||||
const TRIANGLE_WIDTH: f32 = 5.;
|
const TRIANGLE_WIDTH: f32 = 5.;
|
||||||
const STROKE_WIDTH: f32 = 0.5;
|
const STROKE_WIDTH: f32 = 0.25;
|
||||||
|
|
||||||
const HALF_HEIGHT: f32 = TRIANGLE_HEIGHT / 2.0;
|
const HALF_HEIGHT: f32 = TRIANGLE_HEIGHT / 2.0;
|
||||||
const HALF_WIDTH: f32 = TRIANGLE_WIDTH / 2.0;
|
const HALF_WIDTH: f32 = TRIANGLE_WIDTH / 2.0;
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
use super::Boid;
|
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
pub(crate) fn boid_border_teleport(
|
|
||||||
mut boids: Query<&mut Transform, With<Boid>>,
|
|
||||||
windows: Query<&Window>,
|
|
||||||
) {
|
|
||||||
let window = windows.get_single().unwrap();
|
|
||||||
let width = window.resolution.width();
|
|
||||||
let height = window.resolution.height();
|
|
||||||
|
|
||||||
let half_width = width / 2.;
|
|
||||||
let half_height = height / 2.;
|
|
||||||
|
|
||||||
let left_bound = -half_width;
|
|
||||||
let right_bound = half_width;
|
|
||||||
let top_bound = half_height;
|
|
||||||
let bottom_bound = -half_height;
|
|
||||||
|
|
||||||
for mut boid_transform in &mut boids {
|
|
||||||
let translation = &mut boid_transform.translation;
|
|
||||||
|
|
||||||
if translation.y > top_bound {
|
|
||||||
translation.y = bottom_bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
if translation.y < bottom_bound {
|
|
||||||
translation.y = top_bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
if translation.x < left_bound {
|
|
||||||
translation.x = right_bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
if translation.x > right_bound {
|
|
||||||
translation.x = left_bound;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
mod boid_mesh;
|
mod boid_mesh;
|
||||||
mod boundary;
|
|
||||||
|
|
||||||
use bevy::{color::palettes::tailwind, prelude::*, sprite::MaterialMesh2dBundle};
|
use bevy::{color::palettes::tailwind, prelude::*, sprite::MaterialMesh2dBundle};
|
||||||
use boid_mesh::BoidMesh;
|
use boid_mesh::BoidMesh;
|
||||||
|
@ -9,7 +8,7 @@ fn main() {
|
||||||
.init_resource::<BoidMesh>()
|
.init_resource::<BoidMesh>()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_systems(Startup, (boid_mesh::build_boid_mesh, setup).chain())
|
.add_systems(Startup, (boid_mesh::build_boid_mesh, setup).chain())
|
||||||
.add_systems(Update, (move_boids, boundary::boid_border_teleport).chain())
|
.add_systems(Update, move_boids)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ fn main() {
|
||||||
struct Boid;
|
struct Boid;
|
||||||
|
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Default)]
|
||||||
struct Velocity(Vec2);
|
struct Velocity(Vec3);
|
||||||
|
|
||||||
#[derive(Bundle, Default)]
|
#[derive(Bundle, Default)]
|
||||||
struct BoidBundle {
|
struct BoidBundle {
|
||||||
|
@ -28,7 +27,7 @@ struct BoidBundle {
|
||||||
|
|
||||||
fn move_boids(mut boids: Query<(&mut Transform, &Velocity), With<Boid>>, time: Res<Time>) {
|
fn move_boids(mut boids: Query<(&mut Transform, &Velocity), With<Boid>>, time: Res<Time>) {
|
||||||
for (mut transform, velocity) in &mut boids {
|
for (mut transform, velocity) in &mut boids {
|
||||||
transform.translation += velocity.0.extend(0.) * time.delta_seconds();
|
transform.translation += velocity.0 * time.delta_seconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ fn setup(
|
||||||
transform: Transform::from_scale(Vec3::splat(2.5)),
|
transform: Transform::from_scale(Vec3::splat(2.5)),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
velocity: Velocity(Vec2::Y * 100.),
|
velocity: Velocity(Vec3::Y * 25.),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue