Skip to content

liukun2634/stack-tower-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Stack Tower ๐Ÿ—๏ธ

A casual arcade stacking game built with vanilla HTML5 Canvas. A block swings from a crane โ€” tap to drop it onto the tower. Overhang gets cut off, making precision crucial. Features adaptive AI difficulty, procedural building skins, background music, and sound effects.

Play Now

How to Play

  1. Tap / Click / Space to start the game
  2. Watch the block swing from the crane
  3. Tap / Click / Space to release the block
  4. Land it on the tower as precisely as possible
  5. Overhang gets cut off โ€” the tower narrows with each miss
  6. Perfect landing (>95% overlap) earns bonus points and combo multipliers
  7. Game ends when you miss the tower completely

Game Features

  • Swinging crane mechanics โ€” block swings on a rope pendulum
  • Adaptive difficulty โ€” game gets harder as you improve, eases off when you struggle
  • Procedural building skins โ€” each floor has unique colors, windows, doors, and decorations
  • Combo system โ€” consecutive perfect landings multiply your score (Nice! / Amazing! / Legendary!)
  • Score popups โ€” floating "+N" text on each landing
  • Background music โ€” cheerful procedural melody (~40s loop) with bass line
  • Sound effects โ€” landing, perfect, combo milestone, game over
  • Mute toggle โ€” click icon or press M, persists across sessions
  • Smooth camera โ€” parallax clouds and auto-scrolling as your tower grows
  • Best score โ€” saved locally, persists across sessions

Controls

Input Action
Click / Tap Drop block / Start / Retry
Space Drop block / Start / Retry
M Toggle mute
Mute icon (top-right) Toggle mute

Run Locally

Option 1: Local HTTP Server (Recommended)

The game uses ES modules, which require a server in most browsers.

Using Node.js:

npx serve stack-tower-game

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

Using Python:

cd stack-tower-game
python -m http.server 8080

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

Option 2: VS Code Live Server

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

Project Structure

stack-tower-game/
โ”œโ”€โ”€ index.html          # Entry point
โ”œโ”€โ”€ css/
โ”‚   โ””โ”€โ”€ style.css       # Responsive layout
โ””โ”€โ”€ js/
    โ”œโ”€โ”€ main.js         # Init, events, game loop
    โ”œโ”€โ”€ game.js         # State machine, scoring, combos
    โ”œโ”€โ”€ block.js        # Swing, drop, landing mechanics
    โ”œโ”€โ”€ tower.js        # Block stack + camera scrolling
    โ”œโ”€โ”€ renderer.js     # All Canvas drawing
    โ”œโ”€โ”€ ai.js           # Difficulty scaling + procedural skins
    โ”œโ”€โ”€ audio.js        # Web Audio API synthesis (BGM + SFX)
    โ””โ”€โ”€ utils.js        # Math helpers

Tech Stack

  • HTML5 Canvas
  • Vanilla JavaScript (ES modules)
  • Web Audio API (procedural synthesis, zero audio files)
  • Zero external dependencies
  • Total size < 100KB

Debug

  1. Open the game in your browser
  2. Press F12 to open DevTools
  3. Console tab โ€” check for errors
  4. Sources tab โ€” set breakpoints in any JS file

Common Issues

Issue Fix
Blank screen Check console for module import errors. Use a local server.
Modules not loading ES modules require HTTP/HTTPS, not file://.
Touch not working Ensure touch-action: none in CSS. Test on actual device or DevTools mobile emulation.

License

MIT

About

๐Ÿ—๏ธ A casual arcade stacking game built with vanilla HTML5 Canvas โ€” swinging crane, adaptive difficulty, procedural building skins, and Web Audio API synthesis. ๐ŸŽฎ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors