References and crates and stuffs
This commit is contained in:
48
src/main.rs
48
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<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(
|
||||
mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed<GridCoords>>,
|
||||
) {
|
||||
@@ -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<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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user