This project is about creating a website for the mighty Pong contest!
https://www.notion.so/transcendence-20ed2fbe756e8096b213eaec9850f049 https://www.notion.so/ft_transcendence-20d8ccef5a8a80d88122e5a2d67d06f0
https://www.npmjs.com/package/@fastify/websocket
- Dual Mode Gaming: Classic 2D mode and immersive 3D split-screen mode
- Multiple Game Modes:
- Single Player (vs AI)
- Local 2 Players
- Online 2 Players
- Tournaments
- Real-time Multiplayer: WebSocket-based networking for responsive gameplay
- Multi-language Support: English, Italian, French, Portuguese, Russian
- Responsive Design: Optimized for different screen sizes
2D Classic Mode:
- Player 1:
W(up) /S(down) - Player 2:
↑(up) /↓(down)
3D Immersive Mode:
- Player 1:
A(left) /D(right) - Player 2:
←(left) /→(right)
ESC: Pause/Resume gameY: Confirm exit (when paused)N: Cancel exit (when paused)
- Use
←/→arrows in the main menu to cycle through languages
ft_transcendence/
├── backend/ # Node.js + Fastify backend
│ ├── src/
│ │ ├── game/ # Game logic (Ball, Paddle, Game classes)
│ │ ├── network/ # WebSocket handling
│ │ ├── shared/ # Shared types and constants
│ │ └── config/ # Configuration files
│ ├── Dockerfile
│ └── package.json
├── frontend/ # TypeScript + Babylon.js frontend
│ ├── src/
│ │ ├── core/ # Main application logic
│ │ ├── engine/ # Babylon.js engine and scene building
│ │ ├── game/ # Game managers (Input, Network, GUI)
│ │ ├── shared/ # Shared types and constants
│ │ ├── translations/ # Multi-language support
│ │ └── ui/ # UI management
│ ├── Dockerfile
│ └── package.json
├── shared/ # Shared files between frontend/backend that will be copied in backend and frontend during building to avoid duplication
├── docker-compose.yml
├── Makefile
└── README.md
Backend:
- Fastify: Fast and efficient web framework
- @fastify/websocket: WebSocket support for real-time communication
- TypeScript: Type-safe development
Frontend:
- Babylon.js: 3D graphics engine for immersive mode
- TypeScript: Type-safe client-side development
- Native WebSocket: Real-time communication with backend
- Tailwind: Framework CSS for styling
- Docker and Docker Compose
- Make (optional, for convenience commands)
-
Clone the repository git clone cd ft_transcendence
-
Build and start the application
make run ----> I'm using docker-compose. need to check if it's ok
-
Access the game
- Open your browser and navigate to:
http://localhost:8443 - The backend WebSocket server runs on:
ws://localhost:3000
- Open your browser and navigate to:
make run # Build and start all services make build # Build both frontend and backend make build-frontend # Build frontend only make build-backend # Build backend only
make start # Start containers make stop # Stop containers make restart # Restart containers make ps # Show container status
make logs # Show all logs make logs-frontend # Show frontend logs make logs-backend # Show backend logs
make clean # Stop containers and remove orphans make fclean # Remove containers, images, and volumes make wipe-all # Remove all Docker artifacts make wipe-images # Remove all Docker images
make update-deps # Update npm dependencies make update # Update deps and rebuild
Create a .env file in the root directory: -----> for this simple setup, it should work even without as we have default numbers
BACKEND_HOST=0.0.0.0 BACKEND_PORT=3000 DEBUG=no
FRONTEND_PORT=8080
Ball Class (backend/src/core/Ball.ts)
- Handles ball physics, movement, and collision detection
- Manages scoring and reset logic
Paddle Classes (backend/src/core/Paddle.ts)
Player: Human-controlled paddleAIBot: AI-controlled paddle with prediction algorithm
Game Classes (backend/src/core/game.ts)
SinglePlayer: Game mode with AI opponentTwoPlayer: Game mode for human vs human
WebSocket Management (backend/src/network/WebSocketManager.ts)
- Handles client connections and message routing
- Manages game sessions and player input
BabylonEngine (frontend/src/engine/BabylonEngine.ts)
- Manages Babylon.js engine lifecycle
- Handles scene creation for 2D/3D modes
Scene Builder (frontend/src/engine/sceneBuilder.ts)
- Creates game objects (paddles, ball, field)
- Sets up cameras and lighting for both modes
NetworkGameManager (frontend/src/game/NetworkGameManager.ts)
- Manages WebSocket communication
- Updates game objects based on server state
Input Manager (frontend/src/game/InputManager.ts)
- Handles keyboard input
- Sends player actions to server
The game uses WebSocket communication with JSON message format:
interface ClientMessage {
type: MessageType;
gameMode?: GameMode;
side?: number;
direction?: Direction;
}interface ServerMessage {
type: MessageType;
state?: GameStateData;
side?: number;
message?: string;
}JOIN_GAME: Client requests to join a gamePLAYER_INPUT: Client sends player movementGAME_STATE: Server broadcasts game state updatesGAME_STARTED: Server confirms game startERROR: Server reports errors
-
Port already in use
make stop # Or change ports in .env file -
WebSocket connection fails
- Ensure backend is running on port 3000
- Check browser console for connection errors
- Verify no firewall blocking WebSocket connections
-
Frontend not loading
- Check if nginx is serving files correctly
- Verify frontend build completed successfully
- Check browser console for JavaScript errors
-
Docker build failures
make fclean # Clean everything make run # Rebuild from scratch
Enable debug logging: ------> Removed most of logs, I kept only the failing
echo "DEBUG=yes" >> .env
make restart
make logs-backend- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Test thoroughly
- Commit:
git commit -m "Add feature description" - Push:
git push origin feature-name - Create a Pull Request
- Use TypeScript for all new code
- Follow existing naming conventions
- Add JSDoc comments for public functions
- Update shared types in
/sharedwhen needed
This project is part of the 42 School curriculum.



