RGame - A Python Game Engine
RGame is a powerful Python game engine designed for developers who want flexibility and performance. With an outstanding vector class and advanced physics simulation, rgame makes it easy to create smooth, realistic motion and interactions. Whether you're building a 2D platformer, a physics-based puzzle game, or a dynamic simulation, rgame provides intuitive tools and optimized performance to bring your ideas to life.
Pip repository: https://pypi.org/project/rgame/
Source code: RGame.zip
Zombie game: https://gyularabai.com/p_3273-zombie-game.html
Example
Check out the Zombie game project, that demonstrates how RGame can be used to create a simple game.
Introduction to RGame
RGame is an object-oriented 2D game engine. It provides a structured way to create graphical applications with separated physics and rendering loops, multithreading support, and built-in error handling.
Basic Usage
from RGame import *
class MainScript(RG_MainScript):
def Main(self):
pass
def PhysicsTick(self, deltaTime):
pass
def Render(self):
pass
def main():
return MainScript()
Run(main)
.pyw to run without a console window (but remember to close the process manually if needed).
Core Components
MainScript: Central class containing everythingMainWindow: Handles window creation and rendering
MainPhysics: Manages physics simulation loop
Appearances: Tkinter-based graphical objects
UserInput: Keyboard & mouse event handling
MainScript
This is the universal class that contains everything. Must be named MainScript and inherit from RG_MainScript.
Overridable Methods
| Method | When Called | Notes |
|---|---|---|
Before() | Before anything is initialized | Can access Stop and Started. Set Stop = True to quit early. |
Main() | After initialization, before event loops | Best place to set window properties & physics mode |
PhysicsTick(deltaTime) | Every physics step (default 20×/s) | Runs in separate thread. Use for movement, logic. |
Render() | Before screen refresh (default 10×/s) | Runs in separate thread. Update visuals here. |
MainScript → use self.XXX.Outside
MainScript → use self.MainScript.XXX.
MainWindow
Handles the Tkinter window, rendering loop (separate thread), and user input.
Methods
self.MainWindow.Exists(script): Checks if a script is subscribed to renderingself.MainWindow.Add(script): Subscribes a script to renderingself.MainWindow.Remove(script): Unsubscribes a script from renderingProperties (most are "main only")
FrameRate.Value: Window refresh rateWindowTitle, WindowWidth, WindowHeightWindowBackGround, WindowIconFailedRenderFailsafe.Value: Max exceptions before crash (0 = unlimited)RenderingManager.FailedRenderCount: Current exception countAppearances: See Appearances documentationActivate: Set to False to prevent window from startingMainPhysics
Handles the physics simulation loop (separate thread).
Methods
self.MainPhysics.Exists(script)self.MainPhysics.Add(script)self.MainPhysics.Remove(script)Properties
Interval: Time between physics ticks (seconds)FailedTickFailsafe: Max exceptions before crashFailedTickCount: Current exception countRunning: Read-only: whether the loop is activeCounter: Read-only: number of physics ticksDeltaTime: Read-only: time since last tick (in interval units)Mouse Input
Accessed via self.MainWindow.Mouse
Binding Events
BindLeftDown(func), BindLeftUp(func)BindMiddleDown(func), BindMiddleUp(func)BindRightDown(func), BindRightUp(func)BindDoubleClick(func)BindMove(func), BindDrag(func)Mouse State Properties
Left, Middle, Right: button pressed?Drag: left button held + moving?ScrollDelta: mouse wheel changeKeyboard Input
Use self.MainWindow.Bind(key, callback)
self.MainWindow.Bind("", self.MoveUp)
self.MainWindow.Bind("", self.StopMoveUp)
Common Key Bindings
<Up>, <Down>, <Left>, <Right><Space>, <Return>, <Escape><Control-c>, <Alt-F4>, etc.Source code
To view the source code online click on the following link:
RGameLib.py source code