Skip to content

Commit

Permalink
Move obstacle from navmesh to tree
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstarman committed Oct 20, 2024
1 parent 14a4553 commit 3757fec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
20 changes: 7 additions & 13 deletions src/navmesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@ pub fn navmesh_setup(mut commands: Commands) {
..default()
},
update_mode: NavMeshUpdateMode::Direct,
transform: Transform::from_xyz(0., 0., -999.),
transform: Transform::default(),
..NavMeshBundle::with_default_id()
});

// TODO: obstacles should be defined on tree
let transform = Transform::from_translation(Vec3::new(-75., 60., 0.0));
commands.spawn((
PrimitiveObstacle::Rectangle(Rectangle::new(20., 20.)),
SpatialBundle::from_transform(transform),
));
}

pub fn navmesh_draw(
Expand All @@ -36,6 +29,7 @@ pub fn navmesh_draw(
navmesh: Query<(&Handle<NavMesh>, Ref<NavMeshStatus>)>,
) {
let (navmesh_handle, status) = navmesh.single();

if (!status.is_changed() || *status != NavMeshStatus::Built) && window_resized.is_empty() {
return;
}
Expand All @@ -58,7 +52,7 @@ pub fn navmesh_draw(
.with_children(|main_mesh| {
main_mesh.spawn(MaterialMesh2dBundle {
mesh: meshes.add(navmesh.to_wireframe_mesh()).into(),
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.1)),
transform: Transform::from_xyz(0.0, 0.0, 0.1),
material: materials.add(ColorMaterial::from(Color::srgb(1., 0., 0.))),
..default()
});
Expand All @@ -68,11 +62,11 @@ pub fn navmesh_draw(
}

pub fn navmesh_obstacle_draw(mut gizmos: Gizmos, query: Query<(&PrimitiveObstacle, &Transform)>) {
for (prim, transform) in &query {
match prim {
PrimitiveObstacle::Rectangle(prim) => {
for (obstacle, transform) in &query {
match obstacle {
PrimitiveObstacle::Rectangle(primitive) => {
gizmos.primitive_2d(
prim,
primitive,
transform.translation.xy(),
transform.rotation.to_axis_angle().1,
Color::srgb(1., 0., 0.),
Expand Down
18 changes: 10 additions & 8 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::prelude::*;
use vleue_navigator::prelude::*;

use crate::ysort::YSort;

Expand All @@ -7,21 +8,22 @@ pub struct Tree;

pub fn tree_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let texture = asset_server.load("tree.png");
let x = 100.;
let y = 100.;
let z = 0.;

commands.spawn((
Tree,
SpriteBundle {
texture,
transform: Transform {
translation: Vec3 {
x: 100.,
y: 100.,
z: 0.,
},
..default()
},
transform: Transform::from_xyz(x, y, z),
..default()
},
YSort { height: 116 },
));

commands.spawn((
PrimitiveObstacle::Rectangle(Rectangle::new(10., 10.)),
SpatialBundle::from_transform(Transform::from_xyz(x, y - 58., z)),
));
}

0 comments on commit 3757fec

Please sign in to comment.