Skip to content

This is a Python raylib game demo repository github that showcases game development using the raylib library with Python bindings.

License

Notifications You must be signed in to change notification settings

NguyenLe15325/Python-raylib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Python-raylib

Python Raylib License Games

Game demo collection using raylib in Python

Explore game loops โ€ข 2D/3D graphics โ€ข Physics simulation โ€ข Interactive demos


๐Ÿš€ Project Overview

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.


๐Ÿ“‚ Contents

Each file demonstrates a different concept. Example files include:

๐ŸŽฏ Basic Demos

  • 1.ball.py โ€” Simple bouncing ball demo
  • 3.Pong.py โ€” Classic Pong game logic
  • 4.Pong_2player.py โ€” Two-player Pong variant

๐ŸŽฎ Platformers & 2D

  • 10.2D_platformer_camera.py โ€” 2D platformer with camera control
  • And more 2D game mechanics...

๐ŸŒ 3D Graphics

  • 16.Basic_3D.py โ€” Introductory 3D scene
  • 3D rendering and camera demos

โš›๏ธ Physics Simulations

  • 19.Physics_playground.py โ€” Basic physics sandbox
  • 20.Physics_simulation.py โ€” Advanced physics demos

See the full list of 20+ demos in the repository!


๐Ÿงฉ Why Use raylib + Python?

raylib
Simple API
Easy-to-use interface for graphics, input, and sound
๐Ÿ“š
Educational
Perfect for learning game loops, rendering, and physics
๐Ÿ–ฅ๏ธ
Cross-platform
Works on Windows, macOS, and Linux
โšก
Rapid Prototyping
Mix Python simplicity with real-time graphics

๐Ÿ›  Getting Started

Prerequisites

  • Python 3.x installed on your system
  • raylib Python binding โ€” Install via pip:
pip install raylib

Note: If you use a different binding or version (e.g., raylib-python-cffi), adjust the import statements accordingly.

Running a Demo

  1. Clone this repository:

    git clone https://github.com/NguyenLe15325/Python-raylib.git
    cd Python-raylib
  2. Run one of the demos:

    python 3.Pong.py
  3. Explore, modify, and experiment!

    • Change colors, speeds, or physics parameters
    • Add new features or mechanics
    • Build your own game using these as templates

๐ŸŽฏ Suggested Learning Path

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!


๐Ÿ’ก Demo Highlights

๐Ÿ“ Classic Pong (3.Pong.py)

Experience the fundamentals of collision detection, scoring systems, and AI opponents.

๐ŸŽฎ 2D Platformer (10.2D_platformer_camera.py)

Learn about character movement, gravity, jumping mechanics, and dynamic camera following.

๐ŸŒ 3D Basics (16.Basic_3D.py)

Explore 3D rendering, camera positioning, and basic 3D object manipulation.

โš›๏ธ Physics Playground (19.Physics_playground.py)

Experiment with gravity, collisions, forces, and realistic object interactions.


โญ Featured Project: 3D Physics Simulation

๐Ÿš€ 20.Physics_simulation.py - Interactive 3D Physics Engine

The crown jewel of this collection - a fully interactive 3D physics sandbox!

Physics Simulation Demo

๐ŸŽฏ What Makes It Special

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!

โœจ Key Features

  • ๐Ÿ•น๏ธ 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

๐ŸŽฎ Controls

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

โš™๏ธ Configurable Parameters

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 limits

๐ŸŽจ Customize Your Spheres

Create 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)
]

๐Ÿ”ฌ What You'll Learn

  • 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

๐Ÿ’ก Experiment Ideas

Try these modifications to learn more:

  1. Adjust gravity โ€” What happens in low gravity? Or with reversed gravity?
  2. Change elasticity โ€” Make everything super bouncy or completely inelastic
  3. Add more spheres โ€” How many objects can the simulation handle?
  4. Modify masses โ€” Create very heavy or very light objects and observe interactions
  5. Change bounds โ€” Make the simulation space larger or smaller
  6. Add spin โ€” Implement rotational physics for even more realism

๐Ÿ“œ License

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.


๐Ÿค Acknowledgements

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


๐ŸŽ“ Additional Resources

๐Ÿ“š Official Documentation

๐ŸŽฅ Video Tutorials


๐Ÿ“ง Contact & Links


๐ŸŽฎ Have fun exploring game development with Python & raylib!

Made with โค๏ธ and Python

โญ If you find this helpful, consider starring the repository! โญ

About

This is a Python raylib game demo repository github that showcases game development using the raylib library with Python bindings.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages