Reset level
This commit is contained in:
parent
56fea25a87
commit
10abb0a676
3 changed files with 37 additions and 24 deletions
49
src/game.rs
49
src/game.rs
|
|
@ -41,12 +41,14 @@ impl Plugin for GamePlugin {
|
|||
.with_system(crate::levels::post_setup_level)
|
||||
.with_system(change_character_system)
|
||||
.with_system(player_movement_system)
|
||||
.with_system(level_keyboard_system)
|
||||
.with_system(move_camera)
|
||||
.with_system(character_particle_effect_system),
|
||||
)
|
||||
.add_system_set(
|
||||
SystemSet::on_update(AppState::Win)
|
||||
.with_system(player_movement_system)
|
||||
.with_system(level_keyboard_system)
|
||||
.with_system(move_camera)
|
||||
.with_system(character_particle_effect_system),
|
||||
)
|
||||
|
|
@ -56,7 +58,7 @@ impl Plugin for GamePlugin {
|
|||
|
||||
// Events
|
||||
|
||||
pub struct LevelStartupEvent(pub Entity);
|
||||
pub struct LevelStartupEvent;
|
||||
|
||||
// Resources
|
||||
|
||||
|
|
@ -94,19 +96,15 @@ pub struct Player;
|
|||
// Systems
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut current_level: ResMut<CurrentLevel>,
|
||||
mut level_startup_event: EventWriter<LevelStartupEvent>,
|
||||
mut camera_query: Query<&mut Transform, With<Camera>>,
|
||||
) {
|
||||
let level_id = LevelId(current_level.0.map_or(0, |level_id| level_id.0 + 1));
|
||||
crate::levels::setup_level(
|
||||
&mut commands,
|
||||
&mut current_level,
|
||||
&mut level_startup_event,
|
||||
&mut camera_query,
|
||||
level_id,
|
||||
);
|
||||
if current_level.0.is_none() {
|
||||
current_level.0 = Some(LevelId(0));
|
||||
}
|
||||
|
||||
crate::levels::setup_level(&mut level_startup_event, &mut camera_query);
|
||||
}
|
||||
|
||||
pub fn spawn_characters<I: IntoIterator<Item = (Transform, Color)>>(
|
||||
|
|
@ -300,7 +298,6 @@ fn change_character_system(
|
|||
fn player_movement_system(
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut characters: Query<&mut Velocity, With<Player>>,
|
||||
mut app_state: ResMut<State<AppState>>,
|
||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||
) {
|
||||
let right_pressed: bool =
|
||||
|
|
@ -316,10 +313,6 @@ fn player_movement_system(
|
|||
velocity.linvel.y = 500.;
|
||||
}
|
||||
}
|
||||
|
||||
if app_state.current() == &AppState::Win && keyboard_input.just_pressed(KeyCode::Return) {
|
||||
app_state.replace(AppState::Game).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn character_particle_effect_system(
|
||||
|
|
@ -374,3 +367,29 @@ fn move_camera(
|
|||
camera_transform.translation.z = 999.0;
|
||||
}
|
||||
}
|
||||
|
||||
fn level_keyboard_system(
|
||||
mut commands: Commands,
|
||||
mut current_level: ResMut<CurrentLevel>,
|
||||
mut level_startup_event: EventWriter<LevelStartupEvent>,
|
||||
mut camera_query: Query<&mut Transform, With<Camera>>,
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
level_query: Query<Entity, With<Level>>,
|
||||
mut app_state: ResMut<State<AppState>>,
|
||||
) {
|
||||
if app_state.current() == &AppState::Win && keyboard_input.just_pressed(KeyCode::Return) {
|
||||
current_level.0 = Some(LevelId(
|
||||
current_level.0.map_or(0, |level_id| level_id.0 + 1),
|
||||
));
|
||||
app_state.replace(AppState::Game).unwrap();
|
||||
}
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::R) {
|
||||
for entity in level_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
}
|
||||
if app_state.replace(AppState::Game).is_err() {
|
||||
crate::levels::setup_level(&mut level_startup_event, &mut camera_query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue