A modular pygame_engine library for Pygame-based 2D games.
Project description
Pygame-Engine
Overview
Pygame-Engine is a lightweight, Unity-inspired game engine built using Python and Pygame. It provides a modular and extensible framework for 2D game development, including GameObjects, Components, Scene Management, Event Handling, and more.
Features
- GameObject System: Modular entities with components like
Transform,SpriteRenderer, andCollider. - Scene Management: Easily manage and transition between game scenes.
- Prefab System: Save and instantiate reusable GameObject templates.
- Event System: Decoupled communication via a publish-subscribe model.
- Input Manager: Centralized input handling with customizable key bindings.
- Scriptable Objects: Reusable and serializable data containers for configurations and items.
Installation
- Clone the repository:
git clone https://github.com/yourusername/pygame-engine.git cd pygame-engine
- Install dependencies:
pip install -r requirements.txt
- Run an example:
python examples/basic_game.py
Usage
GameObject System
Create GameObjects and add Components:
from engine.game_object import GameObject
from engine.components import Transform, SpriteRenderer
player = GameObject("Player")
player_transform = player.add_component(Transform)
player_renderer = player.add_component(SpriteRenderer)
player_transform.position = [100, 100]
Scene Management
Switch between scenes or reset the current scene:
from engine.scene_manager import SceneManager
from engine.scene import Scene
main_scene = Scene("MainScene")
SceneManager.load_scene(main_scene)
SceneManager.reset_scene()
Prefab System
Save and instantiate reusable prefabs:
from engine.prefab_system import PrefabSystem
PrefabSystem.save_prefab("PlayerPrefab", "player_prefab.json", player)
new_player = PrefabSystem.instantiate_prefab("player_prefab.json")
Event System
Publish and subscribe to events:
from engine.event_system import EventBus
EventBus.subscribe("player_died", lambda score: print(f"Player died with score {score}"))
EventBus.publish("player_died", score=100)
Input Manager
Bind keys to actions:
from engine.input_manager import InputManager
InputManager.bind_action("jump", pygame.K_SPACE, "down")
InputManager.register_callback("jump", lambda: print("Jump!"))
Examples
Explore the examples/ directory for usage demonstrations:
basic_game.py: A basic game showcasing core features.event_bus_example.py: Demonstrates the EventBus system.input_manager_example.py: Demonstrates the InputManager system.prefab_system_example.py: Demonstrates the PrefabSystem.
Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes and create a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- Pygame for providing the core library.
- Unity for inspiring the engine's architecture.
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 polystack_pygame_engine-1.2.5.tar.gz.
File metadata
- Download URL: polystack_pygame_engine-1.2.5.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c5062c8f44f543c38f589686bf762fad4165fb970e961f63c882ec2630fb80f
|
|
| MD5 |
a2b1551e376282757ed10fa87c5fde7c
|
|
| BLAKE2b-256 |
2321e55b4797db617ac9d2aa0995029447afa1f72706f99809080c98010d2a1b
|
Provenance
The following attestation bundles were made for polystack_pygame_engine-1.2.5.tar.gz:
Publisher:
python-publish.yml on PolyStack-Games/Pygame-Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polystack_pygame_engine-1.2.5.tar.gz -
Subject digest:
7c5062c8f44f543c38f589686bf762fad4165fb970e961f63c882ec2630fb80f - Sigstore transparency entry: 161657412
- Sigstore integration time:
-
Permalink:
PolyStack-Games/Pygame-Engine@9b705f531361423a396eaa6115a06c64eac0e36a -
Branch / Tag:
refs/tags/1.2.5 - Owner: https://github.com/PolyStack-Games
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9b705f531361423a396eaa6115a06c64eac0e36a -
Trigger Event:
release
-
Statement type:
File details
Details for the file polystack_pygame_engine-1.2.5-py3-none-any.whl.
File metadata
- Download URL: polystack_pygame_engine-1.2.5-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73288aeed2d705d2cf58b8e4b4f774493a85e416a587c10eb582dfcc0a60d444
|
|
| MD5 |
29aa0ba7c3a92676b6de328db56bce23
|
|
| BLAKE2b-256 |
73464c784ee0e3a1dcf3d24d5c4d1b75f965c412e89291ebee40a41ed9244859
|
Provenance
The following attestation bundles were made for polystack_pygame_engine-1.2.5-py3-none-any.whl:
Publisher:
python-publish.yml on PolyStack-Games/Pygame-Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polystack_pygame_engine-1.2.5-py3-none-any.whl -
Subject digest:
73288aeed2d705d2cf58b8e4b4f774493a85e416a587c10eb582dfcc0a60d444 - Sigstore transparency entry: 161657413
- Sigstore integration time:
-
Permalink:
PolyStack-Games/Pygame-Engine@9b705f531361423a396eaa6115a06c64eac0e36a -
Branch / Tag:
refs/tags/1.2.5 - Owner: https://github.com/PolyStack-Games
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9b705f531361423a396eaa6115a06c64eac0e36a -
Trigger Event:
release
-
Statement type: