Build a playable Super Mario Bros-style platformer game in a single HTML file using HTML5 canvas, CSS, and vanilla JavaScript โ no external libraries or assets. The final result must be clean, responsive, and fully self-contained (index.html
only).
The game should capture the core mechanics and feel of the classic Mario platformer:
-
Player Movement
- Smooth left/right movement with arrow keys or
A/D
- Jumping with
Space
orW
- Gravity, momentum, and mid-air physics that feel like classic Mario
- Smooth left/right movement with arrow keys or
-
Platforms & Level Layout
- Basic level design with ground tiles, floating platforms, gaps to jump across
- Background (simple parallax or scrolling optional)
- Put those floating bars in the sky as well like in a classic Mario game
-
Enemies (like Koopas)
- Include roaming turtle-like enemies
- If the player touches them from the side/front, they take damage or die
- If the player jumps on top of them, the enemy is defeated
-
Collision Detection
- Handle all collision logic cleanly: platforms, ground, ceilings, enemies
- Ensure precise bounding boxes for both player and enemies
-
Scoring & HUD
- Show player score and coins collected
- Display number of lives
- Optional: a simple timer (like in classic Mario)
-
Game States
- Game Over screen when player runs out of lives or falls
- Restart functionality
- Optional: Level complete condition (e.g., reach the right side or a flag)
โ โ
orA/D
โ Move left/rightSpace
orW
โ Jump- (Optional:
R
โ Restart game)
- Use Canvas to render all visuals โ tilemap, character, enemies, etc.
- Style with embedded
<style>
and script inside<script>
โ all in a singleindex.html
- Pixel-style visuals (blocky tiles, 8-bit feel) are preferred
- Use simple color fills, gradients, or inline SVG/CSS tricks to simulate sprite graphics
- Include simple animations: walking cycle, enemy movement, player death
- A single HTML file with all logic, styles, and game assets embedded
- Functional game loop using
requestAnimationFrame
- Clean, readable, and commented JavaScript code
- Fully playable and enjoyable browser experience โ no build steps or setup
Remember: this is a Mario-inspired clone, so aim for gameplay thatโs fun, responsive, and nostalgic โ even with minimal graphics. Prioritize solid mechanics, working collision logic, and enemy behavior.