Skip to content

Commit

Permalink
Merge pull request #373 from agateau/fix-missiles-showing-over-walls
Browse files Browse the repository at this point in the history
fix missiles showing over walls
  • Loading branch information
agateau authored Jul 27, 2023
2 parents 8baa877 + f060e7a commit fca6a63
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20230726-110733.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions core/src/com/agateau/pixelwheels/ZLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

/** The drawing layers, ordered from bottom to top */
public enum ZLevel {
GROUND,
VEHICLES,
SHADOWS,
OBSTACLES,
FLYING
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
}
2 changes: 1 addition & 1 deletion core/src/com/agateau/pixelwheels/bonus/BonusSpot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/agateau/pixelwheels/bonus/Mine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/com/agateau/pixelwheels/bonus/Missile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/agateau/pixelwheels/obstacles/Obstacle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.ON_GROUND;
if (zLevel != wantedZIndex) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/com/agateau/pixelwheels/racescreen/GameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ 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.OBSTACLES && mForegroundLayerIndexes.length > 0) {
if (z == ZLevel.FG_LAYERS && mForegroundLayerIndexes.length > 0) {
mGameObjectPerformanceCounter.stop();
mTilePerformanceCounter.start();

Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/agateau/pixelwheels/racescreen/Helicopter.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ 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;
drawFrameBuffer(batch, offset);
batch.setPackedColor(old);
} else if (zLevel == ZLevel.FLYING) {
} else if (zLevel == ZLevel.FLYING_HIGH) {
drawFrameBuffer(batch, 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fca6a63

Please sign in to comment.