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_easypygame provides:

  • a simple init() function for window setup
  • a single run() loop for frame updates
  • callback binding for frame and input events
  • shape factories 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_easypygame

Quick Start

import Blu_easypygame as epy

# 1. Initialize the window
epy.init(width=640, height=480, bg="lightgray")

# 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"
)

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

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

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

Core API (summary)

  • 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().
  • epy.run() — Start the main game loop. The loop finishes when the window closes or epy.stop() is called.

  • epy.run() — Start the main game loop. Runs all bound callbacks and draws shapes each frame until stopped.

  • epy.bind(funcType, func) — Register a callback. Supported funcType values include:

    • mainLoop — called each frame with dt in seconds
    • physicsLoop — called each frame with a physics delta time
    • phisicLoop — legacy alias for physicsLoop (kept for backwards compatibility)
    • mouseDown, mouseUp, leftMouseDown, leftMouseUp, middleMouseDown, middleMouseUp, rightMouseDown, rightMouseUp
    • mouseMotion, mouseWheel, keyDown, keyUp
  • epy.unbind(funcType) — Remove a bound callback.

  • epy.stop() — Stop the running game loop.

  • epy.getWidth(), epy.getHeight() — Return current window dimensions.

  • epy.getFPS() — Return the current frame rate value.

  • epy.getGameTime() — Return elapsed game time in milliseconds.

  • epy.getBackground() / epy.setBackground(color) — Read or change background color.

  • epy.sleep(milliseconds, processOS=True) — Pause execution for the given time (milliseconds).

  • epy.unbind(funcType) — Remove a previously bound callback for funcType.

  • epy.stop() — Request the loop to exit on the next frame.

  • epy.getWidth(), epy.getHeight() — Return current window dimensions (pixels).

  • epy.getFPS() — Return the measured frames per second.

  • epy.getGameTime() — Return elapsed game time in milliseconds since pygame.init().

  • epy.getBackground() / epy.setBackground(color) — Get or set the current clear/background color.

  • epy.sleep(milliseconds, processOS=True) — Pause the game loop; processOS=True uses wait, otherwise delay.

Examples:

width = epy.getWidth()
fps = epy.getFPS()
epy.setBackground("black")

Shapes

Create shapes with epy.graphics. They are drawn automatically each frame.

  • epy.graphics.rect(x, y, width, height, angle=0, color="black")
  • epy.graphics.rect(x, y, width, height, angle=0, color="black") — Create a rectangle shape positioned with center at (x, y).
  • epy.graphics.circle(x, y, radius, color="black") — Create a circle shape centered at (x, y).
  • epy.graphics.ellipse(x, y, width, height, angle=0, color="black") — Create an ellipse with given size and rotation.
  • epy.graphics.square(x, y, radius, angle=0, color="black") — Create a square (radius = half side length) centered at (x, y).
  • epy.graphics.line(points, width=1, color="black") — Create a polyline connecting points; set width for stroke.
  • epy.graphics.polygon(points, width=0, angle=0, color="black") — Create a filled (width=0) or stroked polygon from points.

Common properties on shapes:

  • x, y, left, right, top, bottom
  • width, height (rectangles, ellipses)
  • radius (circles, squares)
  • points (lines, polygons)
  • angle, color

Example:

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

Event data

Mouse callbacks receive a dictionary with keys such as pos, rel, buttons, touch, window, and wheel deltas x, y.

Keyboard callbacks receive unicode, key, mod, and scancode values.

Example:

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

epy.bind("leftMouseDown", on_click)

Full example

import Blu_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()

If you spot any remaining inconsistencies or want the README formatted for PyPI/long description, I can update it accordingly.

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.dev41.tar.gz (59.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.dev41-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blu_easypygame-0.1.dev41.tar.gz
  • Upload date:
  • Size: 59.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.dev41.tar.gz
Algorithm Hash digest
SHA256 8f5d2d506f3a94383d2963a4a91a1eb3de225c02bfd72efb0ca8622e090a3e3a
MD5 38af79563f2e6e23c0593c6550a0f947
BLAKE2b-256 7bd01cd0faeeb66be50a5a46057edcb079fa8bf33d1420e6b74ec188bdf2fd52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blu_easypygame-0.1.dev41-py3-none-any.whl
Algorithm Hash digest
SHA256 afb7300ab5a4e5108e5a82f5f29baa72f58903c6a8c4be3a1ce9cde6eeeda64b
MD5 0d2deda2e17e67260ebb903ef86dd5c6
BLAKE2b-256 aca5a2c46a1db2c542579f256ed2be93d1298445f22cdfc3444e500731f65efd

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