Compare commits
2 commits
683bfa2c99
...
55ab83588a
Author | SHA1 | Date | |
---|---|---|---|
55ab83588a | |||
a735ae7713 |
2 changed files with 52 additions and 62 deletions
|
@ -5,7 +5,6 @@
|
||||||
* 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
|
||||||
|
|
111
src/game.rs
111
src/game.rs
|
@ -1,11 +1,12 @@
|
||||||
#![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::{MaterialMesh2dBundle, Mesh2dHandle},
|
sprite::Mesh2dHandle,
|
||||||
};
|
};
|
||||||
use bevy_fundsp::prelude::*;
|
use bevy_fundsp::prelude::*;
|
||||||
use bevy_hanabi::*;
|
use bevy_hanabi::*;
|
||||||
|
@ -69,6 +70,9 @@ 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(
|
||||||
|
@ -174,20 +178,21 @@ 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(MaterialMesh2dBundle {
|
.spawn_bundle(ColorMesh2dBundle {
|
||||||
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(1.0))
|
.insert(Friction::new(0.8))
|
||||||
.insert(Damping {
|
.insert(Damping {
|
||||||
linear_damping: 0.5,
|
linear_damping: 0.5,
|
||||||
angular_damping: 0.5,
|
angular_damping: 0.5,
|
||||||
|
@ -231,30 +236,43 @@ fn spawn_character(
|
||||||
|
|
||||||
fn collision_event_system(
|
fn collision_event_system(
|
||||||
mut commands: Commands,
|
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>,
|
current_level: Res<CurrentLevel>,
|
||||||
mut collision_events: EventReader<CollisionEvent>,
|
mut collision_events: EventReader<CollisionEvent>,
|
||||||
//character_query: Query<(&CharacterId, &Handle<ColorMaterial>)>,
|
character_query: Query<(&CharacterId, &CharacterColor, &Transform)>,
|
||||||
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 (Ok((c1_id, c1_material)), Ok((c2_id, c2_material))) =
|
if let (
|
||||||
if let (Ok(c1_id), Ok(c2_id)) =
|
Ok((c1_id, c1_color, c1_transform)),
|
||||||
(character_query.get(*e1), character_query.get(*e2))
|
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) =
|
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);
|
||||||
if selected_character_id.0 == Some(*c2_id) {
|
selected_character_id.0 = None;
|
||||||
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,21 +303,11 @@ 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((
|
if let Some((_character_id, _velocity, _impulse, _force, children)) = characters
|
||||||
_character_id,
|
.iter_mut()
|
||||||
_velocity,
|
.find(|(character_id, _velocity, _impulse, _force, _children)| {
|
||||||
_impulse,
|
*character_id == selected_character_id
|
||||||
_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()
|
||||||
|
@ -319,20 +327,11 @@ fn keyboard_input_system(
|
||||||
CharacterId(0)
|
CharacterId(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((
|
if let Some((_character_id, _velocity, _impulse, _force, children)) = characters
|
||||||
_character_id,
|
.iter_mut()
|
||||||
_velocity,
|
.find(|(character_id, _velocity, _impulse, _force, _children)| {
|
||||||
_impulse,
|
**character_id == selected
|
||||||
_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()
|
||||||
|
@ -342,25 +341,17 @@ fn keyboard_input_system(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let right_pressed: bool = keyboard_input.pressed(KeyCode::Right) || keyboard_input.pressed(KeyCode::D);
|
let right_pressed: bool =
|
||||||
let left_pressed: bool = keyboard_input.pressed(KeyCode::Left) || keyboard_input.pressed(KeyCode::A);
|
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(selected_character_id) = &selected_character_id.0 {
|
||||||
if let Some((
|
if let Some((_character_id, mut velocity, _impulse, _force, _children)) = characters
|
||||||
_character_id,
|
.iter_mut()
|
||||||
mut velocity,
|
.find(|(character_id, _velocity, _impulse, _force, _children)| {
|
||||||
mut impulse,
|
*character_id == selected_character_id
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in a new issue