Skip to content
Open
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,120 changes: 1,502 additions & 618 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 @@ -10,7 +10,7 @@ opt-level = 1
opt-level = 3

[dependencies]
bevy = {version = "0.9", features = ["dynamic", "wav"] }
bevy = {version = "0.10", features = ["wav"] }
bevy-inspector-egui = "0.14.0"
bevy_mod_picking = "0.10"
bevy_mod_picking = { git = "https://github.com/Fincap/bevy_mod_picking.git", branch = "migrate-bevy-0.10.0" }

8 changes: 3 additions & 5 deletions src/bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ impl Plugin for BulletPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Bullet>()
.register_type::<Lifetime>()
.add_system_set(
SystemSet::on_update(GameState::Gameplay)
.with_system(bullet_collision)
.with_system(move_bullets)
.with_system(bullet_despawn),
.add_systems(
(bullet_collision, move_bullets, bullet_despawn)
.in_set(OnUpdate(GameState::Gameplay)),
);
}
}
Expand Down
25 changes: 13 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{pbr::NotShadowCaster, prelude::*, utils::FloatOrd};
use bevy_inspector_egui::{Inspectable, RegisterInspectable, WorldInspectorPlugin};
use bevy::{pbr::NotShadowCaster, prelude::*, utils::FloatOrd, window::WindowResolution};
use bevy_inspector_egui::Inspectable;
use bevy_mod_picking::*;

pub const HEIGHT: f32 = 720.0;
Expand Down Expand Up @@ -29,8 +29,9 @@ pub use player::*;
pub use target::*;
pub use tower::*;

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[derive(States, Debug, Default, Clone, Eq, PartialEq, Hash)]
pub enum GameState {
#[default]
MainMenu,
Gameplay,
}
Expand All @@ -40,31 +41,31 @@ fn main() {
// Window Setup
.insert_resource(ClearColor(Color::rgb(0.3, 0.3, 0.3)))
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
width: WIDTH,
height: HEIGHT,
primary_window: Some(Window {
resolution: WindowResolution::new(WIDTH, HEIGHT),
title: "Bevy Tower Defense".to_string(),
resizable: false,
..default()
},
}),
..default()
}))
// Inspector Setup
.add_plugin(WorldInspectorPlugin::new())
// TODO: Update to a new version of bevy_inspector_egui
// .add_plugin(WorldInspectorPlugin::new())
// Mod Picking
.add_plugins(DefaultPickingPlugins)
// Our State
.add_state(GameState::MainMenu)
.add_state::<GameState>()
// Our Systems
.add_plugin(TowerPlugin)
.add_plugin(TargetPlugin)
.add_plugin(BulletPlugin)
.add_plugin(MainMenuPlugin)
.add_plugin(PlayerPlugin)
//TODO despawn scene on returning to main menu (on_exit)
.add_system_set(SystemSet::on_enter(GameState::Gameplay).with_system(spawn_basic_scene))
.add_system(spawn_basic_scene.in_schedule(OnEnter(GameState::Gameplay)))
.add_startup_system(spawn_camera)
.add_startup_system_to_stage(StartupStage::PreStartup, asset_loading)
.add_startup_system(asset_loading.in_base_set(StartupSet::PreStartup))
.add_system(camera_controls)
.run();
}
Expand Down Expand Up @@ -138,7 +139,7 @@ fn spawn_basic_scene(
) {
commands
.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 50.0 })),
mesh: meshes.add(Mesh::from(shape::Plane::from_size(50.0))),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
})
Expand Down
13 changes: 9 additions & 4 deletions src/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,34 @@ pub struct MainMenuPlugin;

impl Plugin for MainMenuPlugin {
fn build(&self, app: &mut App) {
app.add_system_set(SystemSet::on_enter(GameState::MainMenu).with_system(spawn_main_menu))
// This could just be a normal system because the button should only exist during the menu state
/*
app.add_systems(SystemSet::on_enter(GameState::MainMenu).with_system(spawn_main_menu))
.add_system_set(
SystemSet::on_update(GameState::MainMenu)
.with_system(start_button_clicked)
.with_system(quit_button_clicked),
);
*/
app.add_system(spawn_main_menu.in_schedule(OnEnter(GameState::MainMenu)))
.add_systems(
(start_button_clicked, quit_button_clicked).in_set(OnUpdate(GameState::MainMenu)),
);
}
}

fn start_button_clicked(
mut commands: Commands,
interactions: Query<&Interaction, (With<StartButton>, Changed<Interaction>)>,
menu_root: Query<Entity, With<MenuUIRoot>>,
mut game_state: ResMut<State<GameState>>,
mut game_state: ResMut<NextState<GameState>>,
mut mouse_input: ResMut<Input<MouseButton>>,
) {
for interaction in &interactions {
if matches!(interaction, Interaction::Clicked) {
let root_entity = menu_root.single();
commands.entity(root_entity).despawn_recursive();

game_state.set(GameState::Gameplay).unwrap();
game_state.set(GameState::Gameplay);
mouse_input.clear();
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ pub struct PlayerPlugin;
impl Plugin for PlayerPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Player>()
.add_system_set(
SystemSet::on_enter(GameState::Gameplay)
.with_system(spawn_player)
.with_system(spawn_gameplay_ui),
.add_systems(
(spawn_player, spawn_gameplay_ui).in_schedule(OnEnter(GameState::Gameplay)),
)
.add_system_set(
SystemSet::on_update(GameState::Gameplay)
.with_system(give_money_on_kill)
.with_system(update_player_ui),
.add_systems(
(give_money_on_kill, update_player_ui).in_set(OnUpdate(GameState::Gameplay)),
);
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ impl Plugin for TargetPlugin {
Vec2::new(9.0, 9.0),
],
})
.add_system_set(
SystemSet::on_update(GameState::Gameplay)
.with_system(move_targets)
.with_system(hurt_player.after(move_targets))
.with_system(target_death),
.add_systems(
(move_targets, hurt_player.after(move_targets), target_death)
.in_set(OnUpdate(GameState::Gameplay)),
);
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/tower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ pub struct TowerPlugin;
impl Plugin for TowerPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Tower>()
.register_inspectable::<TowerType>()
// TODO: Figure out what to do here:
// .register_inspectable::<TowerType>()
.register_type::<TowerButtonState>()
.add_system_set(
SystemSet::on_update(GameState::Gameplay)
.with_system(tower_shooting)
.with_system(tower_button_clicked)
.with_system(create_ui_on_selection)
.with_system(grey_tower_buttons.after(create_ui_on_selection)),
.add_systems(
(
tower_shooting,
tower_button_clicked,
create_ui_on_selection,
grey_tower_buttons.after(create_ui_on_selection),
)
.in_set(OnUpdate(GameState::Gameplay)),
);
}
}
Expand Down