Despawn black characters

This commit is contained in:
Pascal Engélibert 2022-08-29 13:12:33 +02:00
parent 160e881ba7
commit 14eb48dcf8
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
2 changed files with 23 additions and 5 deletions

View file

@ -2,6 +2,8 @@
[Play in browser](https://txmn.tk/projects/lux-synthese/)
In latin, _lux synthesĕ_ means "light by the means of synthesia".
## Controls
* **Move**: arrows
@ -14,12 +16,10 @@
## TODO
* more filters
* despawn black characters
* despawn character when too far
* more levels
* (?) multiplayer
* more audio
* bug: in level2, move the blue character to win, then reset. The characters are lighter than expected. (also level 4)
* bug: when reset after win, character colors are wrong
* redshift warning
## Build
@ -54,6 +54,8 @@ Skip to level `N: u32` with the command `bevyjam <N>`.
Edit the level `N: u32` with the command `bevyjam <N> e`.
Editor is not available in the WASM build.
### Editor controls
* **Select**: left click to select, click in void to deselect, CTRL+click to select many, CTRL+A to select all

View file

@ -398,6 +398,8 @@ fn collision_event_system(
)>,
pass_through_filter_query: Query<&PassThroughFilter>,
melty_query: Query<&Melty>,
mut character_list: ResMut<CharacterList>,
mut change_character_event: EventWriter<ChangeCharacterEvent>,
) {
for collision_event in collision_events.iter() {
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
@ -416,20 +418,34 @@ fn collision_event_system(
}
}
} else if *flags == CollisionEventFlags::SENSOR {
if let (Ok((mut c_color, _c_transform, mut c_material, _c_player)), Ok(filter)) = (
if let (Ok((mut c_color, _c_transform, mut c_material, c_player)), Ok(filter)) = (
character_query.get_mut(*e1),
pass_through_filter_query.get(*e2),
) {
c_color.0 = filter.apply(c_color.0);
if c_color.0.as_hsla_f32()[2] < 0.1 {
commands.entity(*e1).despawn_recursive();
character_list.0.remove(e1);
if c_player.is_some() {
change_character_event.send(ChangeCharacterEvent);
}
}
*c_material = materials.add(ColorMaterial::from(c_color.0));
} else if let (
Ok((mut c_color, _c_transform, mut c_material, _c_player)),
Ok((mut c_color, _c_transform, mut c_material, c_player)),
Ok(filter),
) = (
character_query.get_mut(*e2),
pass_through_filter_query.get(*e1),
) {
c_color.0 = filter.apply(c_color.0);
if c_color.0.as_hsla_f32()[2] < 0.1 {
commands.entity(*e2).despawn_recursive();
character_list.0.remove(e2);
if c_player.is_some() {
change_character_event.send(ChangeCharacterEvent);
}
}
*c_material = materials.add(ColorMaterial::from(c_color.0));
}
}