A side-scrolling platformer game built with TypeScript and HTML5 Canvas. Control Mario through an interactive world, collect coins, and explore the basic mechanics of a classic platformer game.
- Node.js (for TypeScript compilation)
- Python 3 (for local HTTP server) or any other static file server
- A modern web browser (Chrome, Firefox, Safari, Edge)
-
Clone the repository:
git clone <repository-url> cd ec26-coding-agents
-
Install dependencies:
npm install
Compile TypeScript source files to JavaScript:
npm run buildThis compiles all .ts files from the src/ directory into the dist/ directory.
For development with automatic recompilation on file changes:
npm run watchStart a local HTTP server:
npm run serveThen open your browser to:
http://localhost:8000
Alternatively, you can build and serve in one command:
npm run dev- A - Move Left
- D - Move Right
The project follows a modular, object-oriented architecture:
src/
├── constants.ts # Game configuration (dimensions, colors, speeds)
├── SpriteSheet.ts # Sprite loading and rendering with flip support
├── Camera.ts # Scrolling camera that follows the player
├── Player.ts # Player character with movement and animation
├── Coin.ts # Collectible coins with collision detection
├── Level.ts # Level design, platforms, decorations, parallax
├── HUD.ts # Heads-up display with score tracking
├── Game.ts # Main game loop and state management
└── main.ts # Entry point and initialization
dist/ # Compiled JavaScript output (auto-generated)
assets/ # Sprite sheets and graphics
Game (src/Game.ts)
- Main game loop using
requestAnimationFrame - Coordinates all game components
- Handles updates and rendering
Player (src/Player.ts)
- Keyboard input handling (A/D keys)
- Sprite animation with walk cycles
- Boundary collision detection
- Character position and movement
Level (src/Level.ts)
- Platform definitions
- Decorative elements (trees, bushes)
- Parallax scrolling effects
- Ground and sky rendering
Camera (src/Camera.ts)
- Follows player with smooth scrolling
- Maintains level boundaries
- Provides viewport offset for rendering
Coin (src/Coin.ts)
- Collision detection with player
- Collection state management
- Animated rendering
HUD (src/HUD.ts)
- Score display
- Win condition detection
- UI rendering
The project uses strict TypeScript settings with:
- ES2020 target for modern JavaScript features
- Strict type checking enabled
- Source maps for debugging
- Declaration files (.d.ts) for type definitions
- HTML5 Canvas for 2D graphics
- Pixel-perfect rendering with
imageSmoothingEnabled: false - 60 FPS game loop using
requestAnimationFrame - Sprite sheet animation with frame cycling
The game follows these design principles:
- Modular components: Each class has a single responsibility
- Type safety: All data structures are properly typed
- Scalability: Easy to add new features (jump mechanics, enemies, levels)
- Clean separation: Update logic separated from rendering
The architecture is ready for:
- Jump mechanics and gravity physics
- Enemy AI and collision
- Multiple levels
- Power-ups and special abilities
- Sound effects and music
- Mobile touch controls
- Edit TypeScript files in
src/ - Run
npm run build(or keepnpm run watchrunning) - Refresh browser to see changes
Source maps are enabled, so you can debug TypeScript directly in browser DevTools:
- Open Developer Tools (F12)
- Go to Sources tab
- Find files under
webpack://orsrc/ - Set breakpoints in TypeScript code
MIT