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 ## TODO
* name
* more filters * more filters
* despawn black characters * despawn black characters
* despawn character when too far * despawn character when too far
* more levels * more levels
* (?) multiplayer * (?) multiplayer
* more audio * 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) * bug: in level2, move the blue character to win, then reset. The characters are lighter than expected. (also level 4)
* redshift warning * redshift warning
* itchio test
## Build ## 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_char_collision_event_system)
.add_system_to_stage(CoreStage::PostUpdate, char_platform_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 // 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 { fn is_landed(&self) -> bool {
return self.0 != 0; self.0 != 0
} }
} }
@ -298,9 +301,8 @@ fn char_char_collision_event_system(
mut collision_events: EventReader<CollisionEvent>, mut collision_events: EventReader<CollisionEvent>,
character_query: Query<( character_query: Query<(
&mut CharacterColor, &CharacterColor,
&Transform, &Transform,
&mut Handle<ColorMaterial>,
Option<&Player>, Option<&Player>,
)>, )>,
@ -313,16 +315,17 @@ fn char_char_collision_event_system(
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 let ( if let (
Ok((c1_color, c1_transform, _c1_material, c1_player)), Ok((c1_color, c1_transform, c1_player)),
Ok((c2_color, c2_transform, _c2_material, c2_player)), Ok((c2_color, c2_transform, c2_player)),
) = (character_query.get(*e1), character_query.get(*e2)) { ) = (character_query.get(*e1), character_query.get(*e2))
{
character_list.0.remove(e1); character_list.0.remove(e1);
character_list.0.remove(e2); character_list.0.remove(e2);
commands.entity(*e1).despawn_recursive(); commands.entity(*e1).despawn_recursive();
commands.entity(*e2).despawn_recursive(); commands.entity(*e2).despawn_recursive();
let new_color = (Vec4::from(c1_color.0) + Vec4::from(c2_color.0)) let new_color =
.clamp(Vec4::ZERO, Vec4::ONE); (Vec4::from(c1_color.0) + Vec4::from(c2_color.0)).clamp(Vec4::ZERO, Vec4::ONE);
// If color approximately white // If color approximately white
if app_state.current() == &AppState::Game && new_color.min_element() >= 0.9 { if app_state.current() == &AppState::Game && new_color.min_element() >= 0.9 {
@ -365,15 +368,13 @@ fn char_platform_collision_event_system(
match collision_event { match collision_event {
CollisionEvent::Started(e1, e2, flags) => { CollisionEvent::Started(e1, e2, flags) => {
if *flags == CollisionEventFlags::SENSOR { if *flags == CollisionEventFlags::SENSOR {
if let (Ok(mut platform_count), Ok(_)) = ( if let (Ok(mut platform_count), Ok(_)) =
platform_count_query.get_mut(*e1), (platform_count_query.get_mut(*e1), platform_query.get(*e2))
platform_query.get(*e2), {
) {
platform_count.increment(); platform_count.increment();
} else if let (Ok(mut platform_count), Ok(_)) = ( } else if let (Ok(mut platform_count), Ok(_)) =
platform_count_query.get_mut(*e2), (platform_count_query.get_mut(*e2), platform_query.get(*e1))
platform_query.get(*e1), {
) {
platform_count.increment(); platform_count.increment();
} }
} }
@ -381,15 +382,13 @@ fn char_platform_collision_event_system(
CollisionEvent::Stopped(e1, e2, flags) => { CollisionEvent::Stopped(e1, e2, flags) => {
if *flags == CollisionEventFlags::SENSOR { if *flags == CollisionEventFlags::SENSOR {
if let (Ok(mut platform_count), Ok(_)) = ( if let (Ok(mut platform_count), Ok(_)) =
platform_count_query.get_mut(*e1), (platform_count_query.get_mut(*e1), platform_query.get(*e2))
platform_query.get(*e2), {
) {
platform_count.decrement(); platform_count.decrement();
} else if let (Ok(mut platform_count), Ok(_)) = ( } else if let (Ok(mut platform_count), Ok(_)) =
platform_count_query.get_mut(*e2), (platform_count_query.get_mut(*e2), platform_query.get(*e1))
platform_query.get(*e1), {
) {
platform_count.decrement(); platform_count.decrement();
} }
} }
@ -521,7 +520,8 @@ fn player_movement_system(
for (mut velocity, children) in characters.iter_mut() { for (mut velocity, children) in characters.iter_mut() {
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;
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() { if keyboard_input.just_pressed(KeyCode::Space) && platform_count.is_landed() {
audio.send(AudioMsg::Jump).ok(); audio.send(AudioMsg::Jump).ok();
velocity.linvel.y = 700.; velocity.linvel.y = 700.;