Compare commits

...

2 commits

Author SHA1 Message Date
be96747d6a removed unused 'use' 2022-08-24 19:45:32 +08:00
3f79054ed7 add change character system to play stageasdasd 2022-08-24 19:45:13 +08:00

View file

@ -9,7 +9,6 @@ use bevy::{
sprite::Mesh2dHandle, ecs::system::EntityCommands,
};
use bevy_rapier2d::prelude::*;
use std::collections::BTreeSet;
pub enum AudioMsg {
Color([f32; 3]),
@ -34,13 +33,13 @@ impl Plugin for GamePlugin {
.add_system_set(
SystemSet::on_update(AppState::Game)
.with_system(crate::levels::post_setup_level)
.with_system(change_character_system)
.with_system(player_movement_system)
.with_system(move_camera)
.with_system(character_particle_effect_system),
)
.add_system_set(
SystemSet::on_update(AppState::Win)
.with_system(change_character_system)
)
.add_system_set(
SystemSet::on_update(AppState::Win)
.with_system(player_movement_system)
.with_system(move_camera)
.with_system(character_particle_effect_system),
@ -186,14 +185,16 @@ fn collision_event_system(
character_meshes: Res<CharacterMeshes>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut collision_events: EventReader<CollisionEvent>,
character_query: Query<(&CharacterColor, &Transform)>,
character_query: Query<(&CharacterColor, &Transform, Option<&Player>)>,
mut app_state: ResMut<State<AppState>>,
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
) {
for collision_event in collision_events.iter() {
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
if flags.is_empty() {
if let (Ok((c1_color, c1_transform)), Ok((c2_color, _c2_transform))) =
if let (
Ok((c1_color, c1_transform, c1_player)),
Ok((c2_color, c2_transform, c2_player))) =
(character_query.get(*e1), character_query.get(*e2))
{
// TODO completely remove particles
@ -210,15 +211,28 @@ fn collision_event_system(
app_state.replace(AppState::Win).ok();
}
spawn_character(
&mut commands,
&character_meshes,
&mut materials,
&audio,
*c1_transform,
new_color.into(),
true,
);
// position character based on current player location
if let Some(_player) = c1_player {
spawn_character(
&mut commands,
&character_meshes,
&mut materials,
&audio,
*c1_transform,
new_color.into(),
true,
);
} else if let Some(_player) = c2_player {
spawn_character(
&mut commands,
&character_meshes,
&mut materials,
&audio,
*c2_transform,
new_color.into(),
true,
);
}
}
}
}
@ -229,7 +243,7 @@ fn change_character_system(
mut commands: Commands,
keyboard_input: Res<Input<KeyCode>>,
characters: Query<(Entity, &Transform, &CharacterColor, Option<&Player>)>,
characters: Query<(Entity, &CharacterColor, Option<&Player>)>,
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
) {
if !keyboard_input.just_pressed(KeyCode::Tab) { return; }
@ -238,7 +252,7 @@ fn change_character_system(
let mut player_count: usize = 0;
// find player idx
for (_entity, _transform, _color, player) in characters.iter() {
for (_entity, _color, player) in characters.iter() {
if let Some(_player) = player {
player_idx = player_count;
}
@ -250,7 +264,7 @@ fn change_character_system(
player_count = 0;
// exchange `Player` component from old `player_idx` to new `next_player_idx`
for (entity, _transform, color, _player) in characters.iter() {
for (entity, color, _player) in characters.iter() {
if player_count == player_idx {
commands.entity(entity).remove::<Player>();
}
@ -260,6 +274,7 @@ fn change_character_system(
audio
.send(AudioMsg::Color([color.0.r(), color.0.g(), color.0.b()]))
.ok();
audio.send(AudioMsg::Jump).ok();
}
player_count += 1;