Skip to content

Commit

Permalink
Bump bevy from 0.14.2 to 0.15.0 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Dec 11, 2024
1 parent 80b64fc commit b6b5682
Show file tree
Hide file tree
Showing 11 changed files with 953 additions and 574 deletions.
1,344 changes: 859 additions & 485 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ version = "0.9.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = {version = "0.14.2", features = ["bevy_dev_tools"]}
vleue_navigator = "0.10.2"
bevy = {version = "0.15.0", features = ["bevy_dev_tools"]}
vleue_navigator = "0.11.0"
3 changes: 1 addition & 2 deletions src/bounding_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub fn bounding_box_draw(query: Query<&BoundingBox>, mut gizmos: Gizmos) {
// TODO: stop using gizmos
gizmos.primitive_2d(
&rectangle,
bounding_box.value.center(),
0.,
Isometry2d::from_translation(bounding_box.value.center()),
Color::srgb(0., 1., 0.),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const PAN_SPEED: f32 = 5.;
pub struct MainCamera;

pub fn camera_setup(mut commands: Commands) {
let camera2d = Camera2dBundle::default();
let camera2d = Camera2d::default();
commands.spawn((camera2d, MainCamera));
}

Expand Down
16 changes: 8 additions & 8 deletions src/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn enemy_setup(
mut atlases: ResMut<Assets<TextureAtlasLayout>>,
) {
let mut atlas_config = HashMap::new();
let texture = asset_server.load("enemy/export.png");
let image = asset_server.load("enemy/export.png");
let tile_size = UVec2::new(16, 32);
let directions = vec![
Directions::East,
Expand Down Expand Up @@ -135,12 +135,12 @@ pub fn enemy_setup(
},
EnemyState::default(),
Direction::default(),
SpriteBundle {
texture,
transform: Transform::from_xyz(0., 100., 0.),
Sprite {
image,
texture_atlas: Some(TextureAtlas::from(default_layout)),
..default()
},
TextureAtlas::from(default_layout),
Transform::from_xyz(0., 100., 0.),
YSort { height: 32 },
BoundingBox {
value: Aabb2d::new(Vec2::new(0., 100.), Vec2::new(8., 16.)),
Expand All @@ -156,13 +156,13 @@ pub fn enemy_setup(

pub fn enemy_atlas_layout(
mut query: Query<
(&EnemyState, &Direction, &mut TextureAtlas),
(&EnemyState, &Direction, &mut Sprite),
(With<Enemy>, Or<(Changed<Direction>, Changed<EnemyState>)>),
>,
animation: Res<Animation<EnemyStates>>,
) {
for (enemy_state, direction, mut atlas) in &mut query {
atlas.layout = animation
for (enemy_state, direction, mut sprite) in &mut query {
sprite.texture_atlas.as_mut().unwrap().layout = animation
.atlas_config
.get(&enemy_state.value)
.unwrap()
Expand Down
14 changes: 11 additions & 3 deletions src/line_of_sight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn line_of_sight_update(
);

let point = point_transform.translation.xy();
let ray = Ray2d::new(position, (point - position).normalize());
let ray = Ray2d::new(position, Dir2::new(point - position).unwrap());
let ray_cast = RayCast2d::from_ray(ray, LINE_OF_SIGHT_DISTANCE as f32);

points[i as usize + 1] = point;
Expand Down Expand Up @@ -125,13 +125,21 @@ pub fn line_of_sight_looking_at_draw(query: Query<(&LineOfSight, &Transform)>, m
let looking_at = position + line_of_sight.looking_at * LINE_OF_SIGHT_DISTANCE as f32;

// TODO: stop using gizmos
gizmos.primitive_2d(&rect, looking_at, 0., Color::WHITE);
gizmos.primitive_2d(
&rect,
Isometry2d::from_translation(looking_at),
Color::WHITE,
);
}
}

pub fn line_of_sight_draw(query: Query<&LineOfSight>, mut gizmos: Gizmos) {
for line_of_sight in &query {
// TODO: stop using gizmos
gizmos.primitive_2d(&line_of_sight.polygon, Vec2::ZERO, 0., Color::WHITE);
gizmos.primitive_2d(
&line_of_sight.polygon,
Isometry2d::from_translation(Vec2::ZERO),
Color::WHITE,
);
}
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ fn main() -> AppExit {
.set(ImagePlugin::default_nearest()),
FpsOverlayPlugin {
config: FpsOverlayConfig {
text_config: TextStyle {
text_config: TextFont {
font_size: 20.,
..default()
},
..default()
},
},
VleueNavigatorPlugin,
Expand Down
3 changes: 1 addition & 2 deletions src/movable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ pub fn path_draw(query: Query<(&Transform, &Movable)>, mut gizmos: Gizmos) {
// TODO: stop using gizmos
gizmos.primitive_2d(
&line,
center,
0.,
Isometry2d::from_translation(center),
Color::linear_rgba(
1.,
1.,
Expand Down
41 changes: 20 additions & 21 deletions src/navmesh.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle, window::WindowResized};
use bevy::{prelude::*, window::WindowResized};
use vleue_navigator::prelude::*;

pub fn navmesh_setup(mut commands: Commands) {
commands.spawn(NavMeshBundle {
settings: NavMeshSettings {
commands.spawn((
NavMeshSettings {
fixed: Triangulation::from_outer_edges(&[
Vec2::new(-400.0, -300.0),
Vec2::new(400., -300.0),
Expand All @@ -13,10 +13,9 @@ pub fn navmesh_setup(mut commands: Commands) {
simplify: 0.05,
..default()
},
update_mode: NavMeshUpdateMode::Direct,
transform: Transform::default(),
..NavMeshBundle::with_default_id()
});
NavMeshUpdateMode::Direct,
Transform::default(),
));
}

pub fn navmesh_draw(
Expand All @@ -26,7 +25,7 @@ pub fn navmesh_draw(
mut materials: ResMut<Assets<ColorMaterial>>,
mut current_mesh_entity: Local<Option<Entity>>,
window_resized: EventReader<WindowResized>,
navmesh: Query<(&Handle<NavMesh>, Ref<NavMeshStatus>)>,
navmesh: Query<(&ManagedNavMesh, Ref<NavMeshStatus>)>,
) {
let (navmesh_handle, status) = navmesh.single();

Expand All @@ -44,18 +43,16 @@ pub fn navmesh_draw(

*current_mesh_entity = Some(
commands
.spawn(MaterialMesh2dBundle {
mesh: meshes.add(navmesh.to_mesh()).into(),
material: materials.add(ColorMaterial::from(Color::srgba(0., 0., 1., 0.25))),
..default()
})
.spawn((
Mesh2d(meshes.add(navmesh.to_mesh())),
MeshMaterial2d(materials.add(ColorMaterial::from(Color::srgba(0., 0., 1., 0.25)))),
))
.with_children(|main_mesh| {
main_mesh.spawn(MaterialMesh2dBundle {
mesh: meshes.add(navmesh.to_wireframe_mesh()).into(),
transform: Transform::from_xyz(0.0, 0.0, 0.1),
material: materials.add(ColorMaterial::from(Color::srgb(1., 0., 0.))),
..default()
});
main_mesh.spawn((
Mesh2d(meshes.add(navmesh.to_wireframe_mesh()).into()),
MeshMaterial2d(materials.add(ColorMaterial::from(Color::srgb(1., 0., 0.)))),
Transform::from_xyz(0.0, 0.0, 0.1),
));
})
.id(),
);
Expand All @@ -68,8 +65,10 @@ pub fn navmesh_obstacle_draw(mut gizmos: Gizmos, query: Query<(&PrimitiveObstacl
// TODO: stop using gizmos
gizmos.primitive_2d(
primitive,
transform.translation.xy(),
transform.rotation.to_axis_angle().1,
Isometry2d::new(
transform.translation.xy(),
Rot2::radians(transform.rotation.to_axis_angle().1),
),
Color::srgb(1., 0., 0.),
);
}
Expand Down
30 changes: 16 additions & 14 deletions src/player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{math::bounding::Aabb2d, prelude::*, window::PrimaryWindow};
use std::collections::HashMap;
use vleue_navigator::NavMesh;
use vleue_navigator::{prelude::ManagedNavMesh, NavMesh};

use crate::{
animation::{Animation, AnimationAtlasConfig},
Expand Down Expand Up @@ -34,7 +34,7 @@ pub fn player_setup(
mut atlases: ResMut<Assets<TextureAtlasLayout>>,
) {
let mut atlas_config = HashMap::new();
let texture = asset_server.load("player/export.png");
let image = asset_server.load("player/export.png");
let tile_size = UVec2::new(16, 32);
let directions = vec![
Directions::East,
Expand Down Expand Up @@ -118,12 +118,12 @@ pub fn player_setup(
Movable::default(),
PlayerState::default(),
Direction::default(),
SpriteBundle {
texture,
transform: Transform::from_translation(Vec3::new(-100., 100., 0.)),
Sprite {
image,
texture_atlas: Some(TextureAtlas::from(default_layout)),
..default()
},
TextureAtlas::from(default_layout),
Transform::from_translation(Vec3::new(-100., 100., 0.)),
YSort { height: 32 },
BoundingBox {
value: Aabb2d::new(Vec2::new(-100., 100.), Vec2::new(8., 16.)),
Expand All @@ -132,30 +132,32 @@ pub fn player_setup(
}

pub fn player_animation(
mut query: Query<(&PlayerState, &mut TextureAtlas), With<Player>>,
mut query: Query<(&PlayerState, &mut Sprite), With<Player>>,
mut animation: ResMut<Animation<PlayerStates>>,
time: Res<Time>,
) {
for (player_state, mut atlas) in &mut query {
for (player_state, mut sprite) in &mut query {
animation.frame_timer.tick(time.delta());

if animation.frame_timer.just_finished() {
let atlas_config = animation.atlas_config.get(&player_state.value).unwrap();
atlas.index = (atlas.index + 1) % (atlas_config.frame_count as usize - 1);
sprite.texture_atlas.as_mut().unwrap().index = (sprite.texture_atlas.as_mut().unwrap().index
+ 1)
% (atlas_config.frame_count as usize - 1);
animation.frame_timer = timer_from_fps(atlas_config.fps);
}
}
}

pub fn player_atlas_layout(
mut query: Query<
(&PlayerState, &Direction, &mut TextureAtlas),
(&PlayerState, &Direction, &mut Sprite),
(With<Player>, Or<(Changed<Direction>, Changed<PlayerState>)>),
>,
animation: Res<Animation<PlayerStates>>,
) {
for (player_state, direction, mut atlas) in &mut query {
atlas.layout = animation
for (player_state, direction, mut sprite) in &mut query {
sprite.texture_atlas.as_mut().unwrap().layout = animation
.atlas_config
.get(&player_state.value)
.unwrap()
Expand All @@ -169,7 +171,7 @@ pub fn player_atlas_layout(
pub fn player_path(
mut query: Query<(&mut Movable, &Transform), With<Player>>,
navmeshes: Res<Assets<NavMesh>>,
navmesh: Query<&Handle<NavMesh>>,
navmesh: Query<&ManagedNavMesh>,
buttons: Res<ButtonInput<MouseButton>>,
windows: Query<&Window, With<PrimaryWindow>>,
camera_q: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
Expand All @@ -181,7 +183,7 @@ pub fn player_path(
if let Some(cursor_position) = window.cursor_position() {
let (camera, global_transform) = camera_q.single();

if let Some(position) = camera.viewport_to_world_2d(global_transform, cursor_position) {
if let Ok(position) = camera.viewport_to_world_2d(global_transform, cursor_position) {
for (mut movable, transform) in &mut query {
let Some(navmesh) = navmeshes.get(navmesh.single()) else {
continue;
Expand Down
67 changes: 32 additions & 35 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
use bevy::{math::bounding::Aabb2d, prelude::*};
use vleue_navigator::prelude::*;

use crate::{bounding_box::BoundingBox, obstacle::Obstacle, ysort::YSort};

#[derive(Component)]
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.;

// sprite
commands.spawn((
Tree,
SpriteBundle {
texture,
transform: Transform::from_xyz(x, y, z),
..default()
},
YSort { height: 116 },
));

// obstacle
commands.spawn((
Obstacle,
PrimitiveObstacle::Rectangle(Rectangle::new(10., 10.)),
SpatialBundle::from_transform(Transform::from_xyz(x, y - 58., z)),
BoundingBox {
value: Aabb2d::new(Vec2::new(x, y - 58.), Vec2::splat(5.)),
},
));
}
use bevy::{math::bounding::Aabb2d, prelude::*};
use vleue_navigator::prelude::*;

use crate::{bounding_box::BoundingBox, obstacle::Obstacle, ysort::YSort};

#[derive(Component)]
pub struct Tree;

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

// sprite
commands.spawn((
Tree,
Sprite { image, ..default() },
Transform::from_xyz(x, y, z),
YSort { height: 116 },
));

// obstacle
commands.spawn((
Obstacle,
PrimitiveObstacle::Rectangle(Rectangle::new(10., 10.)),
Transform::from_xyz(x, y - 58., z),
BoundingBox {
value: Aabb2d::new(Vec2::new(x, y - 58.), Vec2::splat(5.)),
},
));
}

0 comments on commit b6b5682

Please sign in to comment.