From b70396ab720422b6f9f7ab5be2e63ebd4bf3d7c2 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Sat, 27 Aug 2022 19:24:31 +0200 Subject: [PATCH] fix: fmt, clippy --- README.md | 3 - src/game.rs | 174 ++++++++++++++++++++--------------------- src/particle_effect.rs | 2 +- 3 files changed, 88 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index cf1337b..d46aca3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/game.rs b/src/game.rs index 9fc323d..0816bfa 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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, character_query: Query<( - &mut CharacterColor, + &CharacterColor, &Transform, - &mut Handle, Option<&Player>, )>, @@ -311,18 +313,19 @@ fn char_char_collision_event_system( mut materials: ResMut>, ) { 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>, ) { 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 = platform_count_query.get_mut(children[0]).unwrap(); + let mut platform_count: Mut = + 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.; diff --git a/src/particle_effect.rs b/src/particle_effect.rs index 4912d46..146ac73 100644 --- a/src/particle_effect.rs +++ b/src/particle_effect.rs @@ -143,6 +143,6 @@ fn particle_effect_system( / particle_effect.radius_squared, ); } - transform.translation.z = 0.005; + transform.translation.z = 0.005; } }