|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#![feature(try_blocks)]
|
|
|
|
|
|
|
|
|
|
// Bevy basically forces "complex types" with Querys
|
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
|
|
|
|
|
@ -82,6 +83,9 @@ fn main() {
|
|
|
|
|
assert_grid_position_uniqueness.run_if(any_component_changed::<GridPosition>),
|
|
|
|
|
sync_health
|
|
|
|
|
.run_if(any_component_changed::<Health>.or(any_component_added::<Health>)),
|
|
|
|
|
damage_on_place_shape.run_if(any_component_removed::<Shape>),
|
|
|
|
|
damage_on_clear_line.run_if(any_component_removed::<LineBlock>),
|
|
|
|
|
damage_over_time.run_if(clock_cycle(5.0))
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
// UI systems
|
|
|
|
|
@ -94,6 +98,7 @@ fn main() {
|
|
|
|
|
sync_singleton_to_ui::<Shape>.run_if(any_component_changed::<Shape>),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_observer(deal_damage)
|
|
|
|
|
.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -972,11 +977,11 @@ fn clear_line(
|
|
|
|
|
if cleared_lines.contains(&l.0) {
|
|
|
|
|
// Move to the N-offset line number (top, top-1, etc)
|
|
|
|
|
let offset = original_cleared_lines_len - cleared_lines.len();
|
|
|
|
|
info!("Moving line {:?}->{:?}", l.0, Y_MAX - 1 - offset);
|
|
|
|
|
debug!("Moving line {:?}->{:?}", l.0, Y_MAX - 1 - offset);
|
|
|
|
|
l.0 = Y_MAX - 1 - offset;
|
|
|
|
|
cleared_lines.pop();
|
|
|
|
|
} else {
|
|
|
|
|
info!("Moving line {:?}->{:?}", l.0, l.0 - cleared_lines.len());
|
|
|
|
|
debug!("Moving line {:?}->{:?}", l.0, l.0 - cleared_lines.len());
|
|
|
|
|
l.0 -= cleared_lines.len();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -1128,7 +1133,6 @@ fn deactivate_shape(
|
|
|
|
|
parent: Query<&ShapeBlocks>,
|
|
|
|
|
lines: Query<(Entity, &Line), With<LineBlocks>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
mut enemy_health: Single<&mut Health, With<Enemy>>
|
|
|
|
|
) {
|
|
|
|
|
events.read().for_each(|target| {
|
|
|
|
|
parent.iter_descendants(target).for_each(|block| {
|
|
|
|
|
@ -1145,9 +1149,6 @@ fn deactivate_shape(
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
commands.entity(target).despawn();
|
|
|
|
|
|
|
|
|
|
// TODO: Turn this into an event
|
|
|
|
|
enemy_health.0 -= 1.0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1207,3 +1208,46 @@ fn sync_health(
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Event)]
|
|
|
|
|
struct Damage {
|
|
|
|
|
quantity: f32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn deal_damage(
|
|
|
|
|
trigger: Trigger<Damage>,
|
|
|
|
|
mut healths: Query<&mut Health>
|
|
|
|
|
) {
|
|
|
|
|
healths.get_mut(trigger.target()).unwrap().0 -= trigger.event().quantity
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn damage_on_place_shape(
|
|
|
|
|
mut events: RemovedComponents<Shape>,
|
|
|
|
|
enemies: Query<Entity, With<Enemy>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
events.read().for_each(|_| {
|
|
|
|
|
enemies.iter().for_each(|e| {
|
|
|
|
|
commands.entity(e).trigger(Damage { quantity: 1.0 });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn damage_on_clear_line(
|
|
|
|
|
mut events: RemovedComponents<LineBlock>,
|
|
|
|
|
enemies: Query<Entity, With<Enemy>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
events.read().for_each(|_| {
|
|
|
|
|
enemies.iter().for_each(|e| {
|
|
|
|
|
commands.entity(e).trigger(Damage { quantity: 1.0 });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn damage_over_time(
|
|
|
|
|
protagonist: Single<Entity, With<Protagonist>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
commands.entity(*protagonist).trigger(Damage { quantity: 1.0 });
|
|
|
|
|
}
|
|
|
|
|
|