Build a polished, playable browser game: Create a complete 2D platformer game similar to…
- User
Build a polished, playable browser game: Create a complete 2D platformer game similar to Super Mario, fully playable, using a suitable programming language such as JavaScript (with HTML5 Canvas) or Unity (C#). Core Requirements: 1. Player: * A controllable character that can move left and right. * Ability to jump with realistic physics (gravity). * Simple animations for movement and jumping. 2. World: * Design levels that include platforms. * Add ground, blocks, and pipes. * Allow the player to fall off platforms. 3. Enemies: * Add enemies that move automatically. * If the player touches an enemy, they lose. * If the player jumps on an enemy, the enemy is defeated. 4. Items: * Add collectible coins. * Increase score when collecting coins. * Optionally include power-ups (e.g., growing the player). 5. Score System: * Display a score counter on the screen. * Increase score when collecting coins or defeating enemies. 6. Physics: * Implement gravity. * Add accurate collision detection between player, platforms, and enemies. 7. Sound: * Add sound effects for jumping, collecting coins, and losing. 8. User Interface (UI): * Start menu screen. * Game over screen. * Display score. 9. Code Structure: * Write clean and well-organized code. * Separate logic into components (Player, Enemy, Game Loop, etc.). * Add comments explaining each part. 10. Execution: * The game must be directly playable (e.g., in a browser if using JavaScript). * Avoid complex external dependencies. Provide a full working code example along with simple step-by-step instructions on how to run the game.. Make the core loop fun within the first ten seconds, with tight controls for both keyboard and touch, and juicy feedback — screen shake, particle effects, and satisfying animations. Include a start screen, a score system, pause and game-over states with instant restart, and a local high-score table. Style it with a cohesive visual theme and make sure it runs smoothly at 60fps on desktop and mobile.
Assistant
I will begin by exploring the current files in the project to understand the structure of the React-Vite application. Let's list the files.
I will inspect
index.htmlandsrc/App.tsxto understand the setup and verify if lucide-react or other packages are needed. Let's readindex.htmlfirst.Let's read
src/App.tsxto understand the existing setup.I will install
lucide-reactso that we have high-quality icons for our UI controls, start screen, powerups, mute buttons, and level selection features. Let's runinstall_npm_packageswithlucide-react.Let's change the page title in
index.htmlto be more exciting and relevant to our platformer game. I'll editindex.htmlto set the title to "Super Retro Bros - Retro Web Platformer Adventure".Now we will design a spectacular, high-fidelity HTML5 Canvas 2D platformer game with Mario-like physics, extremely juice-packed visuals, smooth responsive controls, and sound/audio synthesis using the Web Audio API. Web Audio API is extremely robust for this task as it does not depend on loading external static mp3 files which often fail to load or get blocked by CORS in sandbox environments. Instead, we can synthesize authentic retro sound effects directly in JavaScript:
- Jump: short high-pass frequency sweep upwards.
- Coin: dual-tone bell chime.
- Stomp: low-pass frequency sweep downwards with a bit of noise (crunchy).
- Powerup / Grow: rapid scale sweep upwards.
- Shrink / Damage: descending alarm tone.
- Game Over: short minor-chord sad arpeggio.
- Win level: triumphant major chord arpeggio.
Let's design the layout and code structure. We'll create:
- An incredibly fun and gorgeous retro level design with:
- Floating platforms, solid ground, brick blocks, mystery blocks, and pipes!
- Multiple kinds of enemies: Goombas (walking patrols), Koopas (patrols that can withstand standard hits or move faster), and Plants (shooting/popping out of pipes).
- Collectibles: Gold Coins, Super Mushrooms (which grow the player, let them survive 1 extra hit, and break brick blocks), Starman power-ups (invincibility, flashing rainbow colors, defeating enemies on contact, with custom trail particles), and Fire Flowers (which let the player shoot bouncing fireballs!).
- Interactive physical interactions: jumping from underneath bricks makes them bounce, or shatters them if the player is powered up! Mystery blocks reveal coins or mushrooms/stars with a satisfying pop animation.
- Particle systems: explosion particles, dust clouds when jumping/landing, sparkling star particles, shiny coin chimes, and screen shake on heavy impacts (stamping enemies, taking damage, or breaking blocks).
- Dynamic smooth-follow camera with zoom, tracking the player in a rich parallax retro background featuring mountains, bushes, and clouds.
- Multiple game states:
- Start Screen with retro pixel-art styling, key instructions, custom level selector (Level 1: Classic Hills, Level 2: Brick Castle, Level 3: Starry Peaks), character customization (Classic Red, Emerald Luigi, Cyber Purple, Golden Boy), and a Local High-score leaderboard.
- Playing State with real-time HUD (Score, Level, Coins, Health/Power, Time Remaining, Invincibility duration), sound mute/unmute buttons, fully-featured pause state, touch controls (on-screen gamepad for mobile, perfectly tuned with zero-delay touchstart/touchend), and level selection.
- Game Over Screen with custom stats (Enemies stomped, coins gathered, max streak), high scores list, and a big restart button.
- Win Screen when reaching the golden flag pole at the end of the level, with fireworks, bonus score calculation, and transition to the next level.
Let's implement a complete sound synthesis manager. I'll create
src/utils/audio.tsto manage all syntheses using standard Web Audio API. Let's create this file.Now let's design and create our high-fidelity, juice-packed level configurations and asset definitions. To make the level design amazing:
- We will define 3 Levels with distinct mechanics and color themes:
- Level 1: Sunlit Grasslands (Theme: Classic Green & Azure Blue Sky)
- Perfect onboarding level with simple pipes, question blocks containing coins and Super Mushrooms, a few Goombas, and a majestic high-altitude castle flag at the end.
- Level 2: Underground Magma Lair (Theme: Red-Crimson Rocks, Dark Sky, Fire Flowers)
- Intense platforms over bottomless pits, Fire Flowers in mystery boxes, faster moving Koopa Troopa enemies, and vertical pipe structures.
- Level 3: Celestial Starlight Peak (Theme: Dark Purple, Moon & Stars, Invincibility Stars, Moving platforms)
- Floating island platforms, heavy concentration of jumping/moving enemies, magical Invincibility Stars, and tricky precision jumps with high wind physics or moving platforms!
- Level 1: Sunlit Grasslands (Theme: Classic Green & Azure Blue Sky)
We can write a dedicated level-builder module or embed the levels within our main game state to ensure perfect coordination. Let's create a beautiful helper file
src/utils/levels.tsthat defines these rich levels. This keeps our mainApp.tsxclean, fully structured, and modular. Let's createsrc/utils/levels.ts.Now, let's build the interactive, polished Retro 2D Platformer game in
src/App.tsx. Let's design the visual styling, full dynamic physics engine (gravity, collision with platforms, blocks bouncing/shattering, enemies bouncing, piranha plant pops, mushroom and star power-ups physics, fireballs bouncing, juice effects, camera shakes, score popups, and full touch gamepad support with on-screen keys).Let's double-check if we need additional variables or state models. Let's program:
- Character choice with state (Classic Red, Emerald Luigi, Cyber Purple, Golden Boy).
- Local high scores saved in
localStorage. - Comprehensive canvas drawer that uses rich vibrant pixel-style vectors (and canvas text/emojis/procedural graphics) so it looks beautiful and clean.
- Sound synthesizers tied to standard buttons and keyboard triggers.
- Fireball shooting mechanics (Press 'X' or click the 'FIRE' button on touch screens).
- Particle effects system (dust, coin sparkles, star trails, block fragments, explosion puffs).
- Camera with smooth interpolation (lerp) so players get beautiful high speed horizontal movement.
Let's write this beautiful complete code inside
src/App.tsx. I will make sure it is robust, bug-free, fully responsive, and offers an incredibly juicy feedback loop (screen shakes, hit flashes, big floating text score indicators, speed particles). Let's edit/overwritesrc/App.tsx.I will now fix the TypeScript and linting errors identified in
src/App.tsx. Let's resolve:- Unused imports (React, Check, LevelConfig, EnemyTemplate, CoinTemplate, reason, anglePulse, accumulatedTime, timeStep).
- Missing type parameters or property like
animFrameoncoinobjects inside the level rendering. - Let's double check the exact lines. Let's load
src/App.tsxand fix them cleanly. I will editsrc/App.tsxto ensure a clean compilation. Let's do this.
Let's build the project using the
build_projecttool to verify that there are no compilation errors or linter warnings remaining.The build was completed flawlessly. I'll provide a friendly, detailed description of the completed 2D platformer browser game, the state-of-the-art Web Audio synthesizers, mechanics, and step-by-step guidance on how to run it.
I have completed the core request and made the loop fun, responsive, and ready to play.
Files built:
index.html,src/utils/audio.ts,src/utils/levels.ts,src/App.tsx
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.