From f2c96dd74acb383a121ab6622192765282c7d3fc Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Wed, 26 Jul 2023 11:06:11 +0200 Subject: [PATCH 1/3] Fix missiles showing over walls --- .changes/unreleased/Fixed-20230726-110733.yaml | 3 +++ core/src/com/agateau/pixelwheels/ZLevel.java | 10 ++++++---- core/src/com/agateau/pixelwheels/bonus/Missile.java | 2 +- .../com/agateau/pixelwheels/racer/VehicleRenderer.java | 2 +- .../agateau/pixelwheels/racescreen/GameRenderer.java | 2 +- .../com/agateau/pixelwheels/racescreen/Helicopter.java | 2 +- .../racescreen/debug/DropLocationDebugObject.java | 2 +- 7 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .changes/unreleased/Fixed-20230726-110733.yaml diff --git a/.changes/unreleased/Fixed-20230726-110733.yaml b/.changes/unreleased/Fixed-20230726-110733.yaml new file mode 100644 index 000000000..bb68d4834 --- /dev/null +++ b/.changes/unreleased/Fixed-20230726-110733.yaml @@ -0,0 +1,3 @@ +kind: Fixed +body: "Missiles are no longer drawn over walls or bridges (#58, #362)." +time: 2023-07-26T11:07:33.016807364+02:00 diff --git a/core/src/com/agateau/pixelwheels/ZLevel.java b/core/src/com/agateau/pixelwheels/ZLevel.java index b66f63a47..ff4992023 100644 --- a/core/src/com/agateau/pixelwheels/ZLevel.java +++ b/core/src/com/agateau/pixelwheels/ZLevel.java @@ -20,9 +20,11 @@ /** The drawing layers, ordered from bottom to top */ public enum ZLevel { - GROUND, + GROUND, // bgX layers, skidmarks, vehicle shadows, mines, bullets... VEHICLES, - SHADOWS, - OBSTACLES, - FLYING + SHADOWS, // obstacle and helicopter shadows + OBSTACLES, // obstacles + FLYING_LOW, // missiles + FG_LAYERS, // fgX layers + FLYING_HIGH, // helicopter, vehicles being carried by helicopter } diff --git a/core/src/com/agateau/pixelwheels/bonus/Missile.java b/core/src/com/agateau/pixelwheels/bonus/Missile.java index 4bef59ec0..45332540c 100644 --- a/core/src/com/agateau/pixelwheels/bonus/Missile.java +++ b/core/src/com/agateau/pixelwheels/bonus/Missile.java @@ -255,7 +255,7 @@ private void findTarget() { @Override public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { - if (zLevel == ZLevel.FLYING) { + if (zLevel == ZLevel.FLYING_LOW) { // Draw the shadow at Z_FLYING so that the shadow is drawn *over* its vehicle drawShadow(batch); drawMissile(batch); diff --git a/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java b/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java index aaf480a36..060b9b8cc 100644 --- a/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java +++ b/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java @@ -162,7 +162,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { } // Vehicle level: wheels and body - ZLevel wantedZIndex = mVehicle.isFlying() ? ZLevel.FLYING : ZLevel.VEHICLES; + ZLevel wantedZIndex = mVehicle.isFlying() ? ZLevel.FLYING_HIGH : ZLevel.VEHICLES; if (zLevel != wantedZIndex) { return; } diff --git a/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java b/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java index 1d74a8f35..877fce665 100644 --- a/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java +++ b/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java @@ -167,7 +167,7 @@ public void render(float delta) { object.draw(mBatch, z, viewBounds); } - if (z == ZLevel.OBSTACLES && mForegroundLayerIndexes.length > 0) { + if (z == ZLevel.FG_LAYERS && mForegroundLayerIndexes.length > 0) { mGameObjectPerformanceCounter.stop(); mTilePerformanceCounter.start(); diff --git a/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java b/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java index ab012c455..42fb316a3 100644 --- a/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java +++ b/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java @@ -248,7 +248,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { float offset = SHADOW_OFFSET * Constants.UNIT_FOR_PIXEL; drawFrameBuffer(batch, offset); batch.setPackedColor(old); - } else if (zLevel == ZLevel.FLYING) { + } else if (zLevel == ZLevel.FLYING_HIGH) { drawFrameBuffer(batch, 0); } } diff --git a/core/src/com/agateau/pixelwheels/racescreen/debug/DropLocationDebugObject.java b/core/src/com/agateau/pixelwheels/racescreen/debug/DropLocationDebugObject.java index 98cfa7f4d..eec2ab02c 100644 --- a/core/src/com/agateau/pixelwheels/racescreen/debug/DropLocationDebugObject.java +++ b/core/src/com/agateau/pixelwheels/racescreen/debug/DropLocationDebugObject.java @@ -88,7 +88,7 @@ public void act(float delta) { @Override public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { - if (!mActive || zLevel != ZLevel.FLYING) { + if (!mActive || zLevel != ZLevel.FLYING_HIGH) { return; } TextureRegion region = mAssets.target; From 184dc1686137b93adb250fbab26e4b1976b71814 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Wed, 26 Jul 2023 20:40:18 +0200 Subject: [PATCH 2/3] Draw helicopter shadows on top of fgX layers --- .../com/agateau/pixelwheels/racescreen/GameRenderer.java | 8 ++++---- .../com/agateau/pixelwheels/racescreen/Helicopter.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java b/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java index 877fce665..b6858ed53 100644 --- a/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java +++ b/core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java @@ -163,10 +163,6 @@ public void render(float delta) { mBatch.begin(); for (ZLevel z : ZLevel.values()) { - for (GameObject object : mWorld.getActiveGameObjects()) { - object.draw(mBatch, z, viewBounds); - } - if (z == ZLevel.FG_LAYERS && mForegroundLayerIndexes.length > 0) { mGameObjectPerformanceCounter.stop(); mTilePerformanceCounter.start(); @@ -178,6 +174,10 @@ public void render(float delta) { mTilePerformanceCounter.stop(); mGameObjectPerformanceCounter.start(); } + + for (GameObject object : mWorld.getActiveGameObjects()) { + object.draw(mBatch, z, viewBounds); + } } mBatch.end(); mGameObjectPerformanceCounter.stop(); diff --git a/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java b/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java index 42fb316a3..d105d1d58 100644 --- a/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java +++ b/core/src/com/agateau/pixelwheels/racescreen/Helicopter.java @@ -242,7 +242,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { if (!AgcMathUtils.rectangleContains(viewBounds, getPosition(), mFrameBufferRadiusU)) { return; } - if (zLevel == ZLevel.SHADOWS) { + if (zLevel == ZLevel.FG_LAYERS) { float old = batch.getPackedColor(); batch.setColor(0, 0, 0, SHADOW_ALPHA); float offset = SHADOW_OFFSET * Constants.UNIT_FOR_PIXEL; From f060e7a42055032c9271d0032ced49ef65c6032c Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Thu, 27 Jul 2023 20:40:51 +0200 Subject: [PATCH 3/3] Merge VEHICLES, SHADOWS and OBSTACLES ZLevel into ON_GROUND --- core/src/com/agateau/pixelwheels/ZLevel.java | 10 ++++------ core/src/com/agateau/pixelwheels/bonus/BonusSpot.java | 2 +- core/src/com/agateau/pixelwheels/bonus/Mine.java | 2 +- .../pixelwheels/gameobject/AnimationObject.java | 2 +- .../com/agateau/pixelwheels/obstacles/Obstacle.java | 4 ++-- .../com/agateau/pixelwheels/racer/VehicleRenderer.java | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/src/com/agateau/pixelwheels/ZLevel.java b/core/src/com/agateau/pixelwheels/ZLevel.java index ff4992023..85001483d 100644 --- a/core/src/com/agateau/pixelwheels/ZLevel.java +++ b/core/src/com/agateau/pixelwheels/ZLevel.java @@ -20,11 +20,9 @@ /** The drawing layers, ordered from bottom to top */ public enum ZLevel { - GROUND, // bgX layers, skidmarks, vehicle shadows, mines, bullets... - VEHICLES, - SHADOWS, // obstacle and helicopter shadows - OBSTACLES, // obstacles - FLYING_LOW, // missiles - FG_LAYERS, // fgX layers + GROUND, // bgX layers, skidmarks, vehicle and obstacle shadows, mines, bullets... + ON_GROUND, // vehicles, obstacles, bonus, mine + FLYING_LOW, // missiles, explosions, impacts + FG_LAYERS, // fgX layers, helicopter shadow FLYING_HIGH, // helicopter, vehicles being carried by helicopter } diff --git a/core/src/com/agateau/pixelwheels/bonus/BonusSpot.java b/core/src/com/agateau/pixelwheels/bonus/BonusSpot.java index a587d479e..d353f66ff 100644 --- a/core/src/com/agateau/pixelwheels/bonus/BonusSpot.java +++ b/core/src/com/agateau/pixelwheels/bonus/BonusSpot.java @@ -106,7 +106,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { if (zLevel == ZLevel.GROUND) { mDrawer.setBatch(batch); mDrawer.drawShadow(mBody, mRegion); - } else if (zLevel == ZLevel.OBSTACLES) { + } else if (zLevel == ZLevel.ON_GROUND) { mDrawer.setBatch(batch); mDrawer.draw(mBody, mRegion); } diff --git a/core/src/com/agateau/pixelwheels/bonus/Mine.java b/core/src/com/agateau/pixelwheels/bonus/Mine.java index 913f76d16..5ab3d72dd 100644 --- a/core/src/com/agateau/pixelwheels/bonus/Mine.java +++ b/core/src/com/agateau/pixelwheels/bonus/Mine.java @@ -188,7 +188,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { TextureRegion region = mAssets.mine.getKeyFrame(mTime); mBodyRegionDrawer.drawShadow(mBody, region); } - if (zLevel == ZLevel.VEHICLES) { + if (zLevel == ZLevel.ON_GROUND) { TextureRegion region = mAssets.mine.getKeyFrame(mTime); mBodyRegionDrawer.draw(mBody, region); } diff --git a/core/src/com/agateau/pixelwheels/gameobject/AnimationObject.java b/core/src/com/agateau/pixelwheels/gameobject/AnimationObject.java index 1617f2bdd..09b80ad57 100644 --- a/core/src/com/agateau/pixelwheels/gameobject/AnimationObject.java +++ b/core/src/com/agateau/pixelwheels/gameobject/AnimationObject.java @@ -69,7 +69,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { if (mTime < 0) { return; } - if (zLevel != ZLevel.OBSTACLES) { + if (zLevel != ZLevel.FLYING_LOW) { return; } TextureRegion region = mAnimation.getKeyFrame(mTime); diff --git a/core/src/com/agateau/pixelwheels/obstacles/Obstacle.java b/core/src/com/agateau/pixelwheels/obstacles/Obstacle.java index 97a2f96da..06cc7ded6 100644 --- a/core/src/com/agateau/pixelwheels/obstacles/Obstacle.java +++ b/core/src/com/agateau/pixelwheels/obstacles/Obstacle.java @@ -75,13 +75,13 @@ public void act(float delta) { @Override public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { - if (zLevel != ZLevel.OBSTACLES && zLevel != ZLevel.SHADOWS) { + if (zLevel != ZLevel.ON_GROUND && zLevel != ZLevel.GROUND) { return; } if (!AgcMathUtils.rectangleContains(viewBounds, getPosition(), mRegionRadius)) { return; } - if (zLevel == ZLevel.OBSTACLES) { + if (zLevel == ZLevel.ON_GROUND) { mBodyRegionDrawer.setBatch(batch); mBodyRegionDrawer.draw(mBody, mRegion); } else { diff --git a/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java b/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java index 060b9b8cc..9668919bf 100644 --- a/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java +++ b/core/src/com/agateau/pixelwheels/racer/VehicleRenderer.java @@ -162,7 +162,7 @@ public void draw(Batch batch, ZLevel zLevel, Rectangle viewBounds) { } // Vehicle level: wheels and body - ZLevel wantedZIndex = mVehicle.isFlying() ? ZLevel.FLYING_HIGH : ZLevel.VEHICLES; + ZLevel wantedZIndex = mVehicle.isFlying() ? ZLevel.FLYING_HIGH : ZLevel.ON_GROUND; if (zLevel != wantedZIndex) { return; }