From 26d7f3b40a198bfa18d07e65c2c3a8034896f57d Mon Sep 17 00:00:00 2001 From: Supermjork Date: Tue, 5 Nov 2024 14:31:15 +0200 Subject: [PATCH] Separated goals and walls --- src/goal.rs | 35 +++++++++++++++++++++++++++++++++++ src/level_structure.rs | 10 ++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/goal.rs create mode 100644 src/level_structure.rs diff --git a/src/goal.rs b/src/goal.rs new file mode 100644 index 0000000..fc4d7ef --- /dev/null +++ b/src/goal.rs @@ -0,0 +1,35 @@ +use bevy::prelude::*; +use bevy_ecs_ldtk::prelude::*; + +use crate::player::Player; + +#[derive(Default, Component)] +pub struct Goal; + +#[derive(Default, Bundle, LdtkEntity)] +pub struct GoalBundle { + goal: Goal, + #[sprite_sheet_bundle] + sprite_sheet_bundle: LdtkSpriteSheetBundle, + #[grid_coords] + grid_coords: GridCoords, +} + +pub fn check_goal( + level_selection: ResMut, + players: Query<&GridCoords, (With, Changed)>, + goals: Query<&GridCoords, With>, +) { + if players + .iter() + .zip(goals.iter()) + .any(|(player_grid_coords, goal_grid_coords)| player_grid_coords == goal_grid_coords) + { + let indices = match level_selection.into_inner() { + LevelSelection::Indices(indices) => indices, + _ => panic!("level selection should always be Indices in this game"), + }; + + indices.level += 1; + } +} \ No newline at end of file diff --git a/src/level_structure.rs b/src/level_structure.rs new file mode 100644 index 0000000..9a4fba2 --- /dev/null +++ b/src/level_structure.rs @@ -0,0 +1,10 @@ +use bevy::prelude::*; +use bevy_ecs_ldtk::prelude::*; + +#[derive(Default, Component)] +pub struct Wall; + +#[derive(Default, Bundle, LdtkIntCell)] +pub struct WallBundle { + wall: Wall, +}