Skip to content

Latest commit

ย 

History

History
124 lines (92 loc) ยท 4 KB

File metadata and controls

124 lines (92 loc) ยท 4 KB

๐Ÿธ Frogger (HTML5 Canvas)

A fully playable Frogger-style arcade game built from scratch using vanilla JavaScript (ES6 modules) and HTML5 Canvas.
This project focuses on game fundamentals, including game loops, collision detection, sprite animation, and state management โ€” without using any external game engines or build tools.


๐ŸŽฎ Features

  • Classic Frogger gameplay
  • Multi-layer canvas rendering (background, sprites, UI)
  • Custom game loop and timing system
  • Collision detection (vehicles, logs, river)
  • Score, lives, and countdown timer
  • Start screen and end-game screen (win / game over)
  • Sprite atlas rendering

๐Ÿ›  Technologies Used

  • JavaScript (ES6 Modules)
  • HTML5 Canvas
  • CSS
  • No external libraries or frameworks
  • No build tools required

๐Ÿš€ How to Run

Because the game uses ES6 modules, it must be served over HTTP (not opened directly as a file:// URL).

Option 1 โ€” VS Code Live Server

  1. Install the Live Server extension.
  2. Right-click sources/index.html โ†’ Open with Live Server.

Option 2 โ€” Python HTTP server

cd sources
python3 -m http.server 8080

Then open http://localhost:8080 in your browser.

Option 3 โ€” Node.js serve

npx serve sources

๐ŸŽฏ Controls

Action Key
Move Up Arrow โ†‘
Move Down Arrow โ†“
Move Left Arrow โ†
Move Right Arrow โ†’

Click Start to begin or Play Again after game over.


๐Ÿง  Architecture Overview

The game is split into ES6 modules inside sources/modules/ for a clean separation of concerns:

sources/
โ”œโ”€โ”€ index.html          # HTML shell with three canvas layers
โ”œโ”€โ”€ index.js            # Entry point โ€” wires event listeners and boots the game
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ sprites.png     # Sprite atlas (all game graphics)
โ”‚   โ””โ”€โ”€ dead.png        # Death animation image
โ””โ”€โ”€ modules/
    โ”œโ”€โ”€ Sprite.js       # Sprite class (position, size, atlas coordinates)
    โ”œโ”€โ”€ Lane.js         # Lane constructor (direction, speed, sprites, river flag)
    โ”œโ”€โ”€ entities.js     # All sprite and lane instances
    โ”œโ”€โ”€ state.js        # Shared mutable state (frog, player, canvases, images)
    โ”œโ”€โ”€ collision.js    # Point and box collision detection helpers
    โ”œโ”€โ”€ renderer.js     # All canvas drawing functions
    โ””โ”€โ”€ game.js         # Game loop, input handling, win/lose logic

Three Canvas Layers

Layer Canvas ID Purpose
Background backgroundCanvas Static environment, HUD
Sprites spriteCanvas Moving vehicles and logs
Interface interfaceCanvas Frog, overlays, start/end screen

Core Concepts Implemented

  • Manual game loop via setInterval
  • State-based game flow (start โ†’ playing โ†’ end)
  • Axis-aligned bounding box (AABB) collision detection
  • Sprite atlas rendering with source-rectangle slicing
  • Object movement with screen-edge wrapping

๐Ÿšง Next Steps

Planned improvements include:

  • ๐Ÿ” Rewrite the game in C++

    • Implement the same mechanics using C++ and a lightweight graphics library (SFML or SDL)
    • Recreate the game loop, collision detection, and entity system
    • Compare architectural differences between JavaScript and C++
    • Explore memory management, ownership, and performance considerations
  • ๐Ÿงฑ Improve architecture

    • Introduce a Game class to own global state
    • Convert entities (Frog, Vehicles, Logs) into reusable components
  • ๐ŸŽฎ Gameplay improvements

    • Difficulty scaling
    • Level progression
    • Improved collision precision
    • Sound effects and animations

The goal is to use this project as a cross-language gameplay engineering exercise.