A modern, feature-rich implementation of the classic 2048 puzzle game built with TypeScript and Phaser 3.
- Classic 2048 mechanics - Slide tiles to merge matching numbers
- Smooth animations - Fluid tile movements with elastic easing
- Win condition - Reach 2048 to win (with option to continue)
- Game over detection - Automatic detection when no moves available
- Keyboard: Arrow keys or WASD
- Touch: Swipe gestures on mobile/tablet devices
- Responsive: Works on desktop, tablet, and mobile
- Beautiful color scheme - Gradient tiles with distinct colors for each value
- Particle effects - Visual feedback on tile merges
- Smooth transitions - All animations use optimized easing functions
- Score animations - Dynamic score updates with visual feedback
- Score tracking - Current score and personal best
- LocalStorage persistence - Best score saved between sessions
- New game button - Quick restart at any time
- Win/Game Over overlays - Clear game state communication
- Continue playing - Option to play beyond 2048
- Node.js (v16 or higher)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd 2048-game
-
Install dependencies
npm install
-
Start development server
npm start
The game will open automatically in your browser at
http://localhost:8080 -
Build for production
npm run build
The production build will be in the
dist/directory
Combine tiles with the same number to create larger numbers. Reach 2048 to win!
- Use arrow keys (↑ ↓ ← →) or WASD to move tiles
- When two tiles with the same number touch, they merge into one
- After every move, a new tile (2 or 4) appears in an empty spot
- The game is won when a 2048 tile is created
- The game is over when no moves are possible
- Keep your highest tile in a corner
- Build tiles in a specific pattern (e.g., snake pattern)
- Don't move your highest tile unless necessary
- Plan ahead - think about where new tiles might appear
2048-game/
├── src/
│ ├── scenes/
│ │ ├── BootScene.ts # Asset loading and initialization
│ │ └── GameScene.ts # Main game scene
│ ├── game-objects/
│ │ ├── Tile.ts # Individual tile with animations
│ │ └── Grid.ts # 4x4 grid manager
│ ├── managers/
│ │ ├── GameManager.ts # Core game logic
│ │ ├── InputManager.ts # Input handling (keyboard/touch)
│ │ ├── ScoreManager.ts # Score tracking & persistence
│ │ └── AnimationManager.ts # Particle effects
│ ├── ui/
│ │ ├── ScoreDisplay.ts # Score UI components
│ │ ├── GameOverlay.ts # Win/lose overlays
│ │ └── Button.ts # Interactive buttons
│ ├── utils/
│ │ ├── Constants.ts # Game constants
│ │ └── ColorScheme.ts # Tile color mappings
│ ├── config.ts # Phaser configuration
│ └── main.ts # Entry point
├── public/
│ ├── index.html # HTML template
│ └── assets/ # Game assets (if any)
├── package.json
├── tsconfig.json
└── webpack.config.js
- TypeScript - Type-safe development with strict mode
- Phaser 3 - Professional game framework for 2D games
- Webpack - Module bundling and hot reload
- Object-Oriented Design - Clean separation of concerns
- 60 FPS animations - Smooth gameplay on all devices
- Efficient rendering - Canvas-based rendering with Phaser
- Minimal DOM manipulation - Game runs entirely on canvas
- Optimized algorithms - Efficient grid traversal and collision detection
- Tile spawn: Elastic bounce-in (400ms)
- Tile move: Cubic easing (250ms)
- Tile merge: Pop effect with scale (150ms)
- Score updates: Smooth counter animation
- Particle effects: Dynamic effects on merges
- Chrome/Edge (latest)
- Firefox (latest)
- Safari (latest)
- Mobile browsers (iOS Safari, Chrome Mobile)
# Start development server with hot reload
npm start
# Build for production
npm run build
# Watch mode for development
npm run devThe codebase is designed for easy extension:
- New tile animations: Modify
Tile.ts - Different grid sizes: Update
Constants.ts(GRID_SIZE) - Custom color schemes: Modify
ColorScheme.ts - New game modes: Extend
GameManager.ts - Sound effects: Add to
BootScene.tspreload and trigger in game events
- Original 2048 game by Gabriele Cirulli
- Built with Phaser 3
- Developed with TypeScript
MIT License - Feel free to use this code for learning or in your own projects!
Potential features for future versions:
- Sound effects and background music
- Multiple grid sizes (3x3, 5x5)
- Undo functionality
- Hints system
- Achievements system
- Leaderboard (online)
- Different themes/skins
- Tutorial mode
Enjoy the game! Try to reach 2048! 🎮