References and crates and stuffs

This commit is contained in:
2024-11-05 14:31:39 +02:00
parent 26d7f3b40a
commit 8686f0872a
2 changed files with 10 additions and 44 deletions

View File

@@ -2,11 +2,17 @@ use bevy::prelude::*;
use bevy_ecs_ldtk::prelude::*; use bevy_ecs_ldtk::prelude::*;
use camera::CameraPlugin; use camera::CameraPlugin;
use logging::log_positions; use logging::log_positions;
use player::{Player, PlayerPlugin}; use player::PlayerPlugin;
use goal::{GoalBundle, check_goal};
use level_structure::WallBundle;
mod camera; mod camera;
mod logging; mod logging;
mod player; mod player;
mod goal;
mod level_structure;
pub const GRID_SIZE: i32 = 16;
fn main() { fn main() {
App::new() App::new()
@@ -30,19 +36,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
}); });
} }
#[derive(Default, Component)]
struct Goal;
#[derive(Default, Bundle, LdtkEntity)]
struct GoalBundle {
goal: Goal,
#[sprite_sheet_bundle]
sprite_sheet_bundle: LdtkSpriteSheetBundle,
#[grid_coords]
grid_coords: GridCoords,
}
pub const GRID_SIZE: i32 = 16;
fn translate_grid_coords_entities( fn translate_grid_coords_entities(
mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed<GridCoords>>, mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed<GridCoords>>,
) { ) {
@@ -52,30 +45,3 @@ fn translate_grid_coords_entities(
.extend(transform.translation.z); .extend(transform.translation.z);
} }
} }
#[derive(Default, Component)]
struct Wall;
#[derive(Default, Bundle, LdtkIntCell)]
struct WallBundle {
wall: Wall,
}
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;
}
}

View File

@@ -1,7 +1,7 @@
use bevy::{prelude::*, utils::HashSet}; use bevy::{prelude::*, utils::HashSet};
use bevy_ecs_ldtk::prelude::*; use bevy_ecs_ldtk::prelude::*;
use crate::{Wall, GRID_SIZE}; use crate::level_structure::Wall;
#[derive(Default, Component)] #[derive(Default, Component)]
pub(crate) struct Player; pub(crate) struct Player;
@@ -86,8 +86,8 @@ fn cache_wall_locations(
let new_level_walls = LevelWalls { let new_level_walls = LevelWalls {
wall_locations, wall_locations,
level_width: level.px_wid / GRID_SIZE, level_width: level.px_wid / crate::GRID_SIZE,
level_height: level.px_hei / GRID_SIZE, level_height: level.px_hei / crate::GRID_SIZE,
}; };
*level_walls = new_level_walls; *level_walls = new_level_walls;