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