Character fusion
This commit is contained in:
parent
a735ae7713
commit
55ab83588a
2 changed files with 35 additions and 20 deletions
|
@ -5,7 +5,6 @@
|
|||
* name
|
||||
* scene management
|
||||
* stream audio (with HexoSynthDSP)
|
||||
* character fusion
|
||||
* color filters
|
||||
* level design
|
||||
* win
|
||||
|
|
52
src/game.rs
52
src/game.rs
|
@ -6,7 +6,7 @@ use crate::AppState;
|
|||
use bevy::{
|
||||
input::{keyboard::KeyCode, Input},
|
||||
prelude::{shape::Quad, *},
|
||||
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||
sprite::Mesh2dHandle,
|
||||
};
|
||||
use bevy_fundsp::prelude::*;
|
||||
use bevy_hanabi::*;
|
||||
|
@ -70,6 +70,9 @@ struct SelectedCharacterId(Option<CharacterId>);
|
|||
#[derive(Component)]
|
||||
struct CharacterIdList(BTreeSet<CharacterId>);
|
||||
|
||||
#[derive(Clone, Component, PartialEq)]
|
||||
struct CharacterColor(Color);
|
||||
|
||||
// Systems
|
||||
|
||||
fn setup(
|
||||
|
@ -175,13 +178,14 @@ fn spawn_character(
|
|||
.clamp(Vec4::new(0., 0., 0., 0.), Vec4::new(1., 1., 1., 0.)),
|
||||
);
|
||||
commands
|
||||
.spawn_bundle(MaterialMesh2dBundle {
|
||||
.spawn_bundle(ColorMesh2dBundle {
|
||||
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())
|
||||
|
@ -232,30 +236,43 @@ fn spawn_character(
|
|||
|
||||
fn collision_event_system(
|
||||
mut commands: Commands,
|
||||
//materials: ResMut<Assets<ColorMaterial>>,
|
||||
character_meshes: Res<CharacterMeshes>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
mut effects: ResMut<Assets<EffectAsset>>,
|
||||
current_level: Res<CurrentLevel>,
|
||||
mut collision_events: EventReader<CollisionEvent>,
|
||||
//character_query: Query<(&CharacterId, &Handle<ColorMaterial>)>,
|
||||
character_query: Query<&CharacterId>,
|
||||
character_query: Query<(&CharacterId, &CharacterColor, &Transform)>,
|
||||
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_material)), Ok((c2_id, c2_material))) =
|
||||
if let (Ok(c1_id), Ok(c2_id)) =
|
||||
(character_query.get(*e1), character_query.get(*e2))
|
||||
if let (
|
||||
Ok((c1_id, c1_color, c1_transform)),
|
||||
Ok((c2_id, c2_color, _c2_transform)),
|
||||
) = (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);
|
||||
if selected_character_id.0 == Some(*c2_id) {
|
||||
selected_character_id.0 = Some(*c1_id);
|
||||
}
|
||||
selected_character_id.0 = None;
|
||||
|
||||
// TODO completely remove particles
|
||||
commands.entity(*e1).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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -330,12 +347,11 @@ fn keyboard_input_system(
|
|||
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)| {
|
||||
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
|
||||
},
|
||||
) {
|
||||
}) {
|
||||
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
|
||||
|
||||
if keyboard_input.just_pressed(KeyCode::Space) {
|
||||
|
|
Loading…
Reference in a new issue