Skip to main content

A powerful and easy-to-use Python library for creating 2D games

Project description

Py2D Game Engine

A powerful and easy-to-use Python library for creating 2D games with high capabilities and excellent performance.

🚀 Version 1.0.0 Beta

Note: This is a beta version of Py2D Game Engine. Some features may be experimental and subject to change.

Features

🎮 Core Game Engine

  • Py2DEngine: Main game engine with window and scene management
  • GameObject: Advanced object system with hierarchical structure
  • Scene: Scene and layer management
  • Camera: Advanced camera system with zoom and rotation

🎨 Graphics System

  • Sprite: Image and graphics management
  • Animation: Advanced animation system
  • Text: Text rendering with custom fonts
  • Shape: Geometric shape drawing
  • TileMap: Tile maps for large worlds

🎵 Audio System

  • AudioManager: Sound and music management
  • Support for various audio formats
  • Volume control
  • Advanced sound effects

🎯 Physics System

  • Physics2D: 2D physics engine
  • RigidBody2D: Rigid bodies with gravity
  • Collider2D: Advanced collision system
  • Collision detection and interactions

⌨️ Input System

  • InputManager: Keyboard and mouse management
  • Vector movement support
  • Advanced input events
  • Keyboard shortcuts

🖼️ User Interface

  • UIElement: Basic UI elements
  • Button: Interactive buttons
  • Label: Text labels
  • Panel: Container panels

Installation

pip install py2d-game

Or from source:

git clone https://github.com/En-Hussain/py2d-game.git
cd py2d-game
pip install -e .

Quick Start

Simple Game

from py2d_game import Py2DEngine, GameObject, Scene, Sprite, Color, Vector2

class Player(GameObject):
    def __init__(self, x, y):
        super().__init__(x, y)
        self.sprite = Sprite(width=32, height=32, color=Color(0, 255, 0))
        self.speed = 200
        
    def update(self, delta_time):
        super().update(delta_time)
        
        input_manager = self.scene.game_engine.input_manager
        movement = input_manager.get_movement_vector()
        self.position += movement * self.speed * delta_time

def main():
    engine = Py2DEngine(800, 600, "My First Game")
    
    scene = Scene("Main Game")
    scene.background_color = Color(50, 50, 100)
    
    player = Player(400, 300)
    scene.add_object(player)
    
    engine.add_scene(scene)
    engine.set_scene("Main Game")
    engine.run()

if __name__ == "__main__":
    main()

Platformer Game

from py2d_game import Py2DEngine, GameObject, Scene, Sprite, Color, Physics2D, RigidBody2D, Collider2D

class Player(GameObject):
    def __init__(self, x, y):
        super().__init__(x, y)
        self.sprite = Sprite(width=24, height=32, color=Color(0, 255, 0))
        self.rigid_body = RigidBody2D(mass=1.0, gravity_scale=1.0)
        self.collider = Collider2D(24, 32)
        self.collider.game_object = self
        self.speed = 300
        self.jump_force = 400
        
    def update(self, delta_time):
        super().update(delta_time)
        
        input_manager = self.scene.game_engine.input_manager
        
        if input_manager.is_key_pressed('left'):
            self.rigid_body.velocity.x = -self.speed
        elif input_manager.is_key_pressed('right'):
            self.rigid_body.velocity.x = self.speed
            
        if input_manager.is_key_just_pressed('space'):
            self.rigid_body.velocity.y = -self.jump_force
            
        self.position += self.rigid_body.velocity * delta_time

def main():
    engine = Py2DEngine(800, 600, "Platformer Game")
    
    scene = Scene("Main Game")
    physics = Physics2D(Vector2(0, 500))
    
    player = Player(100, 400)
    scene.add_object(player)
    physics.add_rigid_body(player.rigid_body)
    physics.add_collider(player.collider)
    
    engine.add_scene(scene)
    engine.set_scene("Main Game")
    engine.run()

if __name__ == "__main__":
    main()

Included Examples

