A geometric tower defense game built with Phaser.js and Node.js, featuring both single-player and real-time multiplayer modes.
Geometry War is a strategic tower defense game where players control geometric units (squares, triangles, rectangles) and defensive turrets to battle against enemy forces. The game features:
- Single Player Mode: Battle against AI enemies with progressive difficulty
- Multiplayer Mode: Real-time PvP battles with friends over the network
- Unit Types: Square (tank), Triangle (ranged), Rectangle (heavy melee)
- Turret Defense: Rock Thrower and Archer Tower defensive structures
- Resource Management: Gold-based economy system
Before running the game, ensure you have:
- Node.js (v16.0.0 or higher)
- npm (comes with Node.js)
- Modern web browser (Chrome, Firefox, Safari, Edge)
- Clone or download the project to your local machine
- Navigate to the project directory:
cd geometrywar - Install dependencies:
npm install
Best for: Testing gameplay mechanics, learning controls, development
npm run dev- Access: Open your browser to
http://localhost:3000 - Features: Full single-player campaign, all units and turrets available
- Network: No server required, runs entirely in browser
Best for: Playing with friends on the same network
npm run dev:multiplayerThis command starts both:
- Game server on
http://localhost:3001 - Client on
http://localhost:3000
How to Play Multiplayer:
-
Host Player:
- Go to
http://localhost:3000 - Click "Multiplayer"
- Click "Create Room"
- Share the room code with your friend
- Go to
-
Joining Player:
- Go to
http://localhost:3000(orhttp://[HOST-IP]:3000if on different computer) - Click "Multiplayer"
- Enter the room code
- Click "Join Room"
- Go to
-
Both players click "Ready" to start the game
Best for: Playing across different computers on the same network
npm run networkThis will:
- Start the multiplayer server accessible to other devices
- Display network IP addresses for remote access
- Show connection URLs for other players
Connection URLs will be shown like:
- Local:
http://localhost:3000 - Network:
http://192.168.1.138:3000(example IP)
Best for: Dedicated server hosting
npm run server- Runs only the multiplayer server on port 3001
- Players connect using separate client instances
- Useful for persistent game hosting
Best for: Deploying the game
# Build the game
npm run build
# Preview the built game
npm run preview# Run all tests
npm test
# Run tests with UI
npm run test:ui# Single player with hot reload
npm run dev
# Multiplayer with hot reload (both server and client)
npm run dev:multiplayer- Unit Spawning: Click unit buttons (Square, Triangle, Rectangle)
- Turret Placement: Click turret button, then click turret slot
- Turret Selling: Click "Sell Turret", then click the turret to sell
- Player Side (Blue): Controls on top of screen
- Enemy Side (Red): Controls on bottom of screen
- Same controls as single player, but for your assigned side only
- Square ($15): Tank unit, high health, melee attack
- Triangle ($35): Ranged unit, projectile attack, moderate health
- Rectangle ($30): Heavy melee unit, high damage and health
- Rock Thrower ($50): Basic defensive turret
- Archer Tower ($75): Advanced ranged defense
If playing across computers, ensure port 3001 is accessible:
Windows:
netsh advfirewall firewall add rule name="Geometry War Server" dir=in action=allow protocol=TCP localport=3001macOS:
- Go to System Preferences โ Security & Privacy โ Firewall
- Add Node.js to allowed applications
Linux:
sudo ufw allow 3001/tcpWindows:
ipconfig | findstr "IPv4"macOS/Linux:
ifconfig | grep "inet ""Cannot connect to server"
- Ensure the server is running (
npm run serverornpm run dev:multiplayer) - Check if port 3001 is available and not blocked by firewall
- Verify the correct IP address for network play
"Room not found"
- Make sure both players are connected to the same server
- Verify the room code is entered correctly
- Try creating a new room
Units not spawning
- Check if you have sufficient gold (displayed at top of screen)
- Ensure you're in an active game (both players ready)
- Look for error messages in browser console (F12)
Performance issues
- Close other browser tabs
- Ensure stable network connection for multiplayer
- Try refreshing the page
Open browser console (F12) to see detailed game logs including:
- Unit spawning attempts and results
- Network connection status
- Gold transactions
- Turret placement and selling events
- Check the browser console for error messages
- Verify network connectivity and firewall settings
- Ensure all players are using the same game version
- Try restarting the server and reconnecting
geometrywar/
โโโ src/
โ โโโ scenes/ # Game scenes (Menu, Game, Multiplayer)
โ โโโ units/ # Unit classes and configurations
โ โโโ turrets/ # Turret classes and configurations
โ โโโ network/ # Network management
โ โโโ test/ # Test files
โโโ server.js # Multiplayer server
โโโ package.json # Dependencies and scripts
โโโ README.md # This file
npm run dev- Development mode (single player)npm run dev:multiplayer- Development mode (multiplayer)npm run server- Server onlynpm run network- Network multiplayernpm run build- Production buildnpm run preview- Preview production buildnpm test- Run testsnpm run test:ui- Run tests with UI
- Start with single player to learn the game mechanics
- Use local network for the smoothest multiplayer experience
- Ensure stable internet when playing across different networks
- Check console logs if you encounter any issues
- Both players should ready up to start multiplayer games
Enjoy playing Geometry War! ๐ฎโจ