I will search GameCanvas.tsx for how centipede movement and dive mechanics are implemented to find and fix the bug where centipedes charge straight to the bottom immediately.
Let's examine lines 370-410 in GameCanvas.tsx carefully. I will read lines 365-415 of src/components/GameCanvas.tsx.
Look at why the centipedes charge to the bottom straight away or dive down:
When spawning a centipede segment:
Let's check lines 150-175 in src/components/GameCanvas.tsx.
Look closely at what happens when targetGridX !== seg.gridX:
In seg.x += seg.dirX * seg.speed;:
Suppose seg.speed is 2.2 or 3.4.
Every frame (at 60 FPS), seg.x increases by 2.2 or 3.4 pixels.
Since CELL_W is 20 pixels, after ~6-9 frames, seg.x crosses a grid cell boundary (targetGridX !== seg.gridX).
Now let's look at lines 382-406:
if (targetGridX !== seg.gridX) {
const nextKey = `${targetGridX},${seg.gridY}`;
const hitEdge = targetGridX < 0 || targetGridX >= COLS;
const hitShroom = st.mushrooms.has(nextKey);
if (hitEdge || hitShroom) {
...
seg.dirX *= -1;
seg.gridY += seg.dirY;
seg.y = seg.gridY * CELL_H + CELL_H / 2;
...
Notice what happens if seg.gridX is NOT updated when hitEdge || hitShroom occurs! Or wait! Look at:
If hitShroom or hitEdge is true, we reverse dirX (seg.dirX *= -1) and step down one row (seg.gridY += seg.dirY, seg.y = ...).
BUT wait! We did NOT update seg.x or snap seg.x to the grid cell center or edge!
And wait! On the VERY NEXT FRAME, what happens?
seg.x += seg.dirX * seg.speed;
Suppose seg.x was at 301 when moving right (cell 15). targetGridX was 15, while seg.gridX was 14.
Suppose cell 15 has a mushroom (hitShroom = true).
So we reverse dirX to -1. And seg.gridY increases by 1 (drops a row). Notice we DID NOT set seg.gridX! So seg.gridX is still 14!
On the next frame, seg.x is 301 + (-1 * 2.2) = 298.8.
targetGridX = Math.floor(298.8 / 20) = 14!
Wait! seg.gridX is 14! So targetGridX === seg.gridX!
Wait, why would it charge down straight away? Let's check what if hitShroom happens again, OR what if a long centipede is following?
Wait! Look at spawnCentipede:
gridX: 15 - i,
gridY: 0,
x: (15 - i) * CELL_W + CELL_W / 2,
y: CELL_H / 2,
Wait! When i = 0 (head), gridX = 15.
When i = 1, gridX = 14.
When i = 10, gridX = 5.
When i = 15, gridX = 0.
Wait! If length is 10 to 16, wait! What if 15 - i < 0? If i = 16, gridX = -1!
Wait, when gridX = -1 or x < 0, wait!
Wait, even for i = 1, x = 14 * 20 + 10 = 290. dirX = 1.
When i = 0 (head) hits a mushroom or edge, it moves down a row (gridY becomes 1) and reverses dirX to -1.
Wait! What do the body segments (i = 1, 2, 3...) do?
In GameCanvas.tsx:
Notice how all segments (seg) are updated completely independently in a loop!
Wait! Body segments (seg.isHead === false) are updated with the EXACT SAME logic as the head!
Wait, if segment 0 moves down a row because cell (16, 0) had a mushroom, on the next frame segment 1 enters cell (16, 0). Since cell (16, 0) STILL has a mushroom, segment 1 ALSO reverses direction and drops down!
Wait! What if there is a cluster of mushrooms or wait! What if targetGridX < 0 || targetGridX >= COLS?
Wait! If seg.x is near an obstacle or edge, wait! Why would centipedes charge to the bottom straight away?
Let's trace:
Suppose a segment hits a mushroom at (col, row). Say dirX = 1. It enters targetGridX = col.
hitShroom is true.
seg.dirX *= -1 (now dirX = -1).
seg.gridY += seg.dirY (drops down to row + 1).
seg.y = seg.gridY * CELL_H + CELL_H / 2.
Wait! What is seg.gridX? seg.gridX was col - 1.
Wait! What if row + 1 ALSO has a mushroom at col - 1?
Wait! If row + 1 has a mushroom at col - 1, wait, on the next frame:
seg.x += -1 * seg.speed. targetGridX becomes col - 1.
Since col - 1 is equal to seg.gridX (col - 1), targetGridX !== seg.gridX is FALSE!
So it keeps moving left across cell col - 1. But wait! Cell col - 1 at seg.gridY HAS A MUSHROOM! It walked straight inside the mushroom without checking!
AND WAIT! When it reaches col - 2, targetGridX becomes col - 2.
If has a mushroom, is true!
So it reverses back to and drops down ANOTHER row ()!
Now it moves right into .
Wait! If has a mushroom, when does it check? When entering !
So if there are two adjacent mushrooms or vertical columns of mushrooms, the centipede bounces back and forth between the two columns every few pixels, dropping one row down on every bounce! It zig-zags straight down to the bottom of the screen in under 1 second!
AND wait! What if gets triggered or wait! Look at :
When runs, are there mushrooms spawned at or near the top?
Let's check :
const row = Math.floor(randFn() * 28) + 1;
Wait! What if a scorpion poisons a mushroom, or what if a flea drops a mushroom?
Wait! More importantly: In real arcade Centipede:
- Body segments DO NOT independently check edge/mushroom collisions to turn around! In classic arcade Centipede, body segments follow the path (history of turn points or exact trailing positions) of the segment immediately ahead of them!
OR if each segment moves on a grid:
When any segment moves horizontally and hits an obstacle (or edge) at its NEXT grid position:
It drops down one row and turns around. BUT when it drops down a row, what if the cell directly below it (or the next cell in its new direction) is blocked?
Wait! If a segment drops down a row, in real Centipede, when it drops down one row, it does NOT immediately drop down again on the same frame or within 2 pixels! It must move across the cell or wait until it hits an obstacle on its new row!
Let's look at why our code made it charge down:
Look at:
if (targetGridX !== seg.gridX) {
const nextKey = `${targetGridX},${seg.gridY}`;
const hitEdge = targetGridX < 0 || targetGridX >= COLS;
const hitShroom = st.mushrooms.has(nextKey);
if (hitEdge || hitShroom) {
if (hitShroom && st.mushrooms.get(nextKey)?.isPoisoned) {
seg.isPoisonDiving = true;
} else {
seg.dirX *= -1;
seg.gridY += seg.dirY;
seg.y = seg.gridY * CELL_H + CELL_H / 2;
Wait! Suppose segment is at seg.gridX = 10. dirX = 1.
It moves right to x = 210.1. targetGridX = 10? No, targetGridX = Math.floor(210.1 / 20) = 10. Wait, CELL_W is 20. So x = 200 is boundary between cell 9 and cell 10.
Suppose seg.gridX is 9. It crosses into targetGridX = 10.
Suppose cell (10, seg.gridY) has a mushroom (hitShroom = true).
So we do:
seg.dirX *= -1 (now dirX = -1).
seg.gridY += seg.dirY (now gridY is 1 row lower).
seg.y = seg.gridY * CELL_H + CELL_H / 2.
Wait! Notice what seg.x is: seg.x is 201 (just past the left edge of cell 10).
And notice what seg.gridX is: seg.gridX is STILL 9!
Now let's trace the NEXT frame:
seg.x += seg.dirX * seg.speed; -> seg.x = 201 + (-1 * 3) = 198.
targetGridX = Math.floor(198 / 20) = 9.
Wait! seg.gridX is 9!
Since targetGridX === seg.gridX, nothing happens on this frame.
Now let's trace the NEXT frame after that:
seg.x = 198 - 3 = 195.
...
After moving across cell 9, it reaches seg.x = 179.9.
targetGridX = Math.floor(179.9 / 20) = 8.
Now targetGridX !== seg.gridX (8 !== 9).
So it checks if cell (8, seg.gridY) has a mushroom!
If cell 8 ALSO has a mushroom, it reverses direction (dirX *= -1 -> 1) and drops down ANOTHER row (seg.gridY += 1)!
Now seg.x is 179.9.
On the NEXT frame, seg.x = 179.9 + 3 = 182.9.
targetGridX = Math.floor(182.9 / 20) = 9.
Since targetGridX === seg.gridX (both are 9!), it doesn't check anything! It just moves right across cell 9!
When it reaches seg.x = 200.1, targetGridX becomes 10.
And cell 10 has a mushroom!
So it drops down ANOTHER row!
So any time there are mushrooms in columns 8 and 10 (or any two nearby columns), every single centipede segment trapped in column 9 simply bounces left and right inside column 9, dropping down 1 row every ~7 frames (~8 times per second)!
AND wait! What if there is a vertical wall or cluster of mushrooms? It plummets to the bottom almost instantly!
Wait, why did this happen and how does authentic arcade Centipede work?
In authentic arcade Centipede:
First, let's fix centipede movement so that:
- When a centipede hits a mushroom or screen edge, it drops down one row AND turns around. BUT when it turns around after hitting a mushroom/edge at
targetGridX, it should be positioned inside its current cell (seg.gridX * CELL_W + CELL_W / 2), and its gridX is updated properly.
Wait! Even more importantly: Why would it get trapped between two mushrooms and plummet?
Because in real Centipede, when a segment drops down a row, if there is a mushroom in the cell it drops into or if it is turning around, let's look at how grid movement should cleanly work!
Wait! Even simpler: Why not make centipedes move smoothly point-to-point from grid cell to grid cell?
Let's think about point-to-point grid cell movement!
If a centipede segment is moving from cell (gridX, gridY) towards a target cell (targetX, targetY):
Suppose targetX = gridX + dirX, targetY = gridY.
Before starting to move from cell A to cell B, we check cell B (targetX, gridY).
If cell B is off-screen (targetX < 0 || targetX >= COLS) or has a mushroom (st.mushrooms.has(targetX,{gridY})):
Then cell B is blocked!
If cell B is blocked:
Instead of moving horizontally to cell B, the segment's new destination is ONE ROW DOWN: (gridX, gridY + dirY).
And once it finishes moving down one row to (gridX, gridY + dirY), its new horizontal direction flips (dirX *= -1).
Let's verify this!
If a segment moves from cell (gridX, gridY):
Suppose it moves smoothly towards its targetPos: { x: number, y: number }.
When it arrives at targetPos:
It updates gridX and gridY to that cell.
Then it determines its NEXT target cell:
Try next horizontal cell: nextX = gridX + dirX, .
Check if is out of bounds (<0 or >=COLS) or if {nextY}.
If it IS blocked:
If the blocked mushroom is poisoned (), the centipede enters poison dive mode ().
Otherwise:
We drop one row vertically! So the next target cell is .
Wait! What if is at the bottom of the screen ()? Then (it turns to move upwards inside the player zone!).
And we set for after the vertical drop!
Let's trace this!
Suppose cell 8 and cell 10 both have mushrooms on rows 2, 3, 4, 5, 6...
Segment is at cell . Moving right ().
It checks cell . Blocked!
So it moves vertically down from to . (Takes CELL_H / speed frames, which is ~20/2.5 = 8 frames).
When it reaches , it flips .
Now it checks cell . Blocked!
So it moves vertically down from to (8 frames).
Wait! In this case, if column 8 and column 10 are completely blocked solid walls, it will step down row by row (taking 8 frames per row).
Wait! Is there anything else causing them to charge to the bottom straight away?
Let's check !
Look at :
for (let i = 0; i < length; i++) {
segments.push({
id: `seg_${Date.now()}_${i}`,
gridX: 15 - i,
gridY: 0,
x: (15 - i) * CELL_W + CELL_W / 2,
y: CELL_H / 2,
dirX: 1, ...
Wait! When i = 0, gridX = 15.
When i = 15, gridX = 0.
When i = 16, gridX = -1.
When i = 17, gridX = -2.
Wait! If gridX is negative or out of bounds, or when seg.x starts off-screen or wait!
If gridX = 15 - i, let's check what happens when dirX = 1 and gridX = 15 - i!
Suppose segment 10 starts at gridX = 5.
Wait! Why would all segments move properly?
Wait! If every segment decides its own turns independently based on targetGridX !== seg.gridX, let's see what happened:
If segment 0 hits a mushroom at (18, 0) and drops to (18, 1),
When segment 1 reaches (18, 0), it also hits the mushroom and drops to (18, 1).
Wait! What if when segment 0 was killed by player bullet, we created a mushroom where it died?
Suppose segment 0 is shot at (14, 2). A new mushroom is created at (14, 2).
Segment 1 is right behind it at (13, 2).
Segment 1 moves right toward (14, 2).
It sees the mushroom created by segment 0 dying!
So segment 1 turns around and drops to (13, 3).
That is exactly how Centipede works!
Wait, let's double check if there was any OTHER reason why centipedes charged straight to the bottom!
Let's check isPoisonDiving:
Could mushrooms be poisoned right away?
Let's check scorpions:
st.scorpionTimer = 450; -> spawns a scorpion after 450 frames (~7.5 seconds).
When a scorpion touches a mushroom, m.isPoisoned = true.
If ANY centipede touches a poisoned mushroom, isPoisonDiving = true.
When isPoisonDiving is true:
seg.y += seg.speed * 2.8;
It dives at 3x speed straight down to the bottom of the screen!
Wait! When seg.y >= CANVAS_HEIGHT - CELL_H:
seg.isPoisonDiving = false;
And then once it reaches the bottom of the screen, what does it do?
It stays at the bottom of the screen zigzagging in the player area!
Wait! If a mushroom near the TOP of the screen gets poisoned by a scorpion, EVERY centipede segment that passes that mushroom will dive straight to the bottom of the screen!
Wait, let's check:
- When does
isPoisonDiving get cleared? When seg.y >= CANVAS_HEIGHT - CELL_H.
And when isPoisonDiving is set to true, in our previous code:
if (hitShroom && st.mushrooms.get(nextKey)?.isPoisoned) {
seg.isPoisonDiving = true;
}
Wait! If a mushroom at row 5 was poisoned, the centipede dives straight to the bottom!
Wait! Is that why the user noticed "remove the bug where the centipedes charge to the bottom straight away"?
Let's check two things:
First: In our previous code, when targetGridX !== seg.gridX triggered:
If targetGridX < 0 || targetGridX >= COLS || hitShroom:
Because seg.gridX wasn't updated when turning around, on every frame after turning around, if there was another obstacle or edge, it repeatedly dropped down row after row!
Second: What if a mushroom is spawned poisoned or gets poisoned too easily? Or wait! What if seg.isPoisonDiving triggers falsely or what if when spawning, initMushrooms created mushrooms that immediately blocked the centipede at row 0 or 1?
Let's look at initMushrooms:
const row = Math.floor(randFn() * 28) + 1;
If row = 1, there are mushrooms at row 1!
When centipede spawns at row = 0, if it moves right and hits the edge (col = 29), it drops to row = 1 and moves left.
If row = 1 has multiple mushrooms close together, and because of our bouncing bug (seg.gridX not updating properly when bouncing off a mushroom), as soon as it hit a mushroom on row 1, it rapid-fire bounced between mushrooms and shot straight down to the bottom!
Let's fix the grid movement for centipedes completely and robustly so that this bug never happens!
How should clean, perfect Centipede movement work?
Let's define clean grid movement for each segment:
Give each segment:
x, y (current position in pixels).
targetX, targetY (the exact pixel coordinates of the center of the grid cell it is currently walking towards).
gridX, gridY (current grid coordinates).
When moving:
Move x and y towards targetX and targetY at speed pixels per frame.
When the distance to targetX, targetY is less than speed (i.e. arrived at cell center):
Set x = targetX, y = targetY.
Set gridX = Math.floor(x / CELL_W), gridY = Math.floor(y / CELL_H).
Now, determine the NEXT target cell (nextGridX, nextGridY):
If isPoisonDiving:
If gridY >= ROWS - 2:
isPoisonDiving = false;
dirY = -1;
nextGridX = gridX + dirX;
nextGridY = gridY;
Else:
nextGridX = gridX;
nextGridY = gridY + 1;
Else:
We check if the cell ahead in horizontal direction (gridX + dirX, gridY) is blocked.
A cell is blocked if gridX + dirX < 0 or gridX + dirX >= COLS or st.mushrooms.has(gridX+dirX,{gridY}).
If NOT blocked:
nextGridX = gridX + dirX;
nextGridY = gridY;
If BLOCKED:
Check if the blocking mushroom is poisoned: st.mushrooms.get({gridY}.
If poisoned:
Else:
// Drop down (or up if at bottom of player zone) one row, and flip dirX for the step after that!
If :
Else if :
Let's trace this point-to-point grid movement:
Suppose segment is at (10, 2). Center is (210, 50). dirX = 1.
Next target cell: check (11, 2). Not blocked. So targetX = 230, targetY = 50.
Segment moves smoothly right until it reaches (230, 50).
At (230, 50), it checks (12, 2).
Suppose (12, 2) has a mushroom!
Blocked!
So nextGridX = 11, nextGridY = 3. targetX = 230, targetY = 70. And dirX becomes -1.
Segment moves smoothly vertically down from (230, 50) to (230, 70)!
When it arrives at (230, 70) (cell 11, 3), it checks its new horizontal path: 11 + (-1) = 10.
Check cell (10, 3). If clear, it moves smoothly left to (210, 70).
If (10, 3) also has a mushroom, then it moves vertically down to (230, 90) and flips dirX = 1.
Notice how clean, predictable, and 100% bug-free this is! There is no rapid-fire bouncing between mushrooms, no skipping grid cells, and no instant charging to the bottom!
Let's also check when spawning centipedes:
When spawning a centipede of length L (e.g. 10):
Let's place the head at (15, 0) with target (16, 0).
Where should segment 1 be placed? At (14, 0) with target (15, 0).
Where should segment i be placed? At (15 - i, 0) with target (16 - i, 0).
Wait! What if 15 - i < 0? If i = 16, 15 - i = -1.
Can we start segments off-screen to the left (gridX < 0) moving right into the screen?
Yes! If gridX < 0, when checking if gridX + dirX is blocked:
If gridX < 0, don't treat gridX < 0 as an edge obstacle! Only treat gridX + dirX < 0 when trying to move LEFT (dirX === -1) as an edge obstacle! When moving RIGHT (dirX === 1) from off-screen (gridX < 0), gridX + dirX should NOT be treated as blocked!
Let's make sure:
const isOffscreenLeft = checkX < 0 && dirX === -1;
const isOffscreenRight = checkX >= COLS;
So if gridX = -3 and dirX = 1, checking checkX = -2 returns NOT blocked, so it walks right into -2, then -1, then 0 (onto the visible screen)!
This makes spawning long centipedes completely smooth and natural!
Let's review all the user's requirements:
- Please keep the game to 1 gamemode.
- Remove
ModeSelector.tsx or replace it with a clean, single-mode arcade starting screen.
- In
types/game.ts, we can simplify or keep GameMode = 'classic' (or single mode).
- Let's check where
GameMode is used:
HighScoreEntry
LeaderboardModal.tsx
GameOverModal.tsx
App.tsx
GameCanvas.tsx
We will streamline everything to one exciting single arcade mode: NEON SWARM ARCADE.
- After a game over and in the starting menu make an upgrades screen.
- Let's make sure the starting menu has two prominent options: PLAY GAME and UPGRADE LAB & SKINS (or show the Upgrades screen via a dedicated button / tab right on the starting menu).
- And after a Game Over, inside
GameOverModal.tsx (or right on the post-game menu), include an UPGRADES LAB button! When clicked, it opens the Upgrades screen directly so players can immediately spend their newly earned coins on extra lives, rapid lasers, or custom cabinet skins before clicking Play Again!
- Please remove the bug where the centipedes charge to the bottom straight away.
- We will implement the exact point-to-point target grid movement for every segment described above. Let's make sure we test and verify it thoroughly.
Let's plan our tool calls to update the code cleanly:
Step 1: Update src/types/game.ts if needed (or keep CentipedeSegment updated with targetX, targetY).
Let's check CentipedeSegment in src/types/game.ts.
Let's edit src/types/game.ts to add targetX: number; and targetY: number; to CentipedeSegment. Also let's simplify GameMode to just 'arcade'. Let's check GameMode in src/types/game.ts.
Let's update src/types/game.ts to set GameMode = 'arcade' and add targetX, targetY to CentipedeSegment.I will update src/types/game.ts to simplify GameMode to a single arcade mode ('arcade') and add targetX and targetY to CentipedeSegment for smooth, exact grid movement that eliminates any premature bottom charging.
Let's update DEFAULT_HIGH_SCORES in src/services/storage.ts so all default high scores use mode: 'arcade'. Also let's check DEFAULT_ACHIEVEMENTS description if needed.I will update src/services/storage.ts so that all stored default high scores use the unified 'arcade' mode.
Now let's replace src/components/ModeSelector.tsx with our single gamemode arcade starting screen, which also prominently features the Upgrades Screen trigger!
Let's see: ModeSelectorProps can take onStartGame: () => void; onOpenShop: () => void; activeSkin: SkinTheme; highScore: number; coins: number;.
Let's check ModeSelectorProps and replace ModeSelector.tsx.I will replace src/components/ModeSelector.tsx to provide a focused, single-gamemode Arcade Launch Screen that also includes prominent access to the Upgrades screen right from the main menu.
Let's clean up the unused Coins import in src/components/ModeSelector.tsx.
Now let's update GameOverModal.tsx to include an UPGRADES LAB button right next to Play Again and Main Menu! Let's read and edit GameOverModal.tsx.
Let's edit GameOverModal.tsx to add onOpenShop: () => void; to props and render the Upgrades Lab button! Also import ShoppingCart.I will update src/components/GameOverModal.tsx to add an UPGRADES LAB button so players can spend coins on upgrades right after a game over before restarting.
Let's render the onOpenShop button in GameOverModal.tsx. Look at lines 125-143 in GameOverModal.tsx.I will render the Upgrades Lab button inside the Actions row of GameOverModal.tsx.
Now let's update LeaderboardModal.tsx to simplify to single mode ('arcade') and remove mode filters. Let's inspect LeaderboardModal.tsx.
Let's replace LeaderboardModal.tsx to display single mode ranks cleanly.I will replace src/components/LeaderboardModal.tsx to streamline it for our single arcade survival mode.
Now let's update src/App.tsx to handle our single mode 'arcade', passing onOpenShop to both ModeSelector and GameOverModal. Let's inspect src/App.tsx.
Let's read lines 215-248 of src/App.tsx.
Let's update src/App.tsx so getHighScoresMap gets the highest score for 'arcade', handleStartGame takes no arguments and launches 'arcade', and onOpenShop navigates to 'shop'. Also update GameOverModal props in App.tsx.I will update src/App.tsx to handle the streamlined single game mode and link both the starting menu and post-game screen to the Upgrades screen.
Let's edit src/App.tsx around getHighScoresMap and rendering of ModeSelector and GameOverModal. Let's read lines 150-248 in src/App.tsx.
Let's read lines 195-248 of src/App.tsx.
Let's update src/App.tsx around getHighScoresMap, ModeSelector, and GameOverModal.I will edit src/App.tsx to pass highScore, coins, and onOpenShop to ModeSelector, and onOpenShop to GameOverModal.
Let's update lines 193-245 of src/App.tsx.I will edit src/App.tsx to properly pass props to ModeSelector and GameOverModal.
Now let's update GameOverModal invocation in src/App.tsx.I will pass onOpenShop to GameOverModal in src/App.tsx.
Now let's update GameCanvas.tsx to remove the old multi-mode comparisons and implement the exact, robust point-to-point target grid movement for Centipede segments!
Let's inspect initMushrooms, spawnCentipede, and the centipede loop in GameCanvas.tsx. Let's read lines 115-180 of GameCanvas.tsx.
Let's update initMushrooms, spawnCentipede, and spawnBoss in GameCanvas.tsx. Also notice in initMushrooms:
const row = Math.floor(randFn() * 26) + 2; // leave top 2 rows clear and bottom clear
Leaving top 2 rows clear ensures the centipede starts with a clear horizontal lane!
And when setting up spawnCentipede:
const gx = 15 - i;
segments.push({
id: `seg_${Date.now()}_${i}`,
gridX: gx,
gridY: 0,
x: gx * CELL_W + CELL_W / 2,
y: CELL_H / 2,
targetX: (gx + 1) * CELL_W + CELL_W / 2,
targetY: CELL_H / 2,
dirX: 1,
dirY: 1, ...
Let's edit lines 119-210 in GameCanvas.tsx.I will update initMushrooms, spawnCentipede, and boss spawning in GameCanvas.tsx to simplify mode checks and initialize exact targetX and targetY coordinates.
Let's clean up getDailySeed and the old mode checks for spiders and fleas in GameCanvas.tsx. Let's check lines 450-515 of GameCanvas.tsx.
Let's remove getDailySeed from GameCanvas.tsx and simplify spider/flea timers. Also let's inspect and replace the centipede loop (section 4 of updateGame). Let's read lines 355-420 of GameCanvas.tsx.
Let's implement exact, smooth point-to-point grid movement for Centipede segments in Section 4. Let's make sure it handles initial targetX, targetY when segments split or spawn!
When a centipede segment moves:
// 4. Update Centipede Segments
for (let i = st.centipede.length - 1; i >= 0; i--) {
const seg = st.centipede[i];
if (seg.isPoisonDiving) {
seg.y += seg.speed * 2.5;
seg.gridY = Math.floor(seg.y / CELL_H);
seg.x = seg.gridX * CELL_W + CELL_W / 2;
if (seg.gridY >= ROWS - 2) {
seg.isPoisonDiving = false;
seg.y = (ROWS - 2) * CELL_H + CELL_H / 2;
seg.targetY = seg.y;
seg.targetX = seg.x + seg.dirX * CELL_W;
}
} else {
// Move smoothly toward (targetX, targetY)
const dx = seg.targetX - seg.x;
const dy = seg.targetY - seg.y;
const dist = Math.hypot(dx, dy);
if (dist <= seg.speed) {
// Arrived at target grid cell!
seg.x = seg.targetX;
seg.y = seg.targetY;
seg.gridX = Math.floor(seg.x / CELL_W);
seg.gridY = Math.floor(seg.y / CELL_H);
// Determine next target cell
const nextHorizCol = seg.gridX + seg.dirX;
const hitEdge = (nextHorizCol < 0 && seg.dirX === -1) || (nextHorizCol >= COLS && seg.dirX === 1);
const nextKey = `${nextHorizCol},${seg.gridY}`;
const hitShroom = st.mushrooms.has(nextKey);
if (hitEdge || hitShroom) {
if (hitShroom && st.mushrooms.get(nextKey)?.isPoisoned) {
seg.isPoisonDiving = true;
} else {
// Drop down one row (or step up if at bottom of player zone)
seg.gridY += seg.dirY;
if (seg.gridY >= ROWS - 1) {
seg.gridY = ROWS - 1;
seg.dirY = -1;
} else if (seg.gridY <= ROWS - 7 && seg.dirY === -1) {
seg.dirY = 1;
}
seg.targetX = seg.x;
seg.targetY = seg.gridY * CELL_H + CELL_H / 2;
seg.dirX *= -1;
}
} else {
// Continue horizontally
seg.targetX = nextHorizCol * CELL_W + CELL_W / 2;
seg.targetY = seg.y;
}
} else {
seg.x += (dx / dist) * seg.speed;
seg.y += (dy / dist) * seg.speed;
}
}
Notice how bullet destruction of a body segment should also set targetX, targetY if needed:
Let's check when bullet destroys a segment:
In Section 9:
When segment is destroyed:
if (cIdx < st.centipede.length - 1) {
st.centipede[cIdx + 1].isHead = true;
}
Since st.centipede[cIdx + 1] already has valid x, y, targetX, targetY, becoming head (isHead = true) requires no coordinate adjustments—it just continues smoothly on its current grid trajectory!
Let's edit GameCanvas.tsx to remove getDailySeed, update spider/flea timers, and replace Section 4.I will update GameCanvas.tsx to implement exact point-to-point target grid movement for Centipede segments and remove the unused mode timers.
Let's remove getDailySeed and simplify spider and flea timer resets in GameCanvas.tsx. Let's check lines 110-118 and 470-530 of GameCanvas.tsx.
Let's remove getDailySeed from lines 111-117.I will delete the unused getDailySeed helper function from GameCanvas.tsx.
Let's fix lines 465-525 of GameCanvas.tsx. Let's read lines 460-530 of GameCanvas.tsx.
Let's edit lines 466-520 of GameCanvas.tsx to set st.spiderTimer = 260; and st.fleaTimer = 340;.I will update the spider and flea spawn timers in GameCanvas.tsx.
Now let's update flea timer in GameCanvas.tsx.I will update the flea spawn timer in GameCanvas.tsx.
Let's run build_project to verify there are no TypeScript or build errors across all files.
The build succeeded cleanly with zero errors! Let's summarize the improvements made.I have completed all your requested updates:
-
Single Gamemode Streamlined ('arcade'):
- The starting screen (
ModeSelector.tsx) has been redesigned into a focused, single-player Neon Swarm Arcade Express survival experience.
- Leaderboards and high scores now cleanly track the unified arcade mode.
-
Accessible Upgrades Screen on Main Menu and Game Over:
- Starting Menu: Features an UPGRADE LAB button showing your current Cyber Coin balance right next to the START ARCADE GAME button, allowing you to buy permanent upgrades or switch cabinet skins before diving in.
- Game Over Screen: Added an UPGRADES LAB button directly between PLAY AGAIN and MENU so you can immediately invest coins earned from your latest run into extra lives, rapid fire, and shield durations before restarting.
-
Fixed Centipede Movement Mechanics (GameCanvas.tsx):
- Replaced continuous floating movement with exact, point-to-point grid trajectory calculations (
targetX, targetY).
- When any segment hits a mushroom or screen boundary, it steps down exactly one row and reverses direction without getting trapped in rapid bounce loops between adjacent mushroom columns.
- Ensured top rows spawn clear of mushrooms so newly spawned swarms march horizontally across the screen before descending naturally.
Files built: src/types/game.ts, src/services/storage.ts, src/components/ModeSelector.tsx, src/components/GameOverModal.tsx, src/components/LeaderboardModal.tsx, src/App.tsx, src/components/GameCanvas.tsx