Skip to content

Commit 58665b5

Browse files
committed
Fix tank shell spawn position
Shell now spawns 16px past the tank's leading edge rather than at the tank's origin, matching the corrected spec (8.2.2).
1 parent 6d752b4 commit 58665b5

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

pkg/logic/enemy_ai.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func moveTank(obj *state.ViewportObject, tick int, ts *state.TankShell, bridgeDe
185185
// River edge reached (or already at it): fire.
186186
// FireTankShell is a no-op while the shell is flying or exploding,
187187
// so this naturally implements the fire/wait cycle.
188-
FireTankShell(ts, obj.X, obj.Y, tick, obj.Orientation)
188+
FireTankShell(ts, shellSpawnX(obj.X, obj.Orientation), obj.Y, tick, obj.Orientation)
189189
}
190190
}
191191
}

pkg/logic/tank_shell.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
package logic
22

33
import (
4+
"github.com/morozov/river-raid-ebiten/pkg/assets"
45
"github.com/morozov/river-raid-ebiten/pkg/domain"
56
"github.com/morozov/river-raid-ebiten/pkg/platform"
67
"github.com/morozov/river-raid-ebiten/pkg/state"
78
)
89

10+
// shellSpawnOffset is the distance (px) from the tank's leading edge to the shell
11+
// spawn point, in the direction the tank faces.
12+
const shellSpawnOffset = 16
13+
14+
// ShellSpawnX returns the shell's initial X coordinate for a tank at the given
15+
// origin X and orientation.
16+
func shellSpawnX(tankX domain.SP, orient domain.Orientation) domain.SP {
17+
offset := domain.SP((assets.SpriteTankWidth + shellSpawnOffset) * domain.SubpixelScale)
18+
if orient == domain.OrientationLeft {
19+
return tankX - domain.SP(shellSpawnOffset*domain.SubpixelScale)
20+
}
21+
22+
return tankX + offset
23+
}
24+
925
// Physical tank shell speeds (px/sec).
1026
const (
1127
shellHorizSpeedPxSec = 24 // px/sec per speed unit (multiplier 1–4)

pkg/logic/tank_shell_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package logic
2+
3+
import (
4+
"testing"
5+
6+
"github.com/morozov/river-raid-ebiten/pkg/assets"
7+
"github.com/morozov/river-raid-ebiten/pkg/domain"
8+
)
9+
10+
func TestShellSpawnX(t *testing.T) {
11+
t.Parallel()
12+
13+
const tankX domain.SP = 100 * domain.SubpixelScale
14+
15+
tests := []struct {
16+
name string
17+
orient domain.Orientation
18+
wantPx domain.Px
19+
}{
20+
{
21+
name: "left-facing: 16px left of left edge",
22+
orient: domain.OrientationLeft,
23+
wantPx: 100 - shellSpawnOffset,
24+
},
25+
{
26+
name: "right-facing: 16px right of right edge",
27+
orient: domain.OrientationRight,
28+
wantPx: 100 + assets.SpriteTankWidth + shellSpawnOffset,
29+
},
30+
}
31+
32+
for _, tc := range tests {
33+
t.Run(tc.name, func(t *testing.T) {
34+
t.Parallel()
35+
36+
got := shellSpawnX(tankX, tc.orient)
37+
want := tc.wantPx.ToSP()
38+
39+
if got != want {
40+
t.Errorf("ShellSpawnX(%d, %v) = %d, want %d", tankX, tc.orient, got, want)
41+
}
42+
})
43+
}
44+
}

0 commit comments

Comments
 (0)