diff --git a/src/main.rs b/src/main.rs index a97b4ad..552d8bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,17 @@ use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; use camera::CameraPlugin; use logging::log_positions; -use player::{Player, PlayerPlugin}; +use player::PlayerPlugin; +use goal::{GoalBundle, check_goal}; +use level_structure::WallBundle; mod camera; mod logging; mod player; +mod goal; +mod level_structure; + +pub const GRID_SIZE: i32 = 16; fn main() { App::new() @@ -30,19 +36,6 @@ fn setup(mut commands: Commands, asset_server: Res) { }); } -#[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( mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed>, ) { @@ -52,30 +45,3 @@ fn translate_grid_coords_entities( .extend(transform.translation.z); } } - -#[derive(Default, Component)] -struct Wall; - -#[derive(Default, Bundle, LdtkIntCell)] -struct WallBundle { - wall: Wall, -} - -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; - } -} diff --git a/src/player.rs b/src/player.rs index bc7e56a..6d696f0 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,7 +1,7 @@ use bevy::{prelude::*, utils::HashSet}; use bevy_ecs_ldtk::prelude::*; -use crate::{Wall, GRID_SIZE}; +use crate::level_structure::Wall; #[derive(Default, Component)] pub(crate) struct Player; @@ -86,8 +86,8 @@ fn cache_wall_locations( let new_level_walls = LevelWalls { wall_locations, - level_width: level.px_wid / GRID_SIZE, - level_height: level.px_hei / GRID_SIZE, + level_width: level.px_wid / crate::GRID_SIZE, + level_height: level.px_hei / crate::GRID_SIZE, }; *level_walls = new_level_walls;