Repository navigation
Add deterministic power-ups, inventory, and server-side activation for Battle Tanks - #63
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31584ec3f9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function beginTurn(state, player = state.activePlayer) { if (state.phase === 'game-over') return false; state.activePlayer = player; state.phase = 'aiming'; state.projectile = null; state.announcement = `Player ${player + 1}: adjust your shot.`; return true; } | ||
| function moveTank(state, direction, amount = 8) { if (state.phase !== 'aiming') return false; const tank = state.tanks[state.activePlayer], bounds = tankBounds(state, state.activePlayer); tank.x = clamp(tank.x + (direction === 'forward' ? (state.activePlayer ? -amount : amount) : (state.activePlayer ? amount : -amount)), bounds.min, bounds.max); tank.y = tankYAt(state, tank); return true; } | ||
| function beginTurn(state, player = state.activePlayer) { if (state.phase === 'game-over') return false; state.activePlayer = player; state.phase = 'aiming'; state.projectile = null; beginTurnEffects(state, player); state.announcement = `Player ${player + 1}: adjust your shot.`; return true; } | ||
| function moveTank(state, direction, amount = 8) { if (state.phase !== 'aiming') return false; const tank = state.tanks[state.activePlayer], bounds = tankBounds(state, state.activePlayer); tank.x = clamp(tank.x + (direction === 'forward' ? (state.activePlayer ? -amount : amount) : (state.activePlayer ? amount : -amount)), bounds.min, bounds.max); tank.y = tankYAt(state, tank); collectPickup(state, state.activePlayer); return true; } |
There was a problem hiding this comment.
Collect pickups during pointer-based movement
Pickup collection is only invoked by moveTank, but local touch/pointer movement in app.js changes tank.x and tank.y directly. Consequently, a player who follows the documented drag controls can drive across a pickup without collecting it; collection should also run from the drag path or all movement should go through a shared helper.
Useful? React with 👍 / 👎.
| if (collected.length) state.announcement = `Player ${player + 1} collected ${POWER_UP_CATALOG[collected[0]].label}.`; | ||
| return collected; | ||
| } | ||
| function expireEffects(state, player) { state.activeEffects[player] = state.activeEffects[player].filter(effect => effect.remainingTurns === undefined || effect.remainingTurns > 0 || effect.remainingAbsorption > 0); return state.activeEffects[player]; } |
There was a problem hiding this comment.
Remove fully depleted shield effects
When a shield reaches zero absorption, this predicate still retains it because shield records have remainingTurns === undefined, making the first condition true regardless of remainingAbsorption. After the shield owner's next turn begins, the inventory panel therefore continues to report Shield 0 as an active effect for the rest of the match instead of returning to “No active effects.”
Useful? React with 👍 / 👎.
Motivation
Description
POWER_UP_CATALOGwith IDs such ashealth-pack,shield,invisibility, weapon pickups (weapon-heavy-shell,weapon-wide-blast), and modifiers (damage-boost,blast-radius-boost) includingconsumesTurnand effect metadata inbattle-tanks/scripts/game.js.pickups,inventories,equippedWeapons,activeEffects,spawnSerial, andcompletedTurns, and exported utility/transition functionsspawnPickup,collectPickup,activatePowerUp,beginTurnEffects,expireEffects, andadvancePickupScheduleinbattle-tanks/scripts/game.js.moveTank(collection caps atINVENTORY_LIMITand healing is capped atSTARTING_HEALTH).consumesTurninfluences turn advancement).activateandequipand ensured the server performs spawning/collection/expiration and serializes pickup/inventory/effect state to clients inserver/battle-tanks-rooms.jsand allowed these message types inserver/index.js.battle-tanks/index.html,battle-tanks/styles.css, andbattle-tanks/scripts/app.jsto show inventory, current weapon, shield visuals, active effects and durations, pickup rendering in the arena, and to disable controls when it is not the player’s turn.tests/battle-tanks.test.jsandtests/battle-tanks-rooms.test.js.Testing
npm testand focused tests (npm test -- --test-name-pattern='power-up|pickup|inventory|activation|rematch'), and all relevant tests passed (no failures).npm run checkto ensure syntax and consistency across modified files, and the check completed without errors.activate/equip, seeded spawning determinism, valid pickup placement, inventory/cap behavior, activation/expiration semantics, rematch cleanup, stale-command rejection, and synchronized state between players all passed.Codex Task