A complete React-based 2D platformer game built with Three.js and React Three Fiber. This project provides both a working game implementation and clean boilerplate code for new game development.
- Player Movement: Smooth WASD/arrow key controls with physics-based movement
- Jump Mechanics: Realistic jumping with gravity and ground detection
- Platform System: Multi-level platforms with AABB collision detection
- Physics Engine: Custom collision detection and response system
- Game States: Ready, playing, paused, and ended states with UI transitions
- Scoring System: Points for jumping and level progression
- Audio Support: Background music and sound effects management
- Responsive UI: Clean overlay interface with game controls
- Level System: Multiple levels with increasing difficulty
- Clean Architecture: Modular, extensible codebase structure
- Node.js 18+
- npm or yarn package manager
- Clone the repository:
git clone https://github.com/rtre84/random-2d-platformer.git
cd random-2d-platformer- Install dependencies:
npm install- Start the development server:
npm run dev- Open your browser and navigate to
http://localhost:5173
- A / โ - Move left
- D / โ - Move right
- W / โ / Space - Jump
- R - Restart game
โโโ client/src/
โ โโโ BoilerplateApp.tsx # Main app entry point
โ โโโ components/
โ โ โโโ SimpleGame.tsx # Game scene management
โ โ โโโ SimplePlayer.tsx # Player character logic
โ โ โโโ SimplePlatform.tsx # Platform components
โ โ โโโ SimpleGameUI.tsx # UI overlay
โ โ โโโ SoundManager.tsx # Audio management
โ โโโ lib/
โ โโโ stores/
โ โ โโโ useGame.tsx # Game state management
โ โ โโโ useAudio.tsx # Audio state management
โ โโโ physics.ts # Collision detection & physics
โโโ server/ # Express.js backend
โโโ shared/ # Shared types and schemas
โโโ GAME_BOILERPLATE.md # Detailed documentation
- React 18 - UI framework with functional components and hooks
- React Three Fiber - 3D rendering engine wrapper for Three.js
- Three.js - Core 3D graphics library for game rendering
- Zustand - Lightweight state management
- TypeScript - Static type checking
- Vite - Fast development server and build tool
- Express.js - RESTful API server
- TypeScript - Full-stack type safety
- Drizzle ORM - Type-safe database toolkit
- Custom Physics - AABB collision detection system
- Component Architecture - Modular game object system
- Audio Management - Browser-native Audio API integration
Edit generatePlatforms() in client/src/lib/stores/useGame.tsx:
platforms.push({
position: { x: 5, y: 3, z: 0 },
size: { width: 3, height: 1, depth: 2 },
color: "#FF5722"
});Modify constants in client/src/lib/physics.ts:
export const PHYSICS_CONSTANTS = {
GRAVITY: -25, // How fast player falls
JUMP_FORCE: 12, // Jump strength
MOVE_SPEED: 8, // Horizontal movement speed
FRICTION: 0.85, // Sliding friction
MAX_FALL_SPEED: -20, // Terminal velocity
MAX_MOVE_SPEED: 15 // Max horizontal speed
};Update styles in client/src/components/SimpleGameUI.tsx for custom appearance.
Place audio files in client/public/sounds/:
background.mp3- Background musichit.mp3- Collision soundsuccess.mp3- Success/scoring sound
The game handles missing audio files gracefully.
This project is optimized for Replit deployment:
- Import the project to Replit
- The project will auto-configure
- Click "Run" to start the development server
- Use the "Deploy" button for production deployment
- Build the project:
npm run build- The built files will be in the
dist/directory - Deploy to your preferred hosting service (Vercel, Netlify, etc.)
- Complete Game Documentation - Detailed guide for customization and extension
- Physics System - Collision detection implementation
- State Management - Game and audio state management
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is open source and available under the MIT License.
This boilerplate provides a solid foundation. Consider adding:
- Enemies: Moving obstacles or AI characters
- Collectibles: Coins, power-ups, or items
- Moving Platforms: Elevators or sliding platforms
- Checkpoints: Save points in longer levels
- Lives System: Multiple attempts before game over
- Mobile Controls: Touch/swipe controls for mobile devices
- Level Editor: In-game platform placement tool
- Save System: LocalStorage for progress persistence
- Multiplayer: WebSocket-based multiplayer support
- Better Graphics: Textures, animations, particle effects
If you have questions or need help:
- Check the documentation
- Look through existing issues
- Create a new issue with detailed information
Happy Coding! ๐ฎโจ
Built with โค๏ธ using React Three Fiber and TypeScript
