Separated goals and walls

This commit is contained in:
2024-11-05 14:31:15 +02:00
parent bd96dab0c1
commit 26d7f3b40a
2 changed files with 45 additions and 0 deletions

35
src/goal.rs Normal file
View File

@@ -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<LevelSelection>,
players: Query<&GridCoords, (With<Player>, Changed<GridCoords>)>,
goals: Query<&GridCoords, With<Goal>>,
) {
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;
}
}

10
src/level_structure.rs Normal file
View File

@@ -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,
}