upd to bevy 0.11

This commit is contained in:
Edgar 2023-09-07 16:04:15 +02:00
parent b8e6a87bb0
commit 74017b961d
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
5 changed files with 429 additions and 299 deletions

689
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,6 @@ opt-level = 3
lto = "thin" lto = "thin"
[dependencies] [dependencies]
bevy = { version = "0.10.1", features = ["dynamic_linking"] } bevy = { version = "0.11", features = ["dynamic_linking"] }
bevy-inspector-egui = "0.18.3" bevy-inspector-egui = "0.19"
bevy_ecs_tilemap = "0.10.0" bevy_ecs_tilemap = "0.11"

View file

@ -1,3 +1,5 @@
# teecity # teecity
`cargo run --features bevy/dynamic_linking` `cargo run --features bevy/dynamic_linking`
https://bevy-cheatbook.github.io/

View file

@ -10,9 +10,10 @@ impl Plugin for GamePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app app
// on enter // on enter
.add_systems((game_setup, player::add_player).in_schedule(OnEnter(AppState::InGame))) .add_systems(OnEnter(AppState::InGame), (game_setup, player::add_player))
// on update // on update
.add_systems( .add_systems(
Update,
( (
physics::move_system, physics::move_system,
player::player_input.before(physics::move_system), player::player_input.before(physics::move_system),
@ -20,11 +21,12 @@ impl Plugin for GamePlugin {
misc::aim_target_system.after(physics::move_system), misc::aim_target_system.after(physics::move_system),
player::player_camera.after(misc::aim_target_system), player::player_camera.after(misc::aim_target_system),
) )
.in_set(OnUpdate(AppState::InGame)), .run_if(in_state(AppState::InGame)),
) )
// on exit // on exit
.add_systems( .add_systems(
(crate::despawn_screen::<OnGameScreen>,).in_schedule(OnExit(AppState::InGame)), OnExit(AppState::InGame),
(crate::despawn_screen::<OnGameScreen>,),
); );
} }
} }

View file

@ -21,13 +21,14 @@ enum MenuState {
impl Plugin for MenuPlugin { impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_state::<MenuState>() app.add_state::<MenuState>()
.add_system(menu_setup.in_schedule(OnEnter(AppState::MainMenu))) .add_systems(OnEnter(AppState::MainMenu), menu_setup)
.add_systems(( .add_systems(OnEnter(MenuState::Main), main_menu_setup)
main_menu_setup.in_schedule(OnEnter(MenuState::Main)), .add_systems(OnExit(MenuState::Main), despawn_screen::<OnMainMenuScreen>)
despawn_screen::<OnMainMenuScreen>.in_schedule(OnExit(MenuState::Main)),
))
// Common systems to all screens that handles buttons behaviour // Common systems to all screens that handles buttons behaviour
.add_systems((menu_action, button_system).in_set(OnUpdate(AppState::MainMenu))); .add_systems(
Update,
(menu_action, button_system).run_if(in_state(AppState::MainMenu)),
);
} }
} }
@ -69,7 +70,6 @@ const HOVERED_BUTTON: Color = Color::rgb(0.25, 0.25, 0.25);
const HOVERED_PRESSED_BUTTON: Color = Color::rgb(0.25, 0.65, 0.25); const HOVERED_PRESSED_BUTTON: Color = Color::rgb(0.25, 0.65, 0.25);
const PRESSED_BUTTON: Color = Color::rgb(0.35, 0.75, 0.35); const PRESSED_BUTTON: Color = Color::rgb(0.35, 0.75, 0.35);
// This system handles changing all buttons color based on mouse interaction
fn button_system( fn button_system(
mut interaction_query: Query< mut interaction_query: Query<
(&Interaction, &mut BackgroundColor, Option<&SelectedOption>), (&Interaction, &mut BackgroundColor, Option<&SelectedOption>),
@ -78,7 +78,7 @@ fn button_system(
) { ) {
for (interaction, mut color, selected) in &mut interaction_query { for (interaction, mut color, selected) in &mut interaction_query {
*color = match (*interaction, selected) { *color = match (*interaction, selected) {
(Interaction::Clicked, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(), (Interaction::Pressed, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(),
(Interaction::Hovered, Some(_)) => HOVERED_PRESSED_BUTTON.into(), (Interaction::Hovered, Some(_)) => HOVERED_PRESSED_BUTTON.into(),
(Interaction::Hovered, None) => HOVERED_BUTTON.into(), (Interaction::Hovered, None) => HOVERED_BUTTON.into(),
(Interaction::None, None) => NORMAL_BUTTON.into(), (Interaction::None, None) => NORMAL_BUTTON.into(),
@ -94,7 +94,8 @@ fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let font = asset_server.load("fonts/OpenSans-Bold.ttf"); let font = asset_server.load("fonts/OpenSans-Bold.ttf");
// Common style for all buttons on the screen // Common style for all buttons on the screen
let button_style = Style { let button_style = Style {
size: Size::new(Val::Px(250.0), Val::Px(65.0)), width: Val::Px(250.0),
height: Val::Px(65.0),
margin: UiRect::all(Val::Px(20.0)), margin: UiRect::all(Val::Px(20.0)),
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
align_items: AlignItems::Center, align_items: AlignItems::Center,
@ -125,7 +126,7 @@ fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn(( .spawn((
NodeBundle { NodeBundle {
style: Style { style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), width: Val::Percent(100.0),
align_items: AlignItems::Center, align_items: AlignItems::Center,
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
..default() ..default()
@ -246,7 +247,7 @@ fn menu_action(
mut game_state: ResMut<NextState<AppState>>, mut game_state: ResMut<NextState<AppState>>,
) { ) {
for (interaction, menu_button_action) in &interaction_query { for (interaction, menu_button_action) in &interaction_query {
if *interaction == Interaction::Clicked { if *interaction == Interaction::Pressed {
match menu_button_action { match menu_button_action {
MenuButtonAction::Quit => app_exit_events.send(AppExit), MenuButtonAction::Quit => app_exit_events.send(AppExit),
MenuButtonAction::Play => { MenuButtonAction::Play => {