changeable z index, with occlusion

This commit is contained in:
StephenAdamson
2024-12-17 21:30:46 +00:00
parent caacf4e072
commit d107626b32
4 changed files with 31 additions and 14 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

+1 -1
View File
@@ -68,7 +68,7 @@ fn setup_tilemap(commands: &mut Commands, asset_server: &Res<AssetServer>) {
}
for x in -15..15 {
for y in -15..15 {
let position = Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, -14.);
let position = Vec3::new(x as f32 * TILE_SIZE, y as f32 * TILE_SIZE, -39.);
commands.spawn(TilePrefab::bedrock(position, asset_server));
}
}
+9 -2
View File
@@ -11,7 +11,7 @@ mod tiles;
fn main() {
App::new()
.insert_resource(game::ZIndex(-5.0))
.insert_resource(game::ZIndex(0.0))
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
@@ -33,7 +33,14 @@ fn main() {
camera::camera_movement,
citizen::citizen_movement,
tile::tile_item_sprite_update,
// tile::camera_z_movement.chain(tile::tile_sprite_occlusion),
),
)
.init_resource::<tile::CameraMoved>()
.add_systems(
FixedUpdate,
(
tile::camera_z_movement,
tile::tile_sprite_occlusion.run_if(|camera_moved: Res<tile::CameraMoved>| camera_moved.0),
),
)
.add_systems(FixedUpdate, cursor::move_cursor)
+21 -11
View File
@@ -55,17 +55,27 @@ pub struct DoorTile {
pub locked: bool,
}
// pub fn camera_z_movement(
// keyboard_input: Res<ButtonInput<KeyCode>>,
// mut z_index: ResMut<game::ZIndex>,
// ) {
// if keyboard_input.pressed(KeyCode::ShiftLeft) {
// z_index.0 -= 1.0;
// }
// if keyboard_input.pressed(KeyCode::ShiftRight) {
// z_index.0 += 1.0;
// }
// }
#[derive(Resource, Default)]
pub struct CameraMoved(pub bool);
// Modify camera_z_movement
pub fn camera_z_movement(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut z_index: ResMut<game::ZIndex>,
mut camera_moved: ResMut<CameraMoved>,
) {
camera_moved.0 = false;
if keyboard_input.pressed(KeyCode::ShiftLeft) {
z_index.0 -= 1.0;
z_index.0 = z_index.0.clamp(-39.0, 5.0);
camera_moved.0 = true;
}
if keyboard_input.pressed(KeyCode::ShiftRight) {
z_index.0 += 1.0;
z_index.0 = z_index.0.clamp(-39.0, 5.0);
camera_moved.0 = true;
}
}
pub fn tile_sprite_occlusion(
mut query: Query<(&mut Visibility, &Transform, &Tile), With<Tile>>,