fix: fmt, clippy

This commit is contained in:
Pascal Engélibert 2022-08-27 19:24:31 +02:00
parent 0627722906
commit b70396ab72
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
3 changed files with 88 additions and 91 deletions

View file

@ -9,17 +9,14 @@
## TODO
* name
* more filters
* despawn black characters
* despawn character when too far
* more levels
* (?) multiplayer
* more audio
* "jumpable" component to avoid jumping on sensors
* bug: in level2, move the blue character to win, then reset. The characters are lighter than expected. (also level 4)
* redshift warning
* itchio test
## Build

View file

@ -60,7 +60,10 @@ impl Plugin for GamePlugin {
.add_system_to_stage(CoreStage::PostUpdate, char_char_collision_event_system)
.add_system_to_stage(CoreStage::PostUpdate, char_platform_collision_event_system)
// collision event system might remove items, therefore, we should detect platforms first before removing them
.add_system_to_stage(CoreStage::PostUpdate, collision_event_system.after(char_platform_collision_event_system));
.add_system_to_stage(
CoreStage::PostUpdate,
collision_event_system.after(char_platform_collision_event_system),
);
}
}
@ -124,7 +127,7 @@ impl PlatformCount {
}
fn is_landed(&self) -> bool {
return self.0 != 0;
self.0 != 0
}
}
@ -283,7 +286,7 @@ pub fn spawn_melty_platform(
.insert(Collider::cuboid(48., 8.))
.insert(Melty(color))
.insert(Level)
.insert(Platform)
.insert(Platform)
.with_children(|c| {
c.spawn_bundle(SpriteBundle {
texture: asset_server.get_handle("melty.png"),
@ -298,9 +301,8 @@ fn char_char_collision_event_system(
mut collision_events: EventReader<CollisionEvent>,
character_query: Query<(
&mut CharacterColor,
&CharacterColor,
&Transform,
&mut Handle<ColorMaterial>,
Option<&Player>,
)>,
@ -311,18 +313,19 @@ fn char_char_collision_event_system(
mut materials: ResMut<Assets<ColorMaterial>>,
) {
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 let (
Ok((c1_color, c1_transform, _c1_material, c1_player)),
Ok((c2_color, c2_transform, _c2_material, c2_player)),
) = (character_query.get(*e1), character_query.get(*e2)) {
Ok((c1_color, c1_transform, c1_player)),
Ok((c2_color, c2_transform, c2_player)),
) = (character_query.get(*e1), character_query.get(*e2))
{
character_list.0.remove(e1);
character_list.0.remove(e2);
commands.entity(*e1).despawn_recursive();
commands.entity(*e2).despawn_recursive();
let new_color = (Vec4::from(c1_color.0) + Vec4::from(c2_color.0))
.clamp(Vec4::ZERO, Vec4::ONE);
let new_color =
(Vec4::from(c1_color.0) + Vec4::from(c2_color.0)).clamp(Vec4::ZERO, Vec4::ONE);
// If color approximately white
if app_state.current() == &AppState::Game && new_color.min_element() >= 0.9 {
@ -362,36 +365,32 @@ fn char_platform_collision_event_system(
) {
// detect platform + player collisions only
for collision_event in collision_events.iter() {
match collision_event {
match collision_event {
CollisionEvent::Started(e1, e2, flags) => {
if *flags == CollisionEventFlags::SENSOR {
if let (Ok(mut platform_count), Ok(_)) = (
platform_count_query.get_mut(*e1),
platform_query.get(*e2),
) {
if let (Ok(mut platform_count), Ok(_)) =
(platform_count_query.get_mut(*e1), platform_query.get(*e2))
{
platform_count.increment();
} else if let (Ok(mut platform_count), Ok(_)) = (
platform_count_query.get_mut(*e2),
platform_query.get(*e1),
) {
} else if let (Ok(mut platform_count), Ok(_)) =
(platform_count_query.get_mut(*e2), platform_query.get(*e1))
{
platform_count.increment();
}
}
}
}
CollisionEvent::Stopped(e1, e2, flags) => {
if *flags == CollisionEventFlags::SENSOR {
if let (Ok(mut platform_count), Ok(_)) = (
platform_count_query.get_mut(*e1),
platform_query.get(*e2),
) {
platform_count.decrement();
} else if let (Ok(mut platform_count), Ok(_)) = (
platform_count_query.get_mut(*e2),
platform_query.get(*e1),
) {
platform_count.decrement();
}
if let (Ok(mut platform_count), Ok(_)) =
(platform_count_query.get_mut(*e1), platform_query.get(*e2))
{
platform_count.decrement();
} else if let (Ok(mut platform_count), Ok(_)) =
(platform_count_query.get_mut(*e2), platform_query.get(*e1))
{
platform_count.decrement();
}
}
}
}
@ -413,61 +412,61 @@ fn collision_event_system(
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
) {
for collision_event in collision_events.iter() {
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
if flags.is_empty() {
if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
(character_query.get_mut(*e1), melty_query.get(*e2))
{
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
commands.entity(*e2).despawn_recursive();
}
} else if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
(character_query.get_mut(*e2), melty_query.get(*e1))
{
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
commands.entity(*e1).despawn_recursive();
}
}
} else if *flags == CollisionEventFlags::SENSOR {
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);
*c_material = materials.add(ColorMaterial::from(c_color.0));
if let CollisionEvent::Started(e1, e2, flags) = collision_event {
if flags.is_empty() {
if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
(character_query.get_mut(*e1), melty_query.get(*e2))
{
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
commands.entity(*e2).despawn_recursive();
}
} else if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
(character_query.get_mut(*e2), melty_query.get(*e1))
{
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
commands.entity(*e1).despawn_recursive();
}
}
} else if *flags == CollisionEventFlags::SENSOR {
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);
*c_material = materials.add(ColorMaterial::from(c_color.0));
if c_player.is_some() {
audio
.send(AudioMsg::Color([
c_color.0.r(),
c_color.0.g(),
c_color.0.b(),
]))
.ok();
audio.send(AudioMsg::Switch).ok();
}
} else if let (
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);
*c_material = materials.add(ColorMaterial::from(c_color.0));
if c_player.is_some() {
audio
.send(AudioMsg::Color([
c_color.0.r(),
c_color.0.g(),
c_color.0.b(),
]))
.ok();
audio.send(AudioMsg::Switch).ok();
}
} else if let (
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);
*c_material = materials.add(ColorMaterial::from(c_color.0));
if c_player.is_some() {
audio
.send(AudioMsg::Color([
c_color.0.r(),
c_color.0.g(),
c_color.0.b(),
]))
.ok();
audio.send(AudioMsg::Switch).ok();
}
}
}
if c_player.is_some() {
audio
.send(AudioMsg::Color([
c_color.0.r(),
c_color.0.g(),
c_color.0.b(),
]))
.ok();
audio.send(AudioMsg::Switch).ok();
}
}
}
}
}
}
@ -521,7 +520,8 @@ fn player_movement_system(
for (mut velocity, children) in characters.iter_mut() {
velocity.linvel.x = 200. * (right_pressed as i8 - left_pressed as i8) as f32;
let mut platform_count: Mut<PlatformCount> = platform_count_query.get_mut(children[0]).unwrap();
let mut platform_count: Mut<PlatformCount> =
platform_count_query.get_mut(children[0]).unwrap();
if keyboard_input.just_pressed(KeyCode::Space) && platform_count.is_landed() {
audio.send(AudioMsg::Jump).ok();
velocity.linvel.y = 700.;

View file

@ -143,6 +143,6 @@ fn particle_effect_system(
/ particle_effect.radius_squared,
);
}
transform.translation.z = 0.005;
transform.translation.z = 0.005;
}
}