Separated goals and walls
This commit is contained in:
35
src/goal.rs
Normal file
35
src/goal.rs
Normal 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
10
src/level_structure.rs
Normal 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,
|
||||
}
|
||||
Reference in New Issue
Block a user