Skip to main content

An easier way to use pygame

Project description

Blu Easy Pygame

A small wrapper for pygame that makes basic game setup easier.

Blu_easy_pygame provides:

  • a simple init() function for window setup
  • a single run() loop for frame updates
  • callback binding for frame and input events
  • shape classes for rectangles, circles, ellipses, lines, squares, and polygons

Installation

Install pygame first, then install the package locally for development:

python -m pip install pygame
python -m pip install -e .

If published on PyPI, install with:

python -m pip install Blu_easy_pygame

Quick Start

import easypygame as epy

# 1. Initialize the window
epy.init(width=600, height=600, bg="white")

# 2. Create shapes
box = epy.graphics.rect(100, 100, 120, 80, color="red")
circle = epy.graphics.circle(300, 200, 50, color="blue")
line = epy.graphics.line([(50, 50), (200, 120)], width=4, color="green")
polygon = epy.graphics.polygon(
    [(350, 100), (420, 180), (320, 220)],
    color="purple"
)

# 3. Frame update function

def update(dt):
    box.x += 100 * dt
    if box.left > epy.getWidth():
        box.right = 0

# 4. Mouse callback

def on_left_click(event):
    print("Left click:", event)

# 5. Bind callbacks
epy.bind("mainLoop", update)
epy.bind("leftMouseDown", on_left_click)

# 6. Start the game loop
epy.run()

Core API

epy.init(width=300, height=300, bg="white", background=None, frame=60, busy=False)

Initialize pygame, configure the display, and set the background color.

Returns:

  • (passed, failed) from pygame.init()

Arguments:

  • width — window width in pixels
  • height — window height in pixels
  • bg — background color
  • background — alias for bg
  • frame — target frames per second
  • busy — optional busy-mode flag

Example:

epy.init(width=800, height=600, bg="black", frame=60)

epy.run()

Start the main game loop. Shapes created with epy.graphics are drawn automatically each frame.

The loop continues until the window closes or epy.stop() is called.

Example:

epy.run()

epy.bind(funcType, func)

Register a callback for a supported event type.

Supported funcType values:

  • mainLoop — called each frame, receives dt in seconds
  • physicsLoop — called each frame, receives physics delta time in seconds
  • phisicLoop — legacy alias for physicsLoop
  • mouseDown — any mouse button press
  • mouseUp — any mouse button release
  • leftMouseDown, leftMouseUp
  • middleMouseDown, middleMouseUp
  • rightMouseDown, rightMouseUp
  • mouseMotion — mouse movement
  • mouseWheel — wheel scrolling
  • keyDown, keyUp

Example:

def update(dt):
    print("Delta time:", dt)

epy.bind("mainLoop", update)

Callbacks may accept a single parameter or no parameters.

Mouse callback example:

def on_click(event):
    print("Mouse event:", event)

epy.bind("leftMouseDown", on_click)

epy.unbind(funcType)

Remove a bound callback.

Example:

epy.unbind("leftMouseDown")

epy.stop()

Stop the game loop from inside a callback.

Example:

def quit_game(dt):
    epy.stop()

epy.bind("mainLoop", quit_game)

epy.getWidth() and epy.getHeight()

Return the window width and height.

Example:

width = epy.getWidth()
height = epy.getHeight()

epy.getFPS()

Return the current frame rate value.

Example:

fps = epy.getFPS()

epy.getGameTime()

Return the elapsed game time in milliseconds.

Example:

elapsed = epy.getGameTime()

epy.getBackground() and epy.setBackground(color)

Read or change the current background color.

Example:

current = epy.getBackground()
epy.setBackground("black")

epy.sleep(milliseconds, processOS=True)

Pause execution for the given time.

Example:

epy.sleep(500)

Shapes

Create shapes using epy.graphics. Shapes are drawn automatically each frame.

epy.graphics.rect(x, y, width, height, angle=0, color="black")

Create a rectangle.

Example:

rect = epy.graphics.rect(50, 50, 120, 80, angle=0, color="red")

epy.graphics.circle(x, y, radius, color="black")

Create a circle.

Example:

circle = epy.graphics.circle(200, 200, 50, color="blue")

epy.graphics.ellipse(x, y, width, height, angle=0, color="black")

Create an ellipse.

Example:

egg = epy.graphics.ellipse(300, 150, 160, 80, angle=0, color="green")

epy.graphics.square(x, y, radius, angle=0, color="black")

Create a square.

Example:

square = epy.graphics.square(150, 300, 50, angle=30, color="purple")

epy.graphics.line(points, width=1, color="black")

Create a line path from points.

Example:

line = epy.graphics.line([(50, 400), (200, 450), (300, 380)], width=3, color="yellow")

epy.graphics.polygon(points, width=0, angle=0, color="black")

Create a polygon from a list of points.

Example:

triangle = epy.graphics.polygon(
    [(350, 100), (420, 180), (320, 220)],
    color="purple"
)

Add more points later:

triangle.add_point(380, 50)

Shape Properties

Most shapes support these properties:

  • x, y
  • left, right, top, bottom
  • width, height for rectangles and ellipses
  • radius for circles and squares
  • points for lines and polygons
  • angle for rotated shapes
  • color

Example:

rect.x += 5
rect.color = "blue"
print(circle.radius)

Event data

Mouse callbacks receive a parameter dictionary with values like:

  • pos — mouse position
  • rel — relative movement
  • buttons — button state
  • touch — touch input data
  • window — window event data
  • x, y — wheel delta values

Keyboard callbacks receive:

  • unicode
  • key
  • mod
  • scancode

Example:

def on_click(event):
    print("Clicked:", event)

Full example

import easypygame as epy

epy.init(width=640, height=480, bg="lightgray")

player = epy.graphics.rect(50, 50, 50, 50, color="blue")
enemy = epy.graphics.polygon(
    [(400, 100), (460, 180), (340, 180)],
    color="red"
)


def update(dt):
    player.x += 120 * dt
    if player.left > epy.getWidth():
        player.right = 0


def on_click(event):
    print("Click event:", event)


epy.bind("mainLoop", update)
epy.bind("leftMouseDown", on_click)
epy.run()

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

blu_easypygame-0.1.dev39.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

blu_easypygame-0.1.dev39-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file blu_easypygame-0.1.dev39.tar.gz.

File metadata

  • Download URL: blu_easypygame-0.1.dev39.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for blu_easypygame-0.1.dev39.tar.gz
Algorithm Hash digest
SHA256 511c75d894ac8ca2f059e733176c1999246f1d596c1a026d223b6c2997ca6159
MD5 13ff194c984276132e87dc8a0050bff5
BLAKE2b-256 a9607e8fb6792986be1d8485932293f4a00c8dfb7d95b1df5c6662dc7adf7911

See more details on using hashes here.

File details

Details for the file blu_easypygame-0.1.dev39-py3-none-any.whl.

File metadata

File hashes

Hashes for blu_easypygame-0.1.dev39-py3-none-any.whl
Algorithm Hash digest
SHA256 486a015c74359826d306e177030fa116c1b8b68de3e5b0f1c2747293ad0d73f2
MD5 7e83d346ffd49ad50d11c62fbd462518
BLAKE2b-256 99f77c329d6c32bb569fd50d590d2ede9b2e844679349ab8ab77fd0e704495ec

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