Gyula Rabai

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

Figure 1 - Rgame library

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)
Tip: Save your file as .pyw to run without a console window (but remember to close the process manually if needed).

Core Components

MainScript: Central class containing everything
MainWindow: 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

MethodWhen CalledNotes
Before()Before anything is initializedCan access Stop and Started. Set Stop = True to quit early.
Main()After initialization, before event loopsBest 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.
Access rule: Inside 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 rendering
self.MainWindow.Add(script): Subscribes a script to rendering
self.MainWindow.Remove(script): Unsubscribes a script from rendering

Properties (most are "main only")

FrameRate.Value: Window refresh rate
WindowTitle, WindowWidth, WindowHeight
WindowBackGround, WindowIcon
FailedRenderFailsafe.Value: Max exceptions before crash (0 = unlimited)
RenderingManager.FailedRenderCount: Current exception count
Appearances: See Appearances documentation
Activate: Set to False to prevent window from starting

MainPhysics

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 crash
FailedTickCount: Current exception count
Running: Read-only: whether the loop is active
Counter: Read-only: number of physics ticks
DeltaTime: 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 change

Keyboard 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

More information


Projects | Books | Printouts | On-line lectures | Presentations