A fully-featured 3D racing game built with Three.js, featuring AI opponents, powerups, multiple tracks, and neural network training.
- 3D Racing: Full 3D kart racing with realistic physics
- Multiple Tracks: Circuit, Desert, and Snow environments
- 3-Lap Races: Complete with checkpoints to prevent cheating
- 4 Players: 1 human player + 3 AI opponents
- Boost: Temporary speed increase
- Missile: Homing projectile that stops opponents
- Mine: Stationary explosive trap
- Neural Networks: AI opponents use trained neural networks
- Reinforcement Learning: Train AI using genetic algorithms
- Multiple Models: Separate models for each track
- CLI Training: Train AI from command line
- Movement: WASD or ZQSD (AZERTY support), Arrow keys, or Numpad 8/2/4/6
- Powerup: Spacebar or Numpad 0
- Camera: Automatic following camera
- Web Audio API: Procedural sound generation
- Buffered Sounds: Efficient audio playback
- Music: Background soundtrack
- SFX: Engine, collision, powerup sounds
- Start Screen: Semi-transparent overlay with autoplay
- Statistics: Real-time FPS, position, lap, powerup
- Responsive: Adapts to screen size
- Node.js 14+ installed
- Modern web browser with WebGL support
-
Clone the repository:
git clone <repository-url> cd kartio
-
Install dependencies:
npm install
-
Start the game:
npm start
-
Open your browser: Navigate to
http://localhost:8000
Train AI opponents using reinforcement learning:
# Train for 50 generations (default)
npm train
# Train for specific generations
npm train 100
# Train for desert track
npm train 75 desert# Run all tests
npm test
# Run with coverage
npm run test:coverage# Start development server
npm start
# Server runs on http://localhost:8000- Realistic kart physics with momentum and friction
- Collision detection between karts and obstacles
- Checkpoint system prevents cheating
- Invulnerability frames after being hit
- Pathfinding using neural networks
- Dynamic difficulty based on training
- Powerup usage strategic deployment
- Racing lines optimized for each track
- Circuit Track: Classic racing circuit with red barriers
- Desert Track: Sandy terrain with cacti obstacles
- Snow Track: Winter landscape with pine trees
kartio/
โโโ src/
โ โโโ js/ # Game source code
โ โ โโโ GameEngine.js # Main game engine
โ โ โโโ Kart.js # Kart physics and rendering
โ โ โโโ NeuralNetwork.js # AI neural network
โ โ โโโ AIController.js # AI behavior
โ โ โโโ Powerup.js # Powerup system
โ โ โโโ Track.js # Track generation
โ โ โโโ AudioManager.js # Audio system
โ โ โโโ main.js # Entry point
โ โโโ training/ # AI training
โ โ โโโ cli.js # Training CLI
โ โโโ tracks/ # Track configurations
โ โโโ audio/ # Audio assets
โ โโโ models/ # Trained AI models
โโโ tests/ # Jest tests
โโโ index.html # Main HTML file
โโโ package.json # Dependencies
โโโ server.js # Express server
โโโ jest.config.js # Test configuration
const game = new GameEngine();
game.startGame(); // Start player game
game.startAutoplay(); // Start AI-only game
game.stop(); // Stop gamenode src/training/cli.js [generations] [track]const network = new NeuralNetwork(inputSize, hiddenSize, outputSize);
network.forward(inputs); // Forward propagation
network.mutate(rate); // Genetic mutation- Chrome: 88+
- Firefox: 85+
- Safari: 14+
- Edge: 88+
- 60 FPS on modern hardware
- WebGL rendering for smooth graphics
- Optimized AI for real-time performance
- Efficient audio with buffered playback
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new features
- Run tests:
npm test - Submit a pull request
MIT License - see LICENSE file for details
Game won't start:
- Ensure WebGL is enabled in your browser
- Check browser console for errors
- Try refreshing the page
AI not moving:
- Ensure models are trained:
npm train 50 - Check models/ directory for .json files
- Restart the server
Audio not working:
- Click anywhere on the page to enable audio
- Check browser audio permissions
- Try a different browser
- Close other tabs to free up memory
- Update browser to latest version
- Disable browser extensions that may interfere
- Use Chrome for best performance
- Initial release
- 3D racing with physics
- AI opponents with neural networks
- Powerup system
- Multiple tracks
- Audio system
- Training CLI