A pixel-style terrain exploration game built with SvelteKit, TypeScript, and Web Workers. This project demonstrates modern web game development techniques with a focus on performance and maintainability.
- 🎮 Real-time terrain exploration
- 👷 Web Worker-based game logic
- 📊 Performance monitoring
- 🎨 Dynamic animations (clouds, water, rivers)
- 🎯 Responsive controls
- 📱 Mobile-friendly design
- 🌈 Theme support
- 🛠 Debug tools
- Framework: SvelteKit
- Language: TypeScript
- Styling: Tailwind CSS
- Architecture: Web Workers for game logic
- Performance: RAF-based animation system
- State Management: Custom game state handler
- 🌊 Water (W) - Impassable boundary
- 🏖 Beach (B) - Transitional zone
- 🌲 Forest (F) - Standard terrain with cover
- ⛰ Mountains (M) - Impassable peaks
- 🌱 Grassland (G) - Open terrain
- 🌊 River (R) - Crossable water
- 🥾 Swamp (S) - Difficult terrain
- 🏔 Hills (H) - Elevated terrain
- Cloud system with dynamic generation and movement
- Water wave effects
- River flow animations
- Character movement with direction-based sprites
- FPS monitoring
- Memory usage tracking
- Idle state management
- Frame throttling
- Efficient canvas rendering
- Real-time performance metrics
- Game state monitoring
- Terrain information
- Worker status tracking
- Animation controls
src/
├── lib/
│ ├── components/
│ │ └── DebugPanel.svelte # Performance monitoring component
│ │ └── Controls.svelte # Game controls component
│ ├── game/
│ │ ├── Game.ts # Main game logic
│ │ ├── draw.ts # Canvas rendering functions
│ │ └── state.ts # Game state management
│ ├── workers/
│ │ └── worker.ts # Web Worker game logic
│ ├── types.ts # TypeScript definitions
│ └── theme.ts # Theming system
└── routes/
└── +page.svelte # Main game component
Web Workers allow you to run JavaScript in background threads. They can perform tasks without interfering with the user interface. This is especially useful for tasks that are computationally expensive or need to run asynchronously.
graph TD;
A[Main Thread] -->|On Message| B[Web Worker]
B -->|Post Message| A
A -->|Render| C[Canvas]
B -->|Game Logic| D[Game State]
- Main Thread: Handles rendering and user input.
- Web Worker: Processes game logic and state management.
- Communication: Main thread and worker communicate via
postMessage
andonmessage
. - Rendering: Main thread updates the canvas based on the game state.
const worker = new Worker('worker.js');
worker.onmessage = (e) => {
const { gameState } = e.data;
// Update the game state and render
};
worker.postMessage({ task: 'START' });
self.onmessage = (e) => {
const { task } = e.data;
if (task === 'START') {
// Initialize game state
postMessage({ gameState });
}
};
-
Terrain System
- Different terrain types with unique properties
- Collision detection
- Movement cost calculations
-
Animation System
- Cloud generation and movement
- Water wave effects
- River flow animations
- Character animations
-
Performance Optimization
- Web Worker offloading
- Frame rate management
- Idle state handling
- Memory monitoring
-
Debug Tools
- FPS counter
- Memory usage
- Game state viewer
- Animation controls
- Arrow keys or WASD for movement
- Toggle panels:
- Debug information
- Terrain legend
- Animation settings
- Install dependencies:
bun install
- Start development server:
bun run dev
- Build for production:
bun run build
The game uses a multi-threaded architecture:
- Main Thread: Handles rendering and user input
- Web Worker: Processes game logic and state management
- RAF Loop: Manages animations and frame timing
- Event System: Coordinates state updates
- Web Worker offloads computation
- Frame throttling based on idle state
- Efficient canvas rendering
- Memory usage optimization
- Animation frame management
MIT License - Feel free to use and modify
Created as a demonstration of modern web game development techniques using SvelteKit and TypeScript.