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'll build a complete 2D platformer game similar to Super Mario. Let me start by exploring the project structure and then create all the necessary files.
Now I'll create a complete 2D platformer game. Let me create the game engine files first:
Let me create the Player class:
Now let me create the Enemy class:
Let me create the Coin class:
Now let me create the Particle class:
Now let me create the PowerUp class:
Let me fix the PowerUp class:
Now let me update the GameEngine to fix the issues:
Let me rewrite the GameEngine to fix the compatibility issues:
Let me fix the remaining issues. First, let me update the Player class:
Now let me fix the Enemy class:
Now let me fix the GameEngine touch handling:
Now let me fix the PowerUp class:
Now let me create the main Game component that integrates with React:
Let me fix the deltaTime issue:
Now let me update the main App.tsx to use the Game component:
Now let me update the index.html with a proper title:
Let me fix the renderGameOverScreen method in GameEngine.ts which is rendering both screens:
Let me update the Game.tsx to fix the rendering logic:
Let me read and rewrite the Game.tsx file:
Let me rewrite the Game.tsx file properly:
Now let me build the project to check for any remaining issues:
The build succeeded! Let me verify the main.tsx file:
Let me check the index.css file:
Let me fix the Player class to not require the deltaTime parameter since we're not using it:
Let me update the index.html with better mobile viewport settings:
Let me run the build again to verify everything works:
Let me verify the built file:
Let me verify all the files are in place:
Let me check the tsconfig to ensure we have proper TypeScript settings:
The build succeeded with all 37 modules transformed. Let me verify everything is working by checking the key files:
Let me run one final build to confirm everything is working:
The 2D Mario-style platformer game is now complete and builds successfully! Here's a summary of what was created:
Game Files Created
Core Game Engine (
src/game/):- GameEngine.ts - Main game loop, state management, physics, collision detection
- Player.ts - Player character with movement, jumping, and power-up mechanics
- Enemy.ts - Enemies that patrol platforms and can be defeated by jumping on them
- Coin.ts - Collectible coins that increase score
- Particle.ts - Particle effects for visual feedback (coin collection, stomp effects, etc.)
- PowerUp.ts - Power-up items that temporarily grow the player
- Game.tsx - React component that integrates the canvas game with React
Game Features Implemented
- Player Controls: Arrow keys/WASD for movement, Space/Up for jumping, touch support for mobile
- Physics: Realistic gravity, collision detection with platforms
- Enemies: Patrolling enemies that can be defeated by jumping on them
- Items: Coin collection with score tracking, power-ups that grow the player
- UI: Score display, health hearts, start menu, game over screen, high scores
- Audio: Web Audio API-generated jump, coin, and enemy sounds
- Visual Effects: Particle effects, screen shake on damage
- Mobile Support: Touch controls, responsive viewport settings
How to Play
- Desktop: Arrow keys/WASD to move, Space/Up to jump, Enter to start, 1 for high scores, R to restart
- Mobile: Tap top half to jump, Enter to start
- Collect coins (+10 points each) and defeat enemies (+50 points each)
- Get a power-up to temporarily grow and defeat enemies by jumping on them
- Enter your name on game over to save to high scores
Build Output
The game builds to a single
dist/index.htmlfile (229 KB gzipped, 69 KB gzipped) that can be served directly in any modern browser with no external dependencies.Files built:
src/game/GameEngine.ts,src/game/Player.ts,src/game/Enemy.ts,src/game/Coin.ts,src/game/Particle.ts,src/game/PowerUp.ts,src/game/Game.tsx,src/App.tsx,index.html
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.