GameStates introduced
This commit is contained in:
parent
f02158833c
commit
b7aff68e3a
7 changed files with 40 additions and 12 deletions
|
|
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
|||
use rand::{prelude::*, rng};
|
||||
|
||||
use crate::{
|
||||
FIRST_CORNER_X, FIRST_CORNER_Y, SECOND_CORNER_X, SECOND_CORNER_Y,
|
||||
FIRST_CORNER_X, FIRST_CORNER_Y, GameState, SECOND_CORNER_X, SECOND_CORNER_Y,
|
||||
collision::{Collided, Collider},
|
||||
damagable::Damagable,
|
||||
projectile::Projectile,
|
||||
|
|
@ -15,8 +15,11 @@ pub struct AsteroidPlugin;
|
|||
|
||||
impl Plugin for AsteroidPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup_asteroids)
|
||||
.add_systems(FixedUpdate, rotate_asteroid);
|
||||
app.add_systems(OnEnter(GameState::Game), setup_asteroids)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
rotate_asteroid.run_if(in_state(GameState::Game)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::GameState;
|
||||
|
||||
pub struct CollisionPlugin;
|
||||
|
||||
impl Plugin for CollisionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(FixedUpdate, calculate_collisions);
|
||||
app.add_systems(
|
||||
FixedUpdate,
|
||||
calculate_collisions.run_if(in_state(GameState::Game)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
use bevy::prelude::*;
|
||||
use std::default::Default;
|
||||
|
||||
use crate::GameState;
|
||||
|
||||
pub struct DamagablePlugin;
|
||||
|
||||
impl Plugin for DamagablePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(FixedPostUpdate, broken_ships_cleanup);
|
||||
app.add_systems(
|
||||
FixedPostUpdate,
|
||||
broken_ships_cleanup.run_if(in_state(GameState::Game)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,13 @@ const FIRST_CORNER_Y: f32 = -512.;
|
|||
const SECOND_CORNER_X: f32 = 512.;
|
||||
const SECOND_CORNER_Y: f32 = 512.;
|
||||
|
||||
#[derive(States, Debug, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum GameState {
|
||||
InMenu,
|
||||
Game,
|
||||
Gameover,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(
|
||||
|
|
@ -37,6 +44,7 @@ fn main() {
|
|||
})
|
||||
.set(ImagePlugin::default_nearest()),
|
||||
)
|
||||
.insert_state(GameState::Game)
|
||||
.add_plugins(VelocityPlugin)
|
||||
.add_plugins(CollisionPlugin)
|
||||
.add_plugins(ShipsPlugin)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
GameState,
|
||||
collision::{Collided, Collider},
|
||||
damagable::Damagable,
|
||||
ships::Factions,
|
||||
|
|
@ -31,8 +32,11 @@ impl Projectile {
|
|||
|
||||
impl Plugin for ProjectilePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, projectile_startup)
|
||||
.add_systems(FixedPreUpdate, projectile_despawn_countdown);
|
||||
app.add_systems(OnEnter(GameState::Game), projectile_startup)
|
||||
.add_systems(
|
||||
FixedPreUpdate,
|
||||
projectile_despawn_countdown.run_if(in_state(GameState::Game)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::projectile::spawn_projectile;
|
||||
use crate::GameState;
|
||||
|
||||
pub mod enemy;
|
||||
pub mod player;
|
||||
|
|
@ -39,11 +39,11 @@ pub struct ShipsPlugin;
|
|||
impl Plugin for ShipsPlugin {
|
||||
fn build(&self, app: &mut bevy::app::App) {
|
||||
app.insert_resource(Time::<Fixed>::from_hz(60.))
|
||||
.add_systems(Startup, startup)
|
||||
.add_systems(OnEnter(GameState::Game), startup)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
player::player_movement_system,
|
||||
player::player_movement_system.run_if(in_state(GameState::Game)),
|
||||
player::player_shooting_system,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
use bevy::prelude::*;
|
||||
use std::default::Default;
|
||||
|
||||
use crate::{FIRST_CORNER_X, FIRST_CORNER_Y, SECOND_CORNER_X, SECOND_CORNER_Y};
|
||||
use crate::{FIRST_CORNER_X, FIRST_CORNER_Y, GameState, SECOND_CORNER_X, SECOND_CORNER_Y};
|
||||
|
||||
pub struct VelocityPlugin;
|
||||
|
||||
impl Plugin for VelocityPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(Time::<Fixed>::from_hz(60.0))
|
||||
.add_systems(FixedUpdate, movement_system);
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
movement_system.run_if(in_state(GameState::Game)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue