Skip to main content

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, and Collider.
  • 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

  1. Clone the repository:
    git clone https://github.com/yourusername/pygame-engine.git
    cd pygame-engine
    
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. 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:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polystack_pygame_engine-1.2.2.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polystack_pygame_engine-1.2.2-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file polystack_pygame_engine-1.2.2.tar.gz.

File metadata

  • Download URL: polystack_pygame_engine-1.2.2.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for polystack_pygame_engine-1.2.2.tar.gz
Algorithm Hash digest
SHA256 730f75c8aa352e79ba4f3cb9db1fee0b3fd285c49f0c2c98eec5c23f52f6b94c
MD5 f01ac9d74865e7686cf0aed020bcb97b
BLAKE2b-256 13c38fea7b7025cd231746c82cb32e00be2970801ea13f9cc00998ee6b5ebac4

See more details on using hashes here.

Provenance

The following attestation bundles were made for polystack_pygame_engine-1.2.2.tar.gz:

Publisher: python-publish.yml on PolyStack-Games/Pygame-Engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polystack_pygame_engine-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for polystack_pygame_engine-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a66fdfe0db6fa87bd45d573dd6981504cf91e44f782ef487f932e8b94d7cd7f
MD5 a28d6b40a257965431517a0b82e1e7fc
BLAKE2b-256 ec9ef51a5742289c9224eccb3145f487554aa5a5cb8376132de60585dde5d1cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for polystack_pygame_engine-1.2.2-py3-none-any.whl:

Publisher: python-publish.yml on PolyStack-Games/Pygame-Engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page