Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.15 #123

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,470 changes: 977 additions & 493 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,42 @@ dev = [
]

# All of Bevy's default features exept for the audio related ones (bevy_audio, vorbis), since they clash with bevy_kira_audio
# and android_shared_stdcxx, since that is covered in `mobile`
# and android_shared_stdcxx/android-game-activity, since those are covered in `mobile`
[dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"animation",
"bevy_asset",
"bevy_state",
"bevy_color",
"bevy_gilrs",
"bevy_scene",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_gilrs",
"bevy_gizmos",
"bevy_gltf",
"bevy_mesh_picking_backend",
"bevy_pbr",
"bevy_picking",
"bevy_render",
"bevy_scene",
"bevy_sprite",
"bevy_sprite_picking_backend",
"bevy_state",
"bevy_text",
"bevy_ui",
"bevy_ui_picking_backend",
"bevy_window",
"bevy_winit",
"custom_cursor",
"default_font",
"hdr",
"multi_threaded",
"png",
"hdr",
"x11",
"bevy_gizmos",
"tonemapping_luts",
"smaa_luts",
"default_font",
"webgl2",
"sysinfo_plugin",
"tonemapping_luts",
"webgl2",
"x11",
] }
bevy_kira_audio = { version = "0.20" }
bevy_asset_loader = { version = "0.21" }
bevy_kira_audio = { version = "0.21" }
bevy_asset_loader = { version = "0.22" }
rand = { version = "0.8.3" }
webbrowser = { version = "1", features = ["hardened"] }

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ Template for a Game using the awesome [Bevy engine][bevy] featuring out of the b
* workflow for GitHub actions creating releases for Windows, Linux, macOS, and Web (Wasm) ready for distribution
* the same workflow creates development builds for the mobile platforms (two separate workflows can push to the stores after [some setup](#deploy-mobile-platforms))
* push a tag in the form of `v[0-9]+.[0-9]+.[0-9]+*` (e.g. `v1.1.42`) to trigger the flow
* WARNING: if you work in a private repository, please be aware that macOS and Windows runners cost more build minutes. **For public repositories the builds are free!**
* CI workflow that checks your application on all native platforms on every push

WARNING: if you work in a private repository, please be aware that macOS and Windows runners cost more build minutes.
**For public repositories the workflow runners are free!**

# How to use this template?

Expand Down
2 changes: 1 addition & 1 deletion mobile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["staticlib", "cdylib"]

[dependencies]
bevy_game = { path = ".." } # ToDo
bevy = { version = "0.14", default-features = false }
bevy = { version = "0.15", default-features = false }

# As long as Kira doesn't expose a feature for this, we need to enable it
# See https://github.com/tesselode/kira/pull/51
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resizable: false,
mode: WindowMode::BorderlessFullscreen,
mode: WindowMode::BorderlessFullscreen(MonitorSelection::Current),
..default()
}),
..default()
Expand Down
3 changes: 1 addition & 2 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ pub fn set_movement_actions(

if let Some(touch_position) = touch_input.first_pressed_position() {
let (camera, camera_transform) = camera.single();
if let Some(touch_position) = camera.viewport_to_world_2d(camera_transform, touch_position)
{
if let Ok(touch_position) = camera.viewport_to_world_2d(camera_transform, touch_position) {
let diff = touch_position - player.single().translation.xy();
if diff.length() > FOLLOW_EPSILON {
player_movement = diff.normalize();
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use winit::window::Icon;

fn main() {
App::new()
.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::linear_rgb(0.4, 0.4, 0.4)))
.add_plugins(
DefaultPlugins
Expand Down
143 changes: 65 additions & 78 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ struct Menu;

fn setup_menu(mut commands: Commands, textures: Res<TextureAssets>) {
info!("menu");
commands.spawn(Camera2dBundle::default());
commands.spawn((Camera2d, Msaa::Off));
commands
.spawn((
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
Menu,
Expand All @@ -54,123 +51,113 @@ fn setup_menu(mut commands: Commands, textures: Res<TextureAssets>) {
let button_colors = ButtonColors::default();
children
.spawn((
ButtonBundle {
style: Style {
width: Val::Px(140.0),
height: Val::Px(50.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
},
background_color: button_colors.normal.into(),
Button,
Node {
width: Val::Px(140.0),
height: Val::Px(50.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..Default::default()
},
BackgroundColor(button_colors.normal),
button_colors,
ChangeState(GameState::Playing),
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Play",
TextStyle {
font_size: 40.0,
color: Color::linear_rgb(0.9, 0.9, 0.9),
..default()
},
));
});
.with_child((
Text::new("Play"),
TextFont {
font_size: 40.0,
..default()
},
TextColor(Color::linear_rgb(0.9, 0.9, 0.9)),
));
});
commands
.spawn((
NodeBundle {
style: Style {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
justify_content: JustifyContent::SpaceAround,
bottom: Val::Px(5.),
width: Val::Percent(100.),
position_type: PositionType::Absolute,
..default()
},
Node {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
justify_content: JustifyContent::SpaceAround,
bottom: Val::Px(5.),
width: Val::Percent(100.),
position_type: PositionType::Absolute,
..default()
},
Menu,
))
.with_children(|children| {
children
.spawn((
ButtonBundle {
style: Style {
width: Val::Px(170.0),
height: Val::Px(50.0),
justify_content: JustifyContent::SpaceAround,
align_items: AlignItems::Center,
padding: UiRect::all(Val::Px(5.)),
..Default::default()
},
background_color: Color::NONE.into(),
Button,
Node {
width: Val::Px(170.0),
height: Val::Px(50.0),
justify_content: JustifyContent::SpaceAround,
align_items: AlignItems::Center,
padding: UiRect::all(Val::Px(5.)),
..Default::default()
},
BackgroundColor(Color::NONE),
ButtonColors {
normal: Color::NONE,
..default()
},
OpenLink("https://bevyengine.org"),
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Made with Bevy",
TextStyle {
parent.spawn((
Text::new("Made with Bevy"),
TextFont {
font_size: 15.0,
color: Color::linear_rgb(0.9, 0.9, 0.9),
..default()
},
TextColor(Color::linear_rgb(0.9, 0.9, 0.9)),
));
parent.spawn(ImageBundle {
image: textures.bevy.clone().into(),
style: Style {
parent.spawn((
ImageNode {
image: textures.bevy.clone(),
..default()
},
Node {
width: Val::Px(32.),
..default()
},
..default()
});
));
});
children
.spawn((
ButtonBundle {
style: Style {
width: Val::Px(170.0),
height: Val::Px(50.0),
justify_content: JustifyContent::SpaceAround,
align_items: AlignItems::Center,
padding: UiRect::all(Val::Px(5.)),
..default()
},
background_color: Color::NONE.into(),
..Default::default()
Button,
Node {
width: Val::Px(170.0),
height: Val::Px(50.0),
justify_content: JustifyContent::SpaceAround,
align_items: AlignItems::Center,
padding: UiRect::all(Val::Px(5.)),
..default()
},
BackgroundColor(Color::NONE),
ButtonColors {
normal: Color::NONE,
hovered: Color::linear_rgb(0.25, 0.25, 0.25),
},
OpenLink("https://github.com/NiklasEi/bevy_game_template"),
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Open source",
TextStyle {
parent.spawn((
Text::new("Open source"),
TextFont {
font_size: 15.0,
color: Color::linear_rgb(0.9, 0.9, 0.9),
..default()
},
TextColor(Color::linear_rgb(0.9, 0.9, 0.9)),
));
parent.spawn(ImageBundle {
image: textures.github.clone().into(),
style: Style {
parent.spawn((
ImageNode::new(textures.github.clone()),
Node {
width: Val::Px(32.),
..default()
},
..default()
});
));
});
});
}
Expand Down
16 changes: 7 additions & 9 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ impl Plugin for PlayerPlugin {
}

fn spawn_player(mut commands: Commands, textures: Res<TextureAssets>) {
commands
.spawn(SpriteBundle {
texture: textures.bevy.clone(),
transform: Transform::from_translation(Vec3::new(0., 0., 1.)),
..Default::default()
})
.insert(Player);
commands.spawn((
Sprite::from_image(textures.bevy.clone()),
Transform::from_translation(Vec3::new(0., 0., 1.)),
Player,
));
}

fn move_player(
Expand All @@ -37,8 +35,8 @@ fn move_player(
}
let speed = 150.;
let movement = Vec3::new(
actions.player_movement.unwrap().x * speed * time.delta_seconds(),
actions.player_movement.unwrap().y * speed * time.delta_seconds(),
actions.player_movement.unwrap().x * speed * time.delta_secs(),
actions.player_movement.unwrap().y * speed * time.delta_secs(),
0.,
);
for mut player_transform in &mut player_query {
Expand Down
Loading