2D game engine for Python with physics, collision detection, and texture support
Project description
Jwarol Engine
2D game engine for Python built with C++ and pybind11. Includes object type system, physics, collision detection, texture support and OpenGL rendering.
Features
- Object Type System: Create objects of different types (PLAYER, ITEM, GUI, OBJECT)
- Physics Engine: Gravity simulation and collision detection
- Boundary Checking: Verify if objects are within world bounds
- Texture Loading: Load and manage textures
- OpenGL Rendering: Hardware-accelerated 2D rendering
- Window Management: Create and manage game windows
Installation
pip install jwarol==0.3.2
API Reference
ObjectType Enum
Define the type of game object:
jwarol.ObjectType.OBJECT # Generic object
jwarol.ObjectType.PLAYER # Player character
jwarol.ObjectType.ITEM # Collectible item
jwarol.ObjectType.GUI # GUI element
Engine Class
Main class for the game engine.
Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
__init__() |
None | Engine | Create new engine instance |
init(width, height, title) |
width (int), height (int), title (str) | bool | Initialize game window (800x600 example). Returns True on success |
create_object(x, y, w, h, type) |
x (float), y (float), w (float), h (float), type (ObjectType) | int | Create new object, returns unique object ID |
is_object(id, type) |
id (int), type (ObjectType) | bool | Check if object with id is of type |
check_collision(id1, id2) |
id1 (int), id2 (int) | bool | Check if two objects collide |
is_open() |
None | bool | Check if window is still open |
clear(r, g, b) |
r (float), g (float), b (float) | None | Clear screen with color (0.0-1.0 range) |
draw_rect(id, r, g, b) |
id (int), r (float), g (float), b (float) | None | Draw object by ID with color |
update() |
None | None | Update screen (swap buffers) |
close() |
None | None | Close engine and free resources |
Usage Examples
Basic Example
import jwarol
# Initialize engine
engine = jwarol.Engine()
engine.init(800, 600, "My Game")
# Create player object
player = engine.create_object(100, 100, 50, 50, jwarol.ObjectType.PLAYER)
# Game loop
while engine.is_open():
engine.clear(0.2, 0.2, 0.2) # Grey background
engine.draw_rect(player, 0.0, 1.0, 0.0) # Green player
engine.update()
engine.close()
Multiple Objects & Collision Detection
import jwarol
engine = jwarol.Engine()
engine.init(800, 600, "Collision Example")
# Create objects of different types
player = engine.create_object(100, 100, 50, 50, jwarol.ObjectType.PLAYER)
enemy = engine.create_object(300, 100, 50, 50, jwarol.ObjectType.OBJECT)
item = engine.create_object(200, 300, 30, 30, jwarol.ObjectType.ITEM)
gui = engine.create_object(10, 10, 100, 30, jwarol.ObjectType.GUI)
# Check object types
print(f"Player is PLAYER: {engine.is_object(player, jwarol.ObjectType.PLAYER)}") # True
print(f"Enemy is OBJECT: {engine.is_object(enemy, jwarol.ObjectType.OBJECT)}") # True
print(f"Item is ITEM: {engine.is_object(item, jwarol.ObjectType.ITEM)}") # True
print(f"GUI is GUI: {engine.is_object(gui, jwarol.ObjectType.GUI)}") # True
while engine.is_open():
engine.clear(0.2, 0.2, 0.2)
# Draw objects with different colors
engine.draw_rect(player, 0.0, 1.0, 0.0) # Green - Player
engine.draw_rect(enemy, 1.0, 0.0, 0.0) # Red - Enemy
engine.draw_rect(item, 1.0, 1.0, 0.0) # Yellow - Item
engine.draw_rect(gui, 0.0, 0.0, 1.0) # Blue - GUI
# Check collision between player and enemy
if engine.check_collision(player, enemy):
print("Player hit enemy!")
engine.update()
engine.close()
Physics & Boundary Checking (Internal)
The engine includes a physics system with gravity and boundary checking:
// C++ internal API (not yet exposed to Python)
physics.apply_gravity(obj, delta_time); // Apply gravity to object
physics.check_boundary(obj, world_width, world_height); // Check if object is in bounds
physics.check_collision_with(obj, objects); // Check collision with other objects
Project Structure
's/
├── main.cpp # Main engine code with Python bindings
├── object_types.h/.cpp # Object type system
├── physics.h/.cpp # Physics engine
├── texture.h/.cpp # Texture management
├── setup.py # Build configuration
├── pyproject.toml # Project metadata
├── LICENSE # MIT License
└── README.md # This file
Author
ruslan
License
MIT License - see LICENSE file.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jwarol-0.3.3.tar.gz.
File metadata
- Download URL: jwarol-0.3.3.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ef264bfdd05c1d76b53693ad165a0def65cc90855770b109f9e4dc0e6c26f46
|
|
| MD5 |
7011e326ee887cd4769b444b8986b023
|
|
| BLAKE2b-256 |
e0af493d41f310c6a37e1f8ad605a9b6b71ef0cbe4a7ea8d1dbfea9191975d46
|
File details
Details for the file jwarol-0.3.3-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: jwarol-0.3.3-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 107.7 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3944622fd18e149035e02bf5f5888b76ffeda15ed5ce1e79c620856ee6aece46
|
|
| MD5 |
4652fb2d0fad9d2c7d01c79341d7287e
|
|
| BLAKE2b-256 |
2855424e89d6367a896e3ae15303465d4daa276ebbef35d56a28d5e20ead15f2
|