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