Compare commits

..

No commits in common. "55ab83588aebf8ebac451016d322a3e261f8777a" and "683bfa2c999ff1315b556b84524a82d9cde0fbdf" have entirely different histories.

2 changed files with 62 additions and 52 deletions

View file

@ -5,6 +5,7 @@
* name * name
* scene management * scene management
* stream audio (with HexoSynthDSP) * stream audio (with HexoSynthDSP)
* character fusion
* color filters * color filters
* level design * level design
* win * win

View file

@ -1,12 +1,11 @@
#![allow(clippy::precedence)] #![allow(clippy::precedence)]
#![allow(clippy::too_many_arguments)]
use crate::AppState; use crate::AppState;
use bevy::{ use bevy::{
input::{keyboard::KeyCode, Input}, input::{keyboard::KeyCode, Input},
prelude::{shape::Quad, *}, prelude::{shape::Quad, *},
sprite::Mesh2dHandle, sprite::{MaterialMesh2dBundle, Mesh2dHandle},
}; };
use bevy_fundsp::prelude::*; use bevy_fundsp::prelude::*;
use bevy_hanabi::*; use bevy_hanabi::*;
@ -70,9 +69,6 @@ struct SelectedCharacterId(Option<CharacterId>);
#[derive(Component)] #[derive(Component)]
struct CharacterIdList(BTreeSet<CharacterId>); struct CharacterIdList(BTreeSet<CharacterId>);
#[derive(Clone, Component, PartialEq)]
struct CharacterColor(Color);
// Systems // Systems
fn setup( fn setup(
@ -178,21 +174,20 @@ fn spawn_character(
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)), .clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)),
); );
commands commands
.spawn_bundle(ColorMesh2dBundle { .spawn_bundle(MaterialMesh2dBundle {
mesh: character_meshes.square.clone(), mesh: character_meshes.square.clone(),
material: materials.add(ColorMaterial::from(color)), material: materials.add(ColorMaterial::from(color)),
transform, transform,
..default() ..default()
}) })
.insert(character_id) .insert(character_id)
.insert(CharacterColor(color))
.insert(RigidBody::Dynamic) .insert(RigidBody::Dynamic)
.insert(Collider::cuboid(32., 32.)) .insert(Collider::cuboid(32., 32.))
.insert(ExternalForce::default()) .insert(ExternalForce::default())
.insert(Velocity::default()) .insert(Velocity::default())
.insert(GravityScale(10.0)) .insert(GravityScale(10.0))
.insert(LockedAxes::ROTATION_LOCKED) .insert(LockedAxes::ROTATION_LOCKED)
.insert(Friction::new(0.8)) .insert(Friction::new(1.0))
.insert(Damping { .insert(Damping {
linear_damping: 0.5, linear_damping: 0.5,
angular_damping: 0.5, angular_damping: 0.5,
@ -236,43 +231,30 @@ fn spawn_character(
fn collision_event_system( fn collision_event_system(
mut commands: Commands, mut commands: Commands,
character_meshes: Res<CharacterMeshes>, //materials: ResMut<Assets<ColorMaterial>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut effects: ResMut<Assets<EffectAsset>>,
current_level: Res<CurrentLevel>, current_level: Res<CurrentLevel>,
mut collision_events: EventReader<CollisionEvent>, mut collision_events: EventReader<CollisionEvent>,
character_query: Query<(&CharacterId, &CharacterColor, &Transform)>, //character_query: Query<(&CharacterId, &Handle<ColorMaterial>)>,
character_query: Query<&CharacterId>,
mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>, mut level_query: Query<(&mut SelectedCharacterId, &mut CharacterIdList)>,
) { ) {
if let Some(level_entity) = current_level.0 { if let Some(level_entity) = current_level.0 {
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_id, c1_material)), Ok((c2_id, c2_material))) =
Ok((c1_id, c1_color, c1_transform)), if let (Ok(c1_id), Ok(c2_id)) =
Ok((c2_id, c2_color, _c2_transform)), (character_query.get(*e1), character_query.get(*e2))
) = (character_query.get(*e1), character_query.get(*e2))
{ {
//c1_material.color = (Vec4::from(c1_material.color) + Vec4::from(c2_material.color)).into();
let (mut selected_character_id, mut character_id_list) = let (mut selected_character_id, mut character_id_list) =
level_query.get_mut(level_entity).unwrap(); level_query.get_mut(level_entity).unwrap();
character_id_list.0.remove(c1_id);
character_id_list.0.remove(c2_id); character_id_list.0.remove(c2_id);
selected_character_id.0 = None; if selected_character_id.0 == Some(*c2_id) {
selected_character_id.0 = Some(*c1_id);
// TODO completely remove particles }
commands.entity(*e1).despawn_recursive();
commands.entity(*e2).despawn_recursive(); commands.entity(*e2).despawn_recursive();
spawn_character(
&mut commands,
&character_meshes,
&mut effects,
&mut materials,
&mut selected_character_id,
&mut character_id_list,
*c1_transform,
(Vec4::from(c1_color.0) + Vec4::from(c2_color.0)).into(),
);
} }
} }
} }
@ -285,7 +267,7 @@ fn keyboard_input_system(
current_level: Res<CurrentLevel>, current_level: Res<CurrentLevel>,
mut characters: Query<( mut characters: Query<(
&CharacterId, &CharacterId,
&mut Velocity, &mut Velocity,
&mut ExternalImpulse, &mut ExternalImpulse,
&mut ExternalForce, &mut ExternalForce,
&Children, &Children,
@ -303,11 +285,21 @@ fn keyboard_input_system(
audio.play(dsp_assets.graph(&sine_wave)); audio.play(dsp_assets.graph(&sine_wave));
let selected = if let Some(selected_character_id) = &mut selected_character_id.0 { let selected = if let Some(selected_character_id) = &mut selected_character_id.0 {
if let Some((_character_id, _velocity, _impulse, _force, children)) = characters if let Some((
.iter_mut() _character_id,
.find(|(character_id, _velocity, _impulse, _force, _children)| { _velocity,
*character_id == selected_character_id _impulse,
}) { _force,
children
)) = characters.iter_mut().find(|(
character_id,
_velocity,
_impulse,
_force,
_children
)| { *character_id == selected_character_id }) {
effect effect
.get_mut(children[0]) .get_mut(children[0])
.unwrap() .unwrap()
@ -327,11 +319,20 @@ fn keyboard_input_system(
CharacterId(0) CharacterId(0)
}; };
if let Some((_character_id, _velocity, _impulse, _force, children)) = characters if let Some((
.iter_mut() _character_id,
.find(|(character_id, _velocity, _impulse, _force, _children)| { _velocity,
**character_id == selected _impulse,
}) { _force,
children
)) = characters.iter_mut().find(|(
character_id,
_velocity,
_impulse,
_force,
_children
)| **character_id == selected)
{
effect effect
.get_mut(children[0]) .get_mut(children[0])
.unwrap() .unwrap()
@ -341,17 +342,25 @@ fn keyboard_input_system(
} }
} }
let right_pressed: bool = let right_pressed: bool = keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D); let left_pressed: bool = keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
let left_pressed: bool =
keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
if let Some(selected_character_id) = &selected_character_id.0 { if let Some(selected_character_id) = &selected_character_id.0 {
if let Some((_character_id, mut velocity, _impulse, _force, _children)) = characters if let Some((
.iter_mut() _character_id,
.find(|(character_id, _velocity, _impulse, _force, _children)| { mut velocity,
*character_id == selected_character_id mut impulse,
}) { mut force,
_children
)) = characters.iter_mut().find(|(
character_id,
_velocity,
_impulse,
_force,
_children
)| { *character_id == selected_character_id }) {
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32; velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
if keyboard_input.just_pressed(KeyCode::Space) { if keyboard_input.just_pressed(KeyCode::Space) {