game states cleanup

This commit is contained in:
2026-09-19 11:07:34 +02:00
parent d42f5af75f
commit 9127d9bb1c
4 changed files with 10 additions and 32 deletions
+1 -10
View File
@@ -12,19 +12,11 @@ pub struct Collider {
pub size: Vec2,
}
#[derive(Resource, Default)]
pub struct HasCollided(pub bool);
// Check collision with Player
pub fn check_collision_with_player(
player: Single<(&Transform, &Collider, &mut Sprite), With<Player>>,
obstacle: Query<(&Transform, &Collider), With<Obstacle>>,
mut has_collided: ResMut<HasCollided>,
) {
if has_collided.0 {
return;
}
let (player_transform, player_collider, mut _player_sprite) = player.into_inner();
// Check whether or not each obstacles overlap the player
@@ -36,7 +28,6 @@ pub fn check_collision_with_player(
collider_collider.size / 2.0,
) {
// player_sprite.color = Color::srgb(1.0, 0.0, 0.0); // Change sprite color
has_collided.0 = true;
break;
}
}
@@ -53,7 +44,7 @@ pub struct CollisionPlugin;
impl Plugin for CollisionPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<HasCollided>().add_systems(
app.add_systems(
Update,
check_collision_with_player
.run_if(in_state(GameState::InGame))