The library includes several ready-to-use examples:

  1. Simple Game (examples/simple_game.py) - Basic game with player and enemies
  2. Platformer Game (examples/platformer_game.py) - Platformer with physics
  3. Space Shooter (examples/space_shooter.py) - Space shooting game
  4. Simple Platformer (platformer_simple.py) - Simplified platformer
  5. Simple Space Shooter (space_shooter_simple.py) - Simplified space shooter

To run the examples:

python examples/simple_game.py
python examples/platformer_game.py
python examples/space_shooter.py
python platformer_simple.py
python space_shooter_simple.py

Complete Documentation

Py2DEngine

The main game engine:

engine = Py2DEngine(width=800, height=600, title="My Game")
engine.add_scene(scene)
engine.set_scene("scene_name")
engine.run()

GameObject

Basic game objects:

class MyObject(GameObject):
    def __init__(self, x, y):
        super().__init__(x, y)
        self.sprite = Sprite(width=32, height=32, color=Color(255, 0, 0))
        
    def update(self, delta_time):
        super().update(delta_time)
        # Update logic here

Input System

input_manager = engine.input_manager

# Check keys
if input_manager.is_key_pressed('space'):
    # Do something

if input_manager.is_key_just_pressed('enter'):
    # Do something once

# Get movement vector
movement = input_manager.get_movement_vector()

# Check mouse
if input_manager.is_mouse_button_pressed(1):  # Left mouse button
    mouse_pos = input_manager.get_mouse_position()

Audio System

audio_manager = engine.audio_manager

# Load and play sound
audio_manager.load_sound("jump", "sounds/jump.wav")
audio_manager.play_sound("jump")

# Load and play music
audio_manager.load_music("background_music.mp3")
audio_manager.play_music(loop=-1)  # Infinite loop

Physics System

physics = Physics2D(Vector2(0, 500))  # Gravity

# Add rigid body
rigid_body = RigidBody2D(mass=1.0, gravity_scale=1.0)
physics.add_rigid_body(rigid_body)

# Add collider
collider = Collider2D(32, 32)
physics.add_collider(collider)

# Update physics
physics.update(delta_time, game_objects)

Requirements

  • Python 3.7 or higher
  • pygame 2.0.0 or higher

License

This library is licensed under the MIT License. See the LICENSE file for details.

Contributing

We welcome contributions! Please read the contributing guide before submitting pull requests.

Technical Support

For technical support and questions, please contact:

Upcoming Features

  • Advanced animation system
  • Particle system
  • Multiplayer networking support
  • Advanced development tools
  • Support for more image formats

Changelog

Version 1.0.0

  • Initial release
  • Core game engine
  • Graphics system
  • Physics system
  • Input system
  • Audio system
  • UI system
  • Example games

Py2D Game Engine - Make game development easy and fun! 🎮

Created by En-Hussain

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

py2d_game-1.0.0b0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

py2d_game-1.0.0b0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file py2d_game-1.0.0b0.tar.gz.

File metadata

  • Download URL: py2d_game-1.0.0b0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for py2d_game-1.0.0b0.tar.gz
Algorithm Hash digest
SHA256 a7d55a124c2214c0d305fc4be61a00540c0bae198b801230f42824f7d0b98571
MD5 9c8f8713199002aaaabe2f6304e36677
BLAKE2b-256 b9ffc3e5086f4d24aa5db60a6a012e2f32b9ddef98010413a39ed9fc0d074639

See more details on using hashes here.

File details

Details for the file py2d_game-1.0.0b0-py3-none-any.whl.

File metadata

  • Download URL: py2d_game-1.0.0b0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for py2d_game-1.0.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 67839e407a8fc6e3a9dd494a4e01add4586753435a12e47c9ee64688267a385a
MD5 9c970f907b931ad5e5a91f98b5f00694
BLAKE2b-256 1fa0087e2d9c8cf65658cd8d958fe0ab6e79a761b154eddee3d6457d434394f2

See more details on using hashes here.

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