Skip to content

Commit

Permalink
Updated lib and examples to bevy 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackPhlox committed Dec 21, 2024
1 parent cde354f commit 1c40fa6
Show file tree
Hide file tree
Showing 18 changed files with 1,746 additions and 1,103 deletions.
2,146 changes: 1,450 additions & 696 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_dolly"
version = "0.0.4"
version = "0.0.5"
authors = ["Black Phlox <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -25,21 +25,22 @@ helpers = ["dep:leafwing-input-manager", "bevy/bevy_pbr"]

[dependencies]
dolly = { path = "dolly", default-features = false }
leafwing-input-manager = { version = "0.14", optional = true }
leafwing-input-manager = { version = "0.16", optional = true }

[dependencies.bevy]
version = "0.14"
features = ["bevy_render", "bevy_asset"]
version = "0.15"
features = ["bevy_render", "bevy_asset", "bevy_window"]
default-features = false

[dev-dependencies]
leafwing-input-manager = "0.14"
bevy-inspector-egui = "0.25"
leafwing-input-manager = "0.16"
bevy-inspector-egui = "0.28"

[dev-dependencies.bevy]
version = "0.14"
version = "0.15"
features = [
"bevy_core_pipeline",
"animation",
"bevy_asset",
"bevy_scene",
"bevy_pbr",
Expand All @@ -56,6 +57,6 @@ features = [
default-features = false

[target.'cfg(target_os = "linux")'.dev-dependencies.bevy]
version = "0.14"
version = "0.15"
features = ["x11", "wayland"]
default-features = false
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ In your `Cargo.toml`:
[dependencies]
# Your bevy dependency here ...
# bevy = "0.14"
bevy_dolly = { version = "0.0.4" }
bevy_dolly = { version = "0.0.5" }
```

In your Bevy App:
Expand Down Expand Up @@ -119,7 +119,7 @@ fn update_input(

```toml
[dependencies]
bevy_dolly = { version = "0.0.4", default-features = false }
bevy_dolly = { version = "0.0.5", default-features = false }
```

To include the drivers back, add `features = ["drivers"],` to the dependency.
Expand All @@ -140,6 +140,7 @@ cargo run --release --example orbit

|bevy|bevy_dolly|
|---|---|
|0.15|0.0.5|
|0.14|0.0.4|
|0.13|0.0.3|
|0.12|0.0.2|
Expand Down Expand Up @@ -176,5 +177,5 @@ Yes this project is still a WIP, so PRs are very welcome.
>
> ```bash
> cd dolly
> git checkout bevy_0.14
> git checkout bevy_0.15
> ```
2 changes: 1 addition & 1 deletion dolly
Submodule dolly updated 1 files
+2 −2 Cargo.toml
30 changes: 10 additions & 20 deletions examples/2d_cam_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const SPEED: f32 = 4.5;

fn main() {
App::new()
.insert_resource(Msaa::default())
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
//If large amount of smoothing is used, where camera movement is expected beyond the time of input
Expand All @@ -22,34 +21,25 @@ fn main() {

/// set up a simple 3D scene
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(SpriteBundle {
texture: asset_server.load("bevy_dolly.png"),
transform: Transform::from_xyz(100., 0., 0.),
sprite: Sprite {
custom_size: Some(Vec2::new(128., 128.)),
..Default::default()
},
..Default::default()
});
let offset_transform = Transform::from_xyz(100., 0., 0.);

let mut dolly = Sprite::from_image(asset_server.load("bevy_dolly.png"));
dolly.custom_size = Some(Vec2::new(128., 128.));
commands.spawn((dolly, offset_transform.with_translation(Vec3 { x: 0., y: 0., z: 1. })));

commands.spawn((
Camera2dBundle::default(),
Camera2d::default(),
MainCamera,
Rig::builder()
.with(Position::default())
.with(Smooth::new_position(0.25))
.build(),
));

commands.spawn(SpriteBundle {
texture: asset_server.load("room.png"),
transform: Transform::from_xyz(100., 0., 0.),
sprite: Sprite {
custom_size: Some(Vec2::new(2.6 * 800., 800.)),
..Default::default()
},
..Default::default()
});
let mut room = Sprite::from_image(asset_server.load("room.png"));
room.custom_size = Some(Vec2::new(2.6 * 800., 800.));

commands.spawn((room, offset_transform));

info!("Use W, A, S, D for movement");
info!("Use Z & X zooming in and out");
Expand Down
60 changes: 20 additions & 40 deletions examples/2d_edge_snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,34 @@ enum Direction {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.spawn(SpriteBundle {
texture: asset_server.load("bevy_dolly.png"),
transform: Transform::from_xyz(100., 0., 0.1),
sprite: Sprite {
custom_size: Some(Vec2::new(128., 128.)),
..Default::default()
},
..Default::default()
})
.insert(Direction::Right);
let offset_transform = Transform::from_xyz(100., 0., 0.);

commands.spawn(SpriteBundle {
texture: asset_server.load("room.png"),
transform: Transform::from_xyz(100., 200., 0.),
sprite: Sprite {
custom_size: Some(Vec2::new(2.6 * 800., 800.)),
..Default::default()
},
..Default::default()
});
let mut dolly = Sprite::from_image(asset_server.load("bevy_dolly.png"));
dolly.custom_size = Some(Vec2::new(128., 128.));
commands.spawn((
dolly,
offset_transform.with_translation(Vec3 { x: 0., y: 0., z: 1. }),
Direction::Right
)
);

let mut room = Sprite::from_image(asset_server.load("room.png"));
room.custom_size = Some(Vec2::new(2.6 * 800., 800.));
commands.spawn((room, offset_transform.with_translation(Vec3 { x: 0., y: 200., z: 0. })));

commands.spawn(SpriteBundle {
texture: asset_server.load("room_end.png"),
transform: Transform::from_xyz(1116., -104.5, 0.2),
sprite: Sprite {
..Default::default()
},
..Default::default()
});
let mut room_end = Sprite::from_image(asset_server.load("room_end.png"));
commands.spawn((room_end.clone(), Transform::from_xyz(1016., -104.5, 2.0)));

commands.spawn(SpriteBundle {
texture: asset_server.load("room_end.png"),
transform: Transform::from_xyz(-916., -104.5, 0.2),
sprite: Sprite {
flip_x: true,
..Default::default()
},
..Default::default()
});
room_end.flip_x = true;
commands.spawn((room_end, Transform::from_xyz(-1016., -104.5, 2.0)));

commands.spawn((
MainCamera,
Rig::builder()
.with(Position::new(Vec3::new(0., 0., 0.)))
.with(Smooth::new_position(1.2))
.build(),
Camera2dBundle::default(),
Camera2d::default(),

Check failure on line 56 in examples/2d_edge_snap.rs

View workflow job for this annotation

GitHub Actions / Clippy

use of `default` to create a unit struct
));
}

Expand All @@ -82,8 +62,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
fn sprite_movement(time: Res<Time>, mut sprite_position: Query<(&mut Direction, &mut Transform)>) {
for (mut logo, mut transform) in &mut sprite_position {
match *logo {
Direction::Right => transform.translation.x += 400. * time.delta_seconds(),
Direction::Left => transform.translation.x -= 400. * time.delta_seconds(),
Direction::Right => transform.translation.x += 400. * time.delta_secs(),
Direction::Left => transform.translation.x -= 400. * time.delta_secs(),
}

if transform.translation.x > 1200. {
Expand Down
93 changes: 34 additions & 59 deletions examples/2d_fight_cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ fn main() {
.add_systems(Startup, setup)
.add_systems(PreUpdate, sprite_movement)
.add_systems(Update, update_camera)
.add_systems(Update, draw_gizmo)
.add_systems(Update, Dolly::<MainCamera>::update_2d_active_continuous)
// So gizmo is drawn after update as to not jump during camera movement
.add_systems(PostUpdate, draw_gizmo)
.run();
}

Expand All @@ -28,76 +29,50 @@ enum Direction {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands
.spawn(SpriteBundle {
texture: asset_server.load("bevy_dolly.png"),
transform: Transform::from_xyz(100., 0., 0.1),
sprite: Sprite {
custom_size: Some(Vec2::new(128., 128.)),
..Default::default()
},
..Default::default()
})
.insert(Direction::Right)
.insert(PlayerOne);

commands
.spawn(SpriteBundle {
texture: asset_server.load("bevy_dolly.png"),
transform: Transform::from_xyz(100., 0., 0.1),
sprite: Sprite {
custom_size: Some(Vec2::new(128., 128.)),
flip_x: true,
..Default::default()
},
..Default::default()
})
.insert(PlayerTwo);

commands.spawn(SpriteBundle {
texture: asset_server.load("room.png"),
transform: Transform::from_xyz(100., 200., 0.),
sprite: Sprite {
custom_size: Some(Vec2::new(2.6 * 800., 800.)),
..Default::default()
},
..Default::default()
});

commands.spawn(SpriteBundle {
texture: asset_server.load("room_end.png"),
transform: Transform::from_xyz(1116., -104.5, 0.2),
sprite: Sprite {
..Default::default()
},
..Default::default()
});

commands.spawn(SpriteBundle {
texture: asset_server.load("room_end.png"),
transform: Transform::from_xyz(-916., -104.5, 0.2),
sprite: Sprite {
flip_x: true,
..Default::default()
},
..Default::default()
});
let offset_transform = Transform::from_xyz(100., 0., 0.);

let mut dolly = Sprite::from_image(asset_server.load("bevy_dolly.png"));
dolly.custom_size = Some(Vec2::new(128., 128.));

commands.spawn((
dolly.clone(),
offset_transform.with_translation(Vec3 { x: 0., y: 0., z: 1. }),
Direction::Right,
PlayerOne
));

dolly.flip_x = true;
commands.spawn((
dolly,
offset_transform.with_translation(Vec3 { x: 0., y: 0., z: 1. }),
PlayerTwo
));

let mut room = Sprite::from_image(asset_server.load("room.png"));
room.custom_size = Some(Vec2::new(2.6 * 800., 800.));
commands.spawn((room, offset_transform.with_translation(Vec3 { x: 0., y: 200., z: 0. })));

let mut room_end = Sprite::from_image(asset_server.load("room_end.png"));
commands.spawn((room_end.clone(), Transform::from_xyz(1016., -104.5, 2.0)));

room_end.flip_x = true;
commands.spawn((room_end, Transform::from_xyz(-1016., -104.5, 2.0)));


commands.spawn((
MainCamera,
Rig::builder()
.with(Position::new(Vec3::new(0., 0., 0.)))
.with(Smooth::new_position(1.2))
.build(),
Camera2dBundle::default(),
Camera2d::default(),
));
}

fn draw_gizmo(mut gizmos: Gizmos, q0: Query<&Transform, With<MainCamera>>) {
for a in &q0 {
gizmos.rect_2d(
a.translation.truncate(),
0.,
Vec2::splat(300.),
Color::BLACK,
);
Expand All @@ -109,8 +84,8 @@ fn draw_gizmo(mut gizmos: Gizmos, q0: Query<&Transform, With<MainCamera>>) {
fn sprite_movement(time: Res<Time>, mut sprite_position: Query<(&mut Direction, &mut Transform)>) {
for (mut logo, mut transform) in &mut sprite_position {
match *logo {
Direction::Right => transform.translation.x += 400. * time.delta_seconds(),
Direction::Left => transform.translation.x -= 400. * time.delta_seconds(),
Direction::Right => transform.translation.x += 400. * time.delta_secs(),
Direction::Left => transform.translation.x -= 400. * time.delta_secs(),
}

if transform.translation.x > 1200. {
Expand Down
Loading

0 comments on commit 1c40fa6

Please sign in to comment.