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
* scene management
* stream audio (with HexoSynthDSP)
* character fusion
* color filters
* level design
* win

View file

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