fix: fmt, clippy
This commit is contained in:
parent
0627722906
commit
b70396ab72
3 changed files with 88 additions and 91 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
174
src/game.rs
174
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_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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +286,7 @@ pub fn spawn_melty_platform(
|
||||||
.insert(Collider::cuboid(48., 8.))
|
.insert(Collider::cuboid(48., 8.))
|
||||||
.insert(Melty(color))
|
.insert(Melty(color))
|
||||||
.insert(Level)
|
.insert(Level)
|
||||||
.insert(Platform)
|
.insert(Platform)
|
||||||
.with_children(|c| {
|
.with_children(|c| {
|
||||||
c.spawn_bundle(SpriteBundle {
|
c.spawn_bundle(SpriteBundle {
|
||||||
texture: asset_server.get_handle("melty.png"),
|
texture: asset_server.get_handle("melty.png"),
|
||||||
|
@ -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>,
|
||||||
)>,
|
)>,
|
||||||
|
|
||||||
|
@ -311,18 +313,19 @@ fn char_char_collision_event_system(
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
) {
|
) {
|
||||||
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 {
|
||||||
|
@ -362,36 +365,32 @@ fn char_platform_collision_event_system(
|
||||||
) {
|
) {
|
||||||
// detect platform + player collisions only
|
// detect platform + player collisions only
|
||||||
for collision_event in collision_events.iter() {
|
for collision_event in collision_events.iter() {
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_query.get(*e1))
|
||||||
platform_count_query.get_mut(*e2),
|
{
|
||||||
platform_query.get(*e1),
|
platform_count.decrement();
|
||||||
) {
|
}
|
||||||
platform_count.decrement();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,61 +412,61 @@ fn collision_event_system(
|
||||||
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
audio: Res<crossbeam_channel::Sender<AudioMsg>>,
|
||||||
) {
|
) {
|
||||||
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((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
|
if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
|
||||||
(character_query.get_mut(*e1), melty_query.get(*e2))
|
(character_query.get_mut(*e1), melty_query.get(*e2))
|
||||||
{
|
{
|
||||||
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
|
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
|
||||||
commands.entity(*e2).despawn_recursive();
|
commands.entity(*e2).despawn_recursive();
|
||||||
}
|
}
|
||||||
} else if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
|
} else if let (Ok((c_color, _c_transform, _c_material, _c_player)), Ok(melty)) =
|
||||||
(character_query.get_mut(*e2), melty_query.get(*e1))
|
(character_query.get_mut(*e2), melty_query.get(*e1))
|
||||||
{
|
{
|
||||||
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
|
if (Vec4::from(melty.0) - Vec4::from(c_color.0)).max_element() <= 0. {
|
||||||
commands.entity(*e1).despawn_recursive();
|
commands.entity(*e1).despawn_recursive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if *flags == CollisionEventFlags::SENSOR {
|
} 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),
|
character_query.get_mut(*e1),
|
||||||
pass_through_filter_query.get(*e2),
|
pass_through_filter_query.get(*e2),
|
||||||
) {
|
) {
|
||||||
c_color.0 = filter.apply(c_color.0);
|
c_color.0 = filter.apply(c_color.0);
|
||||||
*c_material = materials.add(ColorMaterial::from(c_color.0));
|
*c_material = materials.add(ColorMaterial::from(c_color.0));
|
||||||
|
|
||||||
if c_player.is_some() {
|
if c_player.is_some() {
|
||||||
audio
|
audio
|
||||||
.send(AudioMsg::Color([
|
.send(AudioMsg::Color([
|
||||||
c_color.0.r(),
|
c_color.0.r(),
|
||||||
c_color.0.g(),
|
c_color.0.g(),
|
||||||
c_color.0.b(),
|
c_color.0.b(),
|
||||||
]))
|
]))
|
||||||
.ok();
|
.ok();
|
||||||
audio.send(AudioMsg::Switch).ok();
|
audio.send(AudioMsg::Switch).ok();
|
||||||
}
|
}
|
||||||
} else if let (
|
} 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),
|
Ok(filter),
|
||||||
) = (
|
) = (
|
||||||
character_query.get_mut(*e2),
|
character_query.get_mut(*e2),
|
||||||
pass_through_filter_query.get(*e1),
|
pass_through_filter_query.get(*e1),
|
||||||
) {
|
) {
|
||||||
c_color.0 = filter.apply(c_color.0);
|
c_color.0 = filter.apply(c_color.0);
|
||||||
*c_material = materials.add(ColorMaterial::from(c_color.0));
|
*c_material = materials.add(ColorMaterial::from(c_color.0));
|
||||||
|
|
||||||
if c_player.is_some() {
|
if c_player.is_some() {
|
||||||
audio
|
audio
|
||||||
.send(AudioMsg::Color([
|
.send(AudioMsg::Color([
|
||||||
c_color.0.r(),
|
c_color.0.r(),
|
||||||
c_color.0.g(),
|
c_color.0.g(),
|
||||||
c_color.0.b(),
|
c_color.0.b(),
|
||||||
]))
|
]))
|
||||||
.ok();
|
.ok();
|
||||||
audio.send(AudioMsg::Switch).ok();
|
audio.send(AudioMsg::Switch).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.;
|
||||||
|
|
|
@ -143,6 +143,6 @@ fn particle_effect_system(
|
||||||
/ particle_effect.radius_squared,
|
/ particle_effect.radius_squared,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
transform.translation.z = 0.005;
|
transform.translation.z = 0.005;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue