Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "movement + projectile 最小ループ(WASD 移動・PointerEvent 射撃・60Hz fixed timestep・Projectile Canvas 描画)の deterministic な MVP を成立させる"
change_kind: code
spec_ssot:
- docs/product/features/movement-projectile.md
runtime_verification_applicability: deferredParent Issue
なし(M1: Foundation Gate の単独 implementation Issue。仕様正本は #2 で main へ確定済みの feature spec docs/product/features/movement-projectile.md)
Parent Goal Ref
- Goal: 戦闘の最小単位「動く」と「撃つ」を deterministic な fixed timestep ループ上で成立させ、後続 collision / damage 実装の前提となる入力・state・描画契約を固定する
- Desired Destination:
src/state/src/systems/src/renderの責務境界を保ったまま、feature specdocs/product/features/movement-projectile.mdの AC が実装上で観測可能になる
Implementation Source of Truth
本 Issue は次の feature spec の実装契約である。Issue 本文と feature spec が衝突した場合は feature spec を正とする。
docs/product/features/movement-projectile.md(PR docs(#2): movement + projectile 最小仕様を feature spec として固定する #440 で main へ確定済み)- 参照:
docs/product/game-logic.mdREQ-LOGIC-TIME-002(panic clamp),docs/adr/0001-architecture-baseline.md
anchor decision: #1 review comment 2026-05-28
Current Validated Scope
src/state/GameState.tsにProjectileState型とprojectiles: ProjectileState[]/nextProjectileId: numberを追加src/systems/MovementSystem.tsに boundary clamp と斜め入力正規化を実装src/systems/CombatSystem.tsを fire intent → cooldown 管理 →GameState.projectilesへの spawn に限定(progress.resources非 mutate)src/systems/ProjectileSystem.ts(新規)でdirection * speed * dt移動と lifetime / 境界外削除src/main.tsの fixed timestep ループに panic clamp 残余破棄とProjectileSystem統合src/input/(新規 adapter 層、anchor reframe)でKeyboardEvent.codeと PointerEvent lifecycle(setPointerCapture/pointercancel/lostpointercapture)を担当src/render/CanvasRenderer.tsにdevicePixelRatio対応と Projectile 描画tests/に movement / combat / projectile / input-mapper の deterministic ユニットテスト- canvas に CSS
touch-action: none適用(index.htmlまたはsrc/style.cssの最小編集)
Remaining Parent Gaps
- collision / damage 実装は本 Issue で実装しない(後続 implementation Issue)
docs/product/game-logic.md71 行目のAimIntent.angle例示修正(feature spec で follow-up 指定済み)- enemy AI / 強化 UI / 戦果画面 / 武器データ外部化 / multi-touch
- balance tuning(
projectile_speed_px_per_sec/projectile_lifetime_ms等の最適値)
Initial Constants for #1
feature spec open_questions のうち #1 実装で固定するもの。Balance tuning は後続 Issue で扱う。
| 識別子 | 値 |
|---|---|
player_speed_px_per_sec |
既存 GameState.player.speed = 210 を流用 |
player_radius_px |
既存 GameState.player.radius = 14 を流用 |
fire_cooldown_ms |
既存 weaponIntervalMs = 280 を流用 |
arena_width_px / arena_height_px |
既存 GameState.arena を流用 |
projectile_speed_px_per_sec |
520 |
projectile_lifetime_ms |
1200 |
projectile_radius_px |
4 |
projectile_out_of_bounds_margin_px |
8 |
aim_epsilon_px |
0.001 |
spawn_origin_offset |
自機中心(offset なし) |
| aim at same position fallback | 直前 frame の非ゼロ aim 方向を保持。初期値が無い場合は +X 方向 |
Outcome
src/state / src/systems / src/render の責務境界を保ったまま、WASD 入力で自機が arena 内を移動し、primary PointerEvent の hold-to-repeat で GameState.projectiles に Projectile が spawn・直進・寿命/境界外で削除され、CanvasRenderer が自機・照準線・Projectile を描画する状態。pnpm typecheck && pnpm lint && pnpm test && pnpm build が PASS する。
成果物: src/state/GameState.ts, src/systems/MovementSystem.ts, src/systems/CombatSystem.ts, src/systems/ProjectileSystem.ts (新規), src/render/CanvasRenderer.ts, src/main.ts, src/input/(新規 adapter), および tests/ 配下の 4 テストファイル(下記)の追加・拡充。
In Scope
src/state/GameState.tsへのProjectileState追加MovementSystemの boundary clamp と斜め入力正規化CombatSystemの fire / cooldown / Projectile spawn(resources 非 mutate)- 新規
ProjectileSystemの移動・削除 - 新規
src/input/adapter(KeyboardEvent.code+ PointerEvent lifecycle) src/main.tsの panic clamp 残余破棄とProjectileSystem統合CanvasRendererのdevicePixelRatio対応と Projectile 描画- 4 件の unit test 追加・拡充
Out of Scope
- collision 判定(弾と敵の衝突検知)
- damage / HP 演算
- enemy AI / 味方 AI
- visual effects(ヒットストップ、パーティクル、画面振動、音、着弾エフェクト)
- 戦果画面 / 強化 UI
- 武器データの外部化(複雑な weapon data)
- multi-touch 対応
- arena サイズの可変化(後続 stage feature の責務)
docs/product/game-logic.mdAimIntent.angle例示の修正(別 Issue)
Acceptance Criteria
- AC1: simulation は 60Hz 固定タイムステップ(
fixedDeltaMs ≈ 16.667)のアキュムレータで進行する - AC2: 1 animation frame あたりの catch-up step は
maxFrameSkip(既定 5)で上限化される - AC3:
maxFrameSkip到達時にaccumulatorMsの>= fixedDeltaMs残余は破棄され、次 frame にはaccumulatorMs < fixedDeltaMsの通常残余のみ持ち越される(テスト可能な純関数 / ヘルパに切り出し) - AC4: cooldown は simulation tick 時間で管理され、
Date.now()/performance.now()/ wall clock に依存しない - AC5: WASD は
KeyboardEvent.code(KeyW/KeyA/KeyS/KeyD)で取得しInputCommandに正規化される - AC6: 斜め入力はベクトル正規化により 8 方向で速度が均等になる
- AC7: 自機中心は
[player_radius_px, arena_size - player_radius_px]に boundary clamp される - AC8: aim の source of truth は
{ x, y }arena logical 座標。角度はGameState/InputCommandに保持しない - AC9:
pointerdownはevent.isPrimary === trueかつevent.button === 0のみ受け付け、canvas.setPointerCapture(pointerId)で capture する - AC10: capture 中の
pointerIdに一致するpointermoveのみ aim を更新する - AC11:
pointerup/pointercancel/lostpointercaptureでprimaryPressed = falseとし fire hold を終了する - AC12: canvas interaction target に CSS
touch-action: noneが指定されている - AC13: primary pointer hold 中はクールダウン完了ごとに自動連射される
- AC14: aim と自機中心の差が
aim_epsilon_px未満の場合は前 frame の非ゼロ aim 方向にフォールバックする(無ければ+X)。zero-length ベクトルからNaNが伝播しない - AC15:
GameState.projectiles: ProjectileState[]と monotonicGameState.nextProjectileIdが追加され、ProjectileStateはid/x/y/radius/directionX/directionY/speedPxPerSec/ageMs/lifetimeMsを持つ - AC16:
CombatSystemは fire 実行時にGameState.projectilesへ Projectile を push し cooldown を reset する。progress.resourcesを mutate せず damage を発生させない - AC17:
ProjectileSystemは各 Projectile をdirection * speed_px_per_sec * fixed_dtで進める - AC18:
ProjectileSystemはageMs >= lifetimeMsまたは arena 境界外(projectile_out_of_bounds_margin_px含む)の Projectile を削除する。残存要素の順序が deterministic - AC19:
CanvasRendererはdevicePixelRatioを考慮して backing store を拡大し描画 context を scale する - AC20: System 層(
src/state/src/systems)はdevicePixelRatioを読まない - AC21: メインループの fixed tick 順は
MovementSystem → CombatSystem → ProjectileSystem → CollisionSystem → tick/elapsedMsで、CombatSystemで spawn された Projectile は同 tick のProjectileSystemで進む - AC22:
pnpm typecheck && pnpm lint && pnpm test && pnpm buildが PASS する
Verification Commands
# AC1
$ pnpm test
# AC2
$ pnpm test
# AC3
$ rg -n "accumulatorMs % fixedDeltaMs|residualMs|panic.*discard|panic.*clamp.*reset" src/main.ts src/state
# AC4
$ pnpm test
# AC5
$ rg -n "KeyW|KeyA|KeyS|KeyD" src tests
# AC6
$ pnpm test
# AC7
$ pnpm test
# AC8
$ pnpm test
# AC9
$ rg -n "setPointerCapture" src
# AC10
$ pnpm test
# AC11
$ rg -n "pointercancel|lostpointercapture" src
# AC12
$ rg -n "touch-action" src/style.css index.html
# AC13
$ pnpm test
# AC14
$ rg -n "aim_epsilon|AIM_EPSILON|aimEpsilon" src/systems
# AC15
$ rg -n "ProjectileState|nextProjectileId" src/state/GameState.ts
# AC16
$ pnpm test
# AC17
$ test -f src/systems/ProjectileSystem.ts
# AC18
$ test -f tests/projectile-system.test.ts
# AC19
$ rg -n "devicePixelRatio" src/render/CanvasRenderer.ts
# AC20
$ pnpm test
# AC21
$ rg -n "ProjectileSystem" src/main.ts
# AC22
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildRequired Tests
tests/movement-system.test.ts:
player_speed_px_per_secで fixed delta 移動- 斜め入力の正規化
- 左 / 上 / 右 / 下の boundary clamp
- 通常より大きい
deltaMs後の clamp - invalid arena(
player_radius_px > arena_width_px / 2等)の防御的扱い
tests/combat-system.test.ts:
- aim を
InputCommand.aimから{x, y}で更新する GameState/InputCommandに angle を保持しない- cooldown 完了時の fire で
GameState.projectilesに Projectile が push される - cooldown 中は spawn が抑止される
- simulation delta で cooldown が減算される
progress.resourcesを mutate しない- same-position aim fallback(前 aim 保持 / 初期
+X)
tests/projectile-system.test.ts(新規):
- 正規化方向 ×
projectile_speed_px_per_sec×dtで進む ageMsが加算されるlifetimeMs経過で削除される- arena 境界外 + margin で削除される
- 残存要素の順序が deterministic
tests/input-mapper.test.ts(新規):
KeyboardEvent.codeがKeyW/KeyA/KeyS/KeyDにマップされる- primary pointer / 左ボタンのみ受け付ける
- captured
pointerIdのみ aim を更新する pointercancelでprimaryPressedがクリアされるlostpointercaptureでprimaryPressedがクリアされる
Allowed Paths
src/state/GameState.tssrc/systems/MovementSystem.tssrc/systems/CombatSystem.tssrc/systems/ProjectileSystem.ts(新規)src/render/CanvasRenderer.tssrc/main.tssrc/input/(新規 adapter 層、anchor reframe)tests/movement-system.test.tstests/combat-system.test.tstests/projectile-system.test.ts(新規)tests/input-mapper.test.ts(新規)index.htmlまたはsrc/style.css(canvastouch-action: noneの最小編集)
Scope Delta(PR #444 で追加)
AC3「panic clamp 残余破棄をテスト可能な純関数 / ヘルパに切り出し」実現のため、Issue contract の意図と整合する範囲で以下 3 件を追加 Allowed Paths とする:
src/systems/SimulationLoop.ts(新規 —runFixedTimestep純関数)src/systems/index.ts(上記の barrel 追記)tests/main-loop.test.ts(新規 — AC3 unit test。Required Tests 末尾で既に言及)
Runtime Verification Applicability
decision: deferred
reason: >
AC は決定論的単体テスト(fixed timestep / pure systems)で網羅検証可能。
Canvas / Pointer 連動の体感確認は feature spec PH-1〜PH-4 として
後続 playtest issue で扱う(docs/dev/runtime-verification-policy.md)。
deferred_destination:
destination_type: phase
destination_ref: M1 Foundation Gate playtest(feature spec PH-1〜PH-4 検証 issue を別途起票)Stop Conditions
実装中に次の状況が発生したら直ちに作業を停止し、Issue comment に状況を記録して人間判断を待つ。
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(AC・Initial Constants・System 責務境界)の変更が必要になった場合
- 別 Issue 起票が必要と判断した場合(collision / damage / enemy AI への波及など)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- TypeScript(strict mode)
- Vitest によるユニットテスト
- HTML5 Canvas 2D API(
devicePixelRatio対応) - PointerEvent / KeyboardEvent(pointer capture,
event.codesemantics) - ECS 風 state / systems 分離アーキテクチャ
Delivery Rule
1 Issue = 1 PR- Draft PR で開始し、AC 全件 PASS 後に Ready for Review
- 実装計画の追加承認は不要。本 Issue contract(Outcome / AC / VC / Allowed Paths)を実装計画の正本として扱う(
docs/dev/workflow.md)
Activity
chore: M1 Milestone 割当実施 — Parent Issue 直接割当・Implementation Issue 解除 (#…
docs(#2): movement + projectile 最小仕様を feature spec として固定する (#440)
squne121 commentedon May 28, 2026
判定
REQUEST CHANGES 相当。
#1 の方向性自体は妥当ですが、現状の #1 本文だけを実装契約として使うと、後続で整備された #2 / #440 の仕様と現在コードの実態を取り逃がします。#1 は「WASD 移動・pointerdown 射撃・60Hz fixed timestep・Projectile の Canvas 描画」を要求していますが、実装仕様の正本は後から #2 / #440 で
docs/product/features/movement-projectile.mdに切り出されています。#1 側にその back-reference がないため、実装者が古い Issue 本文だけで作業すると仕様ドリフトします。([GitHub]1)関連 PR #440 では、初期 approve 後に「panic clamp」「AimIntent の source of truth」「速度識別子」「pointer capture」などの意味論的な欠陥が REQUEST CHANGES で指摘され、その後修正されて main に merge されています。つまり、#1 は #440 で確定した仕様を実装 Issue に再注入してから着手すべきです。([GitHub]2)
Blocker 1: #1 が現在の仕様正本を参照していない
#1 は Projectile 実装の範囲と AC を書いていますが、Projectile speed、lifetime、arena size、same-position aim fallback、PointerEvent の終了条件など、実装で必ず決める必要がある値や振る舞いが曖昧です。#2 は「#1 の前提として movement + projectile feature spec を固定する」ための Issue で、#1 実装は out of scope、#1 本文からの back-reference は follow-up とされています。([GitHub]1)
修正要求: #1 本文の冒頭に次を追加してください。
さらに #1 の AC は、現在の feature spec に合わせて
KeyboardEvent.code、PointerEvent primary pointer / capture / cancel / lostpointercapture、simulation-time cooldown、projectile state schema、DPR-aware Canvas rendering を明記するべきです。([GitHub]3)Blocker 2: current main loop の panic clamp が仕様と衝突している
現在の
main.tsはwhile (accumulatorMs >= fixedDeltaMs && frameSkips < maxFrameSkip)で 1 frame 内の catch-up 回数を制限していますが、上限に達した後の backlog を破棄していません。つまり、重い frame の後も巨大なaccumulatorMsが残り、次 frame 以降も catch-up が継続します。これは #440 で指摘された「panic clamp residual carry」問題そのものです。([GitHub]4)feature spec は「通常の accumulator remainder だけを持ち越し、panic clamp 超過分は捨てる」としています。fixed timestep の古典的な設計でも、simulation が追いつけない場合は spiral of death を避けるため、1 frame あたりの最大 simulation step を制限し、重い状況では見かけ上スローになる方が安全です。([GitHub]3)
修正要求: #1 の実装 AC に次を追加。
実装例は概念的には以下です。
この挙動は closure 内に閉じず、純粋関数またはテスト可能な loop helper として切り出してください。そうしないと回帰テストが書けません。
Blocker 3: input contract が current code と merged spec でズレている
現在の入力処理は
event.keyでw/a/s/dを見ています。しかし merged spec はKeyboardEvent.codeを要求しています。ゲーム入力で WASD を物理キーとして扱うなら、キーボード配列差、たとえば AZERTY などを考慮してcodeを使うのが妥当です。MDN もゲームの WASD 例では、同じ物理キーを使うためKeyboardEvent.codeを使うべきと説明しています。([GitHub]4)Pointer 入力も未完成です。現在は canvas の
pointermove/pointerdownと window のpointerupだけで、setPointerCapture、pointercancel、lostpointercapture、primary pointer 判定、touch-action: noneがありません。Pointer capture は capture した要素へ後続 pointer event を送る仕組みで、pointercancelはブラウザがスクロール・ズーム等を開始した場合にも発火します。touch device 対応を崩さないため、この契約は省略できません。([GitHub]4)修正要求: DOM binding を
main.tsに直書きし続けるのではなく、少なくとも pointer lifecycle をテスト可能な adapter に切り出してください。期待挙動:
CSS 側は canvas に
touch-action: noneを指定するべきです。MDN も touch-action によりブラウザの既定タッチ動作を制御できると説明しています。([MDN Web Docs]5)Blocker 4: CombatSystem が Projectile ではなく resource を増やしている
現在の
CombatSystemは fire 時にshotsFiredを増やし、さらにprogress.resources += weaponPowerを実行しています。#1 の non-goal は damage、result screen、upgrade UI、complex weapon data を明示的に除外しており、merged spec でも CombatSystem の責務は Projectile spawn と cooldown に寄せられています。([GitHub]6)これは設計上かなり危険です。射撃ボタンを押すだけで resource が増える現行挙動を残したまま Projectile を追加すると、「Projectile は見た目だけで、実際の戦果は CombatSystem が即時付与する」という二重モデルになります。後で collision / damage を入れると破綻します。
修正要求: #1 の実装では fire の副作用を次に限定してください。
Blocker 5: GameState に Projectile の正規 schema がない
現在の
GameStateは arena、player、progress、telemetry を持ちますが、projectilesやnextProjectileIdがありません。merged spec はGameState.projectilesと monotonic counter を要求しています。([GitHub]7)推奨 schema:
禁止事項:
Projectile ID と lifetime は simulation state から決定し、wall-clock や乱数に依存させない方が deterministic test を書けます。
Blocker 6: CanvasRenderer が DPR-aware ではない
現在の
CanvasRendererはcanvas.width = state.arena.width、canvas.height = state.arena.heightとし、logical arena size をそのまま backing store size にしています。merged spec は「simulation は logical pixels、devicePixelRatio は renderer が扱う」としています。高 DPI canvas の一般実装では、CSS 上の表示サイズとdevicePixelRatioを使って backing store を拡大し、描画 context を scale します。([GitHub]8)修正要求: renderer の責務を次のように固定してください。
Projectile 描画は
state.projectilesを走査して円または短い streak として描画すれば十分です。FX は #1 の non-goal なので不要です。([GitHub]1)Major: MovementSystem の clamp と test が不足している
現在の
MovementSystemは axis normalization と速度反映はしていますが、arena boundary clamp がありません。#1 は「player が Canvas 内に clamp される」ことを AC にしています。([GitHub]9)既存 test は右移動の基本ケースのみで、境界、左上、右下、巨大 dt、斜め入力後の clamp を検証していません。merged spec は boundary clamp 関連テストを明示しています。([GitHub]10)
追加テスト必須:
Major: Projectile update order を明文化すべき
現在の loop order は
MovementSystem -> CombatSystem -> CollisionSystem -> tickです。#1 でProjectileSystemを追加するなら、spawn された Projectile を同 tick で動かすのか、次 tick から動かすのかを決める必要があります。ここを曖昧にすると、初弾位置、snapshot test、将来の collision timing がブレます。([GitHub]4)推奨は次です。
個人的には、CombatSystem で spawn した Projectile は同 tick の ProjectileSystem で進める方が実装は単純です。ただし test で「spawn 後 1 fixed tick 分だけ進む」ことを固定してください。
Major: same-position aim fallback が未確定
merged spec は aim source of truth を
{x, y}logical arena coordinate に固定していますが、player center と aim point が同一だった場合の fallback は open question のままです。([GitHub]3)推奨: 次のように固定してください。
これにより zero-length vector の
NaN化を防げます。#1 に入れるべき具体的な修正案
既存 state の player speed、radius、cooldown は現在コード上に既に存在するので、#1 ではそれを再利用できます。Projectile speed / lifetime / radius は #1 で明示しないと実装者判断になり、後続レビューで不毛な差し戻しになります。([GitHub]7)
必須テストセット
現在の
testsにはprojectile-system.test.tsが存在せず、movement test も基本移動のみです。#1 の完了条件にするには不足です。([GitHub][11])最終レビューコメント案
結論として、#1 は **「実装してよい Issue」ではなく、「#440 の仕様を取り込んでから実装する Issue」**です。実装 PR を出すなら、上の blocker を PR scope に含めない限り差し戻しが妥当です。
[11]: https://github.com/squne121/loop-protocol/tree/main/tests "loop-protocol/tests at main · squne121/loop-protocol · GitHub"****
squne121 commentedon May 28, 2026
issue-refinement-loop 完了
termination_reason:
approvediterations: 2(iteration 0 → needs-fix → iteration 1 → approve)
anchor: #1 review comment 2026-05-28(OWNER, classification:
feedback_update_required/ scope_impact:amend、anchor reframe でsrc/input/新規層を allowed)Deterministic checks(13/13 pass)
反映した anchor フィードバック
docs/product/features/movement-projectile.mdを本文先頭で固定(PR docs(#2): movement + projectile 最小仕様を feature spec として固定する #440 で main 確定済み)KeyboardEvent.code/ PointerEvent capture+cancel+lostpointercapture /touch-action: none/CombatSystemのprogress.resources非 mutate /GameState.projectiles&nextProjectileIdschema / DPR は renderer 責務)# AC<N>ブロックを deterministic コマンドで紐付けopen_questionsのうち#1実装値を固定(projectile_speed_px_per_sec=520/projectile_lifetime_ms=1200/projectile_radius_px=4/out_of_bounds_margin_px=8/aim_epsilon_px=0.001)+X)を明文化src/input/(新規 adapter 層、anchor reframe)を含めたdeferred/destination_type: phase/ playtest PH-1〜PH-4 を後続 issue 起票へ委譲scope rollup / follow-up materialization
docs/product/game-logic.mdAimIntent.angle例示修正 → 既に docs(game-logic): AimIntent 例示を {x, y} arena 座標表現に修正する #443 として起票済み次のステップ
本 Issue は
issue-contract-reviewを通せば実装着手可能な状態。/impl-review-loop 1で実装ループへ進める。[-]自機移動と Projectile 射撃システムを実装する[/-][+]実装: 自機移動と Projectile 射撃システム[/+]squne121 commentedon May 28, 2026
Contract Snapshot (2026-05-28T10:12:45Z)
# AC<N>で紐付け(本文参照).claude/worktrees/issue-1-jiki-ido-to-projectile-shageki-systemworktree-issue-1-jiki-ido-to-projectile-shageki-systemsqune121 commentedon May 28, 2026
implement-issue: 実装完了 (2026-05-28T10:23:25Z)
.claude/worktrees/issue-1-jiki-ido-to-projectile-shageki-systemworktree-issue-1-jiki-ido-to-projectile-shageki-systemfix(#1): iteration 2 — SimulationLoop wiring / AC14 last-aim fallback…
feat(#1): 自機移動と Projectile 射撃システム (AC1-AC22) (#444)
fix(#432): address review blockers — artifact rename, belt-and-suspen…
feat: enforce manifest validation required check (#432) (#540)
fix: PR #1479 OWNER レビュー指摘の P1 Blocker 1-3 / P1 High / P2 High / P2 を…
実装: publish laneに新規branch初回publish用のatomicなbranch作成laneを追加する (#1479)
fix: VRT baseline を CI (pinned Playwright container) の実描画結果に合わせて再生成する (…
実装: Playwright primary VRT suite を pending/provisional baseline だけで導入…
fix(#1791 review remediation): readiness→structured_blockers を決定論的CLI…
実装: review-issue の structured_blockers を compact_review_result.py の R…