Compare commits

..

2 commits

Author SHA1 Message Date
160e881ba7
fix: allow negative values for rotating filter 2022-08-29 09:54:36 +02:00
da1a8351ff
Remove lost characters 2022-08-29 09:53:50 +02:00
2 changed files with 28 additions and 3 deletions

View file

@ -23,6 +23,10 @@ impl PassThroughFilter {
PassThroughFilter::Rotating(filter_angle) => { PassThroughFilter::Rotating(filter_angle) => {
let mut hsla = color.as_hsla_f32(); let mut hsla = color.as_hsla_f32();
hsla[0] = (hsla[0] + filter_angle) % 360.; hsla[0] = (hsla[0] + filter_angle) % 360.;
// floating rem is not modulo!
if hsla[0] < 0. {
hsla[0] += 360.;
}
Color::hsla(hsla[0], hsla[1], hsla[2], hsla[3]) Color::hsla(hsla[0], hsla[1], hsla[2], hsla[3])
} }
} }

View file

@ -25,6 +25,7 @@ pub struct GamePlugin;
impl Plugin for GamePlugin { impl Plugin for GamePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<LevelStartupEvent>() app.add_event::<LevelStartupEvent>()
.add_event::<ChangeCharacterEvent>()
.init_resource::<CharacterMeshes>() .init_resource::<CharacterMeshes>()
.insert_resource(CurrentLevel(None)) .insert_resource(CurrentLevel(None))
.init_resource::<CharacterList>() .init_resource::<CharacterList>()
@ -41,7 +42,8 @@ impl Plugin for GamePlugin {
.with_system(player_movement_system) .with_system(player_movement_system)
.with_system(level_keyboard_system) .with_system(level_keyboard_system)
.with_system(camera_system) .with_system(camera_system)
.with_system(character_particle_effect_system), .with_system(character_particle_effect_system)
.with_system(kill_character_system),
) )
.add_system_set( .add_system_set(
SystemSet::on_update(AppState::Win) SystemSet::on_update(AppState::Win)
@ -65,6 +67,8 @@ impl Plugin for GamePlugin {
pub struct LevelStartupEvent; pub struct LevelStartupEvent;
pub struct ChangeCharacterEvent;
// Resources // Resources
pub struct CurrentLevel(pub Option<LevelId>); pub struct CurrentLevel(pub Option<LevelId>);
@ -435,14 +439,14 @@ fn collision_event_system(
fn change_character_system( fn change_character_system(
mut commands: Commands, mut commands: Commands,
keyboard_input: Res<Input<KeyCode>>, keyboard_input: Res<Input<KeyCode>>,
characters: Query<(Entity, &CharacterColor, Option<&Player>)>, characters: Query<(Entity, &CharacterColor, Option<&Player>)>,
character_list: Res<CharacterList>, character_list: Res<CharacterList>,
audio_assets: Res<audio_system::AudioAssets>, audio_assets: Res<audio_system::AudioAssets>,
audio: Res<Audio>, audio: Res<Audio>,
change_character_event: EventReader<ChangeCharacterEvent>,
) { ) {
if !keyboard_input.just_pressed(KeyCode::Tab) { if !keyboard_input.just_pressed(KeyCode::Tab) && change_character_event.is_empty() {
return; return;
} }
@ -623,3 +627,20 @@ fn level_keyboard_system(
} }
} }
} }
fn kill_character_system(
mut commands: Commands,
character_query: Query<(Entity, &Transform, Option<&Player>), With<CharacterColor>>,
mut character_list: ResMut<CharacterList>,
mut change_character_event: EventWriter<ChangeCharacterEvent>,
) {
for (entity, transform, player) in character_query.iter() {
if transform.translation.y < -512. {
commands.entity(entity).despawn_recursive();
character_list.0.remove(&entity);
if player.is_some() {
change_character_event.send(ChangeCharacterEvent);
}
}
}
}