Skip to content

Commit 9ffcbd9

Browse files
authored
Merge pull request #63 from sam-mfb/collision-bug
fix shielding behavior in new collision model
2 parents 9d167b8 + b108e37 commit 9ffcbd9

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

src/game/gameLoop/createCollisionMapThunk.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,40 @@ export const createCollisionMap = createSyncThunk<void>(
8888
)
8989
}
9090

91-
// Helper to add shot collision with optional wrapping
92-
const addShotCollision = (
93-
shot: (typeof state.shots.bunkshots)[0],
94-
screenOffsetX: number
95-
): void => {
96-
const shotX = shot.x - screenOffsetX
97-
const shotY = shot.y - state.screen.screeny
98-
const shotItem: CollisionItem = [
99-
{ x: shotX, y: shotY, collision: Collision.LETHAL },
100-
{ x: shotX + 1, y: shotY, collision: Collision.LETHAL },
101-
{ x: shotX, y: shotY + 1, collision: Collision.LETHAL },
102-
{ x: shotX + 1, y: shotY + 1, collision: Collision.LETHAL }
103-
]
104-
extra.collisionService.addItem(shotItem)
105-
}
106-
107-
// Add bunker shots at normal position
108-
state.shots.bunkshots
109-
.filter(shot => shot.lifecount > 0)
110-
.forEach(shot => addShotCollision(shot, state.screen.screenx))
91+
// only add bunker shots to collision map if ship is not shielding
92+
if (!state.ship.shielding) {
93+
// Helper to add shot collision with optional wrapping
94+
const addShotCollision = (
95+
shot: (typeof state.shots.bunkshots)[0],
96+
screenOffsetX: number
97+
): void => {
98+
const shotX = shot.x - screenOffsetX
99+
const shotY = shot.y - state.screen.screeny
100+
const shotItem: CollisionItem = [
101+
{ x: shotX, y: shotY, collision: Collision.LETHAL },
102+
{ x: shotX + 1, y: shotY, collision: Collision.LETHAL },
103+
{ x: shotX, y: shotY + 1, collision: Collision.LETHAL },
104+
{ x: shotX + 1, y: shotY + 1, collision: Collision.LETHAL }
105+
]
106+
extra.collisionService.addItem(shotItem)
107+
}
111108

112-
// Add bunker shots at wrapped position
113-
if (on_right_side && worldwrap) {
109+
// Add bunker shots at normal position
114110
state.shots.bunkshots
115111
.filter(shot => shot.lifecount > 0)
116-
.forEach(shot =>
117-
addShotCollision(shot, state.screen.screenx - state.planet.worldwidth)
118-
)
112+
.forEach(shot => addShotCollision(shot, state.screen.screenx))
113+
114+
// Add bunker shots at wrapped position
115+
if (on_right_side && worldwrap) {
116+
state.shots.bunkshots
117+
.filter(shot => shot.lifecount > 0)
118+
.forEach(shot =>
119+
addShotCollision(
120+
shot,
121+
state.screen.screenx - state.planet.worldwidth
122+
)
123+
)
124+
}
119125
}
120126
}
121127
)

0 commit comments

Comments
 (0)