Game demo collection using raylib in Python
Explore game loops โข 2D/3D graphics โข Physics simulation โข Interactive demos
This repository presents a variety of small games and graphics demos written in Python using the raylib library. It's ideal for exploring game-loop structure, 2D/3D graphics, physics simulation, and interactive demos.
Whether you're learning game development or experimenting with new ideas, these demos provide hands-on examples of core concepts in action.
Note: Demo code in this repository was generated with assistance from Google Gemini and Claude AI, and refined through experimentation.
Each file demonstrates a different concept. Example files include:
|
|
See the full list of 20+ demos in the repository!
- Python 3.x installed on your system
- raylib Python binding โ Install via pip:
pip install raylibNote: If you use a different binding or version (e.g.,
raylib-python-cffi), adjust the import statements accordingly.
-
Clone this repository:
git clone https://github.com/NguyenLe15325/Python-raylib.git cd Python-raylib -
Run one of the demos:
python 3.Pong.py
-
Explore, modify, and experiment!
- Change colors, speeds, or physics parameters
- Add new features or mechanics
- Build your own game using these as templates
Follow this progression to get the most out of these demos:
1. ๐ข Start with basics (1.ball.py)
โ Understand the game loop and rendering
2. ๐ก Add input (3.Pong.py, 4.Pong_2player.py)
โ Progress to input-driven games
3. ๐ Explore platformers (10.2D_platformer_camera.py)
โ Learn camera control and advanced 2D mechanics
4. ๐ด Try 3D (16.Basic_3D.py)
โ Dive into 3D scenes and rendering
5. ๐ฃ Physics (19.Physics_playground.py, 20.Physics_simulation.py)
โ Experiment with physics simulations
6. โซ Build your own!
Extend a demo: add new mechanics, change assets, or create something original!
Experience the fundamentals of collision detection, scoring systems, and AI opponents.
Learn about character movement, gravity, jumping mechanics, and dynamic camera following.
Explore 3D rendering, camera positioning, and basic 3D object manipulation.
Experiment with gravity, collisions, forces, and realistic object interactions.
This demo showcases a complete 3D physics simulation environment where you can interact with multiple spherical objects in real-time. It's not just a demonstrationโit's a fully playable physics sandbox that responds to your every action!
- ๐น๏ธ Free Camera Movement โ Navigate through 3D space with WASD controls and mouse look
- ๐คฒ Object Interaction โ Hold and throw spheres with realistic physics
- โก Real-time Physics โ Watch objects bounce, collide, and interact with gravity
- ๐จ Multiple Objects โ Experiment with spheres of different sizes, masses, and colors
- ๐ง Highly Configurable โ Tweak physics parameters to create your own simulation
| Input | Action |
|---|---|
W A S D |
Move camera forward/left/back/right |
Space / Left Shift |
Move camera up/down |
Mouse |
Look around (first-person view) |
Left Click |
Grab/hold sphere |
Mouse Scroll |
Adjust grabbed object's distance from camera |
Release Click |
Throw sphere (velocity based on mouse movement) |
ESC |
Exit simulation |
The simulation is designed to be tweaked! Here are some parameters you can adjust:
# Screen Settings
SCREEN_WIDTH = 1200
SCREEN_HEIGHT = 800
FPS = 60
# Physics Constants
GRAVITY_ACCEL = Vector3(0.0, -9.81, 0.0) # Earth-like gravity
BOUNDS_SIZE = 15.0 # Simulation cube size
FRICTION_FACTOR = 0.85 # Bounce elasticity (0-1)
THROW_FACTOR = 0.5 # Throw strength multiplier
# Camera Settings
CAM_SPEED = 15.0 # Movement speed
CAM_SENSITIVITY = 0.15 # Mouse sensitivity
CAMERA_BOUNDS_SIZE = 18.0 # Camera movement limitsCreate your own physics objects with different properties:
spheres = [
# Small and light - bounces easily
Sphere(Vector3(-5.0, 5.0, 0.0), radius=0.7, mass=0.5, color=SKYBLUE),
# Medium size - balanced behavior
Sphere(Vector3(5.0, 10.0, 0.0), radius=1.5, mass=3.0, color=LIME),
# Tiny and floaty - fun to throw
Sphere(Vector3(0.0, 15.0, 5.0), radius=0.5, mass=0.2, color=YELLOW),
# Large and heavy - powerful collisions
Sphere(Vector3(-10.0, 10.0, -5.0), radius=2.0, mass=5.0, color=MAGENTA)
]- 3D Camera Systems โ First-person camera with constraints and smooth movement
- Vector Physics โ Velocity, acceleration, and force calculations in 3D
- Collision Detection โ Sphere-to-sphere and sphere-to-boundary collisions
- Realistic Interactions โ Momentum transfer, friction, and energy conservation
- Input Handling โ Mouse picking and drag-to-throw mechanics
- Performance Optimization โ Efficient physics updates at 60 FPS
Try these modifications to learn more:
- Adjust gravity โ What happens in low gravity? Or with reversed gravity?
- Change elasticity โ Make everything super bouncy or completely inelastic
- Add more spheres โ How many objects can the simulation handle?
- Modify masses โ Create very heavy or very light objects and observe interactions
- Change bounds โ Make the simulation space larger or smaller
- Add spin โ Implement rotational physics for even more realism
This project is licensed under the MIT License โ see the LICENSE file for details.
You're free to use, modify, and distribute this code for personal or commercial projects.
raylib โ Amazing lightweight graphics/game library by Ramon Santamaria
The open-source Python community โ For bindings, examples, and endless inspiration
Google Gemini & Claude AI โ AI assistance in generating and refining demo code
ezgif.com โ GIF editing and optimization tools
- The ultimate introduction to Raylib [2D & 3D game dev]
- Getting Started with Raylib
- Game Development Tutorials
Nguyen Le โข @NguyenLe15325
๐ Star this repo โข ๐ Report Bug โข ๐ก Request Feature

