I'll build a polished Super Mario-style browser game! Let me start by planning the architecture and then implement it step by step.
Plan
- Set up the project structure
- Create the game engine with canvas rendering
- Implement player physics, platforms, enemies, coins
- Add particle effects, screen shake, score system
- Build UI overlays (start, pause, game-over, high scores)
- Support keyboard + touch controls
Let me start by exploring the current project structure and then build everything.
Good, I have the project structure. This is a React + Vite + Tailwind project. Now let me build the complete Mario-style game. I'll use a canvas-based game engine with React for UI overlays.
Let me start creating the game files:
Now let me create the game engine and all components. I'll build this as a single comprehensive game file with all game logic, then wire it into the React app.
Now the main game loop logic:
Now let me create the main Game component that ties everything together:
Now update the App.tsx to use our Game component:
Now let's add the Google Fonts "Press Start 2P" for the pixel-art font in the index.html:
Now let's update the CSS to ensure it's properly set up for full-screen game:
Now let me try building to see if there are any issues:
The build succeeds. Now let me do some polishing — the game needs a few improvements. Let me enhance the enemy behavior so they actually turn around properly and add some more juice. Also, I noticed the dt parameter might not flow properly through the game loop because the keyboard handling doesn't support touch properly in the game loop update. Let me refine the game.
Let me also fix the camera/player relationship and make the game feel snappier with better movement:
Now let me enhance the game loop to improve enemy AI and make the overall game feel more responsive. I also want to fix the edge detection for enemies and add wall collision:
I need to fix a few things. Let me rewrite the game loop more robustly, fixing enemy edge detection and improving platform collision for the player:
Now let me also improve the Game.tsx component - I want to fix an issue with the state synchronization and make the touch controls smoother. Also, I need to fix the start/gameover touch handling:
I need to fix the React state synchronization issue - the useEffect for the game loop depends on state values that it updates, causing unnecessary re-renders. Let me refactor to use refs for animation frame loop and avoid re-creating it:
Now let me build and verify:
Build succeeds. Now let me enhance the renderer to be more visually polished. The game works but I want to make it even juicier. Let me also add some more visual flair — better background parallax, the classic Mario pipe decorations, and more satisfying feedback:
The renderer looks good. Let me enhance the game with better level design — flag pole at the end, pipe decorations, and more enemy variety with proper movement. Let me also add a decorative flag at the end of the level and pipes:
Now let me also add a subtle squash-and-stretch effect when the player lands, and improve the level to have the flag be the win trigger. Let me also adjust the level so the win condition is reaching the flag (near level end):
The level is good as-is. The win condition triggers when the player reaches the far right edge, which is near the flag pole. Let me now build and test:
Build succeeds. Let me now enhance the game further with some key improvements:
- Better player squash/stretch on landing
- Score bonuses for stomping multiple enemies in a row (combo)
- More satisfying game feel
Let me also make the level a bit more interesting by varying the gaps more and adding more enemy variety near the end:
Now let me also fix the enemy edge-detection logic. The issue is enemies placed over pits. Let me make sure enemies placed near gaps get proper edge detection. Also, I want to ensure enemies don't walk off staircases. The current edge detection checks one point at the enemy's mid-bottom — let me verify it works for staircases too:
The current detection checks footX = enemy.x + enemy.width / 2 — this should work fine for staircases. Enemies on ground blocks will find ground below them. Enemies on stair edges will detect the step below.
Let me also fix a subtle issue: when the player is killed, the lives ref in game data gets decremented, and we need the game-over detection to work properly when lives reach 0 during killPlayer:
The logic looks solid. Let me now add one more polish — a "combo" counter that shows when you stomp multiple enemies without touching the ground, and also boost the stomp bounce:
I see I already imported Enemy and Platform — let me update the stomp function to track combos. Let me add a comboCount to the game data:
Now I need to add comboCount to all places where GameData is initialized:
Now I need to also add it in the resetGame function. Let me search for all bgOffset occurrences in Game.tsx:
Now let me update the stomp function to use combos and also update the onGround detection to reset combos:
I need to add combo reset when the player lands on ground. Let me edit the onGround logic:
Now update the stomp function:
Now let me also reset combo on death:
Let me now build to confirm everything compiles:
Build succeeds. Now let me add one more cool feature — a "power-up" mushroom that occasionally appears from question blocks, and make the game slightly more dynamic. Actually, let me keep things focused — the game already has:
- ✅ Start screen with controls display
- ✅ Platform generation with bricks, question blocks, ground
- ✅ Coin collection with spinning animation
- ✅ Enemy AI (goombas and koopas) with edge detection
- ✅ Stomp combos with increasing scores and particles
- ✅ Screen shake on stomp and death
- ✅ Particle effects (jump, coin, stomp, death, win)
- ✅ Floating score text
- ✅ Lives system with invincibility frames
- ✅ High scores stored in localStorage
- ✅ Pause/unpause (P/ESC)
- ✅ Game over and instant restart
- ✅ Win condition (reach the flag)
- ✅ Touch controls for mobile
- ✅ Keyboard controls for desktop
- ✅ Parallax background with clouds and hills
- ✅ Pipes, flag pole decorations
- ✅ Progress bar at bottom
- ✅ HUD with score, coins, lives, world
- ✅ Speed trail on player
The game is already quite polished. Let me make one final improvement — I want to ensure the game handles touch events properly for the start/game-over screen taps, and also add a subtle "landing" animation when the player touches down:
The game is fully functional. Let me do a final build to confirm everything is clean:
The build is clean and successful. Let me verify the final file structure:
Everything is in order. Here's a summary of what I built:
🎮 Super Pixel Run — A Polished Mario-Style Browser Game
Architecture
src/game/engine.ts — Core types, constants, and factory functions for the game
src/game/level.ts — Level design: platforms, bricks, question blocks, enemies, coins, staircases
src/game/gameLoop.ts — All update logic: physics, collisions, enemy AI, combos, scoring
src/game/renderer.ts — Canvas rendering: backgrounds, player, enemies, particles, HUD, pipes, flag pole
src/Game.tsx — React component: canvas setup, keyboard/touch input, UI overlays, game loop
src/App.tsx — Entry point, renders <Game />
Features
- Tight Controls — Arrow keys/WASD + Space for keyboard; on-screen touch D-pad + jump button for mobile
- Juicy Feedback — Screen shake on stomps/death, particle bursts (12+ types), floating score text, combo system with escalating rewards
- Start Screen — Animated title, controls guide, press Space/Jump to begin
- Score System — Coins (+50), enemy stomps (+100+combo bonuses), question blocks (+200), level completion (+1000)
- Combo System — Chain stomps without landing for escalating bonuses (x2, x3...) with bigger particles and screen shake
- Pause — P/ESC to toggle, touch pause button
- Game Over + Restart — Instant restart with Space or Jump tap, shows final score and high scores
- High Score Table — Top 5 persisted in localStorage, gold-highlighted current score
- 3 Lives — Invincibility frames with flashing animation after getting hit
- Visual Polish — Parallax clouds/hills, spinning coins, animated enemies, player walk cycle, speed trail, pipes, flag pole with waving flag, gradient progress bar
- 60fps — Efficient canvas rendering with requestAnimationFrame, state synced to React at lower frequency
Files built: index.html, src/game/engine.ts, src/game/level.ts, src/game/renderer.ts, src/game/gameLoop.ts, src/Game.tsx, src/App.tsx, src/index.css