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

upgraded to bevy 0.14.0 #1

Merged
merged 6 commits into from
Aug 8, 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
2,412 changes: 1,763 additions & 649 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,30 @@ opt-level = 3
[profile.dev]
opt-level = 1

[features]
dev = ["bevy/bevy_dylib"]

# Bevy defaults minus audio and some other not needed things
# see https://github.com/bevyengine/bevy/blob/main/Cargo.toml#L31-L54
default = ["bevy/animation", "bevy/bevy_asset", "bevy/bevy_scene", "bevy/bevy_winit", "bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gltf", "bevy/bevy_render", "bevy/bevy_sprite", "bevy/bevy_text", "bevy/bevy_ui", "bevy/png", "bevy/hdr", "bevy/zstd", "bevy/x11", "bevy/ktx2", "bevy/filesystem_watcher", "bevy/tonemapping_luts"]



[dependencies]
bevy = { version = "0.10.1", default-features = false }
bevy_asset_loader = "0.15.0"
bevy_kira_audio = { version = "0.15", default-features = false, features = ["wav", "ogg"] }
bevy = { version = "0.14.0", default-features = false, features = [
"animation",
"bevy_asset",
"bevy_scene",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_gltf",
"bevy_render",
"bevy_sprite",
"bevy_text",
"bevy_ui",
"png",
"hdr",
"zstd",
"x11",
"ktx2",
"file_watcher", # Changed from "filesystem_watcher"
"multi_threaded", # Add this line
"tonemapping_luts",
"dynamic_linking" # Optional: remove if not needed
]}
bevy_asset_loader = { version = "0.21.0" }
bevy_kira_audio = { version = "0.20.0", default-features = false, features = ["wav", "ogg"] }
rand = "0.8.5"
bevy_jornet = "0.4.0"
bevy_jornet = "0.8.0"
4 changes: 2 additions & 2 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bevy::prelude::*;
use bevy_asset_loader::prelude::AssetCollection;
use bevy_asset_loader::prelude::*;
use bevy_kira_audio::AudioSource;

#[derive(AssetCollection, Resource)]
#[derive(Resource, AssetCollection)]
pub struct AudioAssets {
#[asset(path = "audio/bgm-main.ogg")]
pub bgm_main: Handle<AudioSource>,
Expand Down
4 changes: 2 additions & 2 deletions src/enemies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn update_enemy_grid_pos(
enemy.current_grid_pos = (grid_pos.0, grid_pos.1);
map.enemies
.entry(enemy.current_grid_pos)
.or_insert_with(Vec::new)
.or_default()
.push(entity);
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn update_healthbar(
.spawn(SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(22.0, 4.0)),
color: Color::rgb(0.0, 0.0, 0.0),
color: Color::srgb(0.0, 0.0, 0.0),
..Default::default()
},
transform: Transform::from_translation(Vec3::new(0.0, -16.0, 6.0)),
Expand Down
2 changes: 1 addition & 1 deletion src/gameplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pub fn gameloop(
}

pub fn start_next_wave(
input: Res<Input<KeyCode>>,
input: Res<ButtonInput<KeyCode>>,
mut game_manager: ResMut<GameManager>,
drums_channel: Res<AudioChannel<DrumsChannel>>,
volume_settings: Res<VolumeSettings>,
Expand Down
4 changes: 2 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn grid_click_handler(
mut ui_data: ResMut<UiData>,
mut ui_state: ResMut<UiStateResource>,
mut inventory: ResMut<Inventory>,
mouse_input: Res<Input<MouseButton>>,
mouse_input: Res<ButtonInput<MouseButton>>,
windows: Query<&Window>,
camera: Query<(&Camera, &GlobalTransform)>,
game_assets: Res<GameAssets>,
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn mouse_hover_handler(
mut children_query: Query<&mut Visibility, With<RangeIndicator>>,
mut hover_pos: ResMut<HoverPosition>,
) {
for event in cursor_events.iter() {
for event in cursor_events.read() {
let mouse_pos = event.position;
let (camera, camera_transform) = camera.get_single().unwrap();

Expand Down
28 changes: 15 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![allow(clippy::too_many_arguments, clippy::type_complexity)]

use audio::{AudioAssets, DrumsChannel, MusicChannel, SoundChannel};
use bevy::prelude::*;
use bevy_asset_loader::prelude::{LoadingState, LoadingStateAppExt};
use bevy_asset_loader::prelude::*;
use bevy_kira_audio::{AudioApp, AudioPlugin};

use audio::{AudioAssets, DrumsChannel, MusicChannel, SoundChannel};
use state::{
game::GamePlugin, loading::GameAssets, main_menu::MainMenuPlugin, results::ResultsPlugin,
};
Expand All @@ -21,19 +22,20 @@ mod ui;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugin(AudioPlugin)
.add_state::<state::State>()
.add_plugins(AudioPlugin)
.init_state::<state::State>()
.add_loading_state(
LoadingState::new(state::State::Loading).continue_to_state(state::State::MainMenu),
LoadingState::new(state::State::Loading)
.continue_to_state(state::State::MainMenu)
.load_collection::<GameAssets>()
.load_collection::<AudioAssets>(),
)
.add_collection_to_loading_state::<_, GameAssets>(state::State::Loading)
.add_collection_to_loading_state::<_, AudioAssets>(state::State::Loading)
.add_plugin(MainMenuPlugin)
.add_plugin(GamePlugin)
.add_plugin(ResultsPlugin)
.add_startup_system(state::results::create_player)
.add_system(state::loading::setup.in_schedule(OnEnter(state::State::Loading)))
.add_system(state::loading::cleanup.in_schedule(OnExit(state::State::Loading)))
.add_plugins(MainMenuPlugin)
.add_plugins(GamePlugin)
.add_plugins(ResultsPlugin)
.add_systems(Startup, state::results::create_player)
.add_systems(OnEnter(state::State::Loading), state::loading::setup)
.add_systems(OnExit(state::State::Loading), state::loading::cleanup)
.add_audio_channel::<MusicChannel>()
.add_audio_channel::<DrumsChannel>()
.add_audio_channel::<SoundChannel>()
Expand Down
160 changes: 123 additions & 37 deletions src/state/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,139 @@ impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.add_event::<tower::TowerPlaced>()
.add_event::<tower::debuffs::AddDebuff>()
.add_system(setup.in_schedule(OnEnter(super::State::Game)))
.add_system(grid::load_map.in_schedule(OnEnter(super::State::Game)))
.add_system(statusbar::draw_status_bar.in_schedule(OnEnter(super::State::Game)))
.add_system(gameplay::gameloop.in_set(OnUpdate(super::State::Game)))
.add_system(gameplay::start_next_wave.in_set(OnUpdate(super::State::Game)))
.add_system(gameplay::game_over_check.in_set(OnUpdate(super::State::Game)))
.add_systems(OnEnter(super::State::Game), setup)
.add_systems(OnEnter(super::State::Game), grid::load_map)
.add_systems(OnEnter(super::State::Game), statusbar::draw_status_bar)
.add_systems(
Update,
gameplay::gameloop.run_if(in_state(super::State::Game)),
) // gameplay::gameloop.in_set(OnUpdate(super::State::Game)))
.add_systems(
Update,
gameplay::start_next_wave.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
gameplay::game_over_check.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
(
enemies::enemy_movement.in_set(OnUpdate(super::State::Game)),
enemies::update_enemy_grid_pos.in_set(OnUpdate(super::State::Game)),
enemies::enemy_movement.run_if(in_state(super::State::Game)),
enemies::update_enemy_grid_pos.run_if(in_state(super::State::Game)),
)
.chain(),
)
.add_systems(
Update,
(
enemies::check_killed.in_set(OnUpdate(super::State::Game)),
enemies::update_healthbar.in_set(OnUpdate(super::State::Game)),
enemies::scale_healthbar.in_set(OnUpdate(super::State::Game)),
enemies::check_killed.run_if(in_state(super::State::Game)),
enemies::update_healthbar.run_if(in_state(super::State::Game)),
enemies::scale_healthbar.run_if(in_state(super::State::Game)),
)
.chain(),
)
.add_system(tower::handle_tower_placement.in_set(OnUpdate(super::State::Game)))
.add_system(tower::debuffs::debuff_event_handler.in_set(OnUpdate(super::State::Game)))
.add_system(tower::debuffs::handle_overheat.in_set(OnUpdate(super::State::Game)))
.add_system(tower::charge_shot::shoot.in_set(OnUpdate(super::State::Game)))
.add_system(tower::sniper::shoot.in_set(OnUpdate(super::State::Game)))
.add_system(tower::handle_projectiles.in_set(OnUpdate(super::State::Game)))
.add_system(tower::laser::shoot.in_set(OnUpdate(super::State::Game)))
.add_system(tower::jammer::rotate_dish.in_set(OnUpdate(super::State::Game)))
.add_system(tower::missile::spawn_missile.in_set(OnUpdate(super::State::Game)))
.add_system(tower::missile::handle_missile.in_set(OnUpdate(super::State::Game)))
.add_system(ui::update_selection_indicator.in_set(OnUpdate(super::State::Game)))
.add_system(inventory::draw_inventory.in_set(OnUpdate(super::State::Game)))
.add_system(inventory::handle_inventory_buttons.in_set(OnUpdate(super::State::Game)))
.add_system(inventory::create_ghost.in_set(OnUpdate(super::State::Game)))
.add_system(inventory::handle_ghost.in_set(OnUpdate(super::State::Game)))
.add_system(tower_options::handle_tower_options.in_set(OnUpdate(super::State::Game)))
.add_system(sidebar::draw_sidebar.in_set(OnUpdate(super::State::Game)))
.add_system(sidebar::handle_toggle_rotation_button.in_set(OnUpdate(super::State::Game)))
.add_system(statusbar::update_status_bar_text.in_set(OnUpdate(super::State::Game)))
.add_system(statusbar::update_score_text.in_set(OnUpdate(super::State::Game)))
.add_system(statusbar::update_lives_text.in_set(OnUpdate(super::State::Game)))
.add_system(statusbar::handle_normal_speed_button.in_set(OnUpdate(super::State::Game)))
.add_system(statusbar::handle_fast_speed_button.in_set(OnUpdate(super::State::Game)))
.add_system(input::grid_click_handler.in_set(OnUpdate(super::State::Game)))
.add_system(input::mouse_hover_handler.in_set(OnUpdate(super::State::Game)))
.add_system(cleanup.in_schedule(OnExit(super::State::Game)));
.add_systems(
Update,
tower::handle_tower_placement.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::debuffs::debuff_event_handler.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::debuffs::handle_overheat.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::charge_shot::shoot.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::sniper::shoot.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::handle_projectiles.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::laser::shoot.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::jammer::rotate_dish.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::missile::spawn_missile.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower::missile::handle_missile.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
ui::update_selection_indicator.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
inventory::draw_inventory.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
inventory::handle_inventory_buttons.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
inventory::create_ghost.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
inventory::handle_ghost.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
tower_options::handle_tower_options.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
sidebar::draw_sidebar.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
sidebar::handle_toggle_rotation_button.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
statusbar::update_status_bar_text.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
statusbar::update_score_text.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
statusbar::update_lives_text.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
statusbar::handle_normal_speed_button.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
statusbar::handle_fast_speed_button.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
input::grid_click_handler.run_if(in_state(super::State::Game)),
)
.add_systems(
Update,
input::mouse_hover_handler.run_if(in_state(super::State::Game)),
)
.add_systems(OnExit(super::State::Game), cleanup);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/state/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
style: Style {
margin: UiRect::all(Val::Auto),
padding: UiRect::all(Val::Px(20.)),
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::ColumnReverse,
Expand Down
25 changes: 16 additions & 9 deletions src/state/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ pub struct MainMenuPlugin;

impl Plugin for MainMenuPlugin {
fn build(&self, app: &mut App) {
app.add_system(setup.in_schedule(OnEnter(super::State::MainMenu)))
.add_system(button_system.in_set(OnUpdate(super::State::MainMenu)))
.add_system(update_button_volume_text.in_set(OnUpdate(super::State::MainMenu)))
.add_system(cleanup.in_schedule(OnExit(super::State::MainMenu)));
app.add_systems(OnEnter(State::MainMenu), setup)
.add_systems(Update, button_system.run_if(in_state(State::MainMenu)))
.add_systems(
Update,
update_button_volume_text.run_if(in_state(State::MainMenu)),
)
.add_systems(OnExit(State::MainMenu), cleanup);
}
}

Expand All @@ -49,8 +52,10 @@ fn setup(
commands
.spawn(ImageBundle {
style: Style {
size: Size::new(Val::Auto, Val::Percent(100.0)),
max_size: Size::new(Val::Px(1920.0), Val::Px(1080.0)),
width: Val::Percent(100.0),
height: Val::Percent(100.0),
max_width: Val::Px(1920.0),
max_height: Val::Percent(1080.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
aspect_ratio: Some(1.778),
Expand All @@ -67,7 +72,8 @@ fn setup(
// Spacer
parent.spawn(NodeBundle {
style: Style {
size: Size::new(Val::Percent(100.0), Val::Px(300.0)),
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..Default::default()
},
..Default::default()
Expand All @@ -80,7 +86,8 @@ fn setup(

fn add_button(parent: &mut ChildBuilder, text: &str, button: MenuButton, font: Handle<Font>) {
let button_style = Style {
size: Size::new(Val::Px(210.0), Val::Px(65.0)),
width: Val::Px(210.0),
height: Val::Px(65.0),
// center button
margin: UiRect::all(Val::Px(20.0)),
// horizontally center child text
Expand Down Expand Up @@ -120,7 +127,7 @@ fn button_system(
) {
for (button, interaction, mut color) in &mut interaction_query {
match *interaction {
Interaction::Clicked => {
Interaction::Pressed => {
*color = BUTTON_BACKGROUND_COLOR_PRESSED.into();
match button {
MenuButton::Start => next_state.set(State::Game),
Expand Down
Loading
Loading