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)frompygame.init()
Arguments:
width— window width in pixelsheight— window height in pixelsbg— background colorbackground— alias forbgframe— target frames per secondbusy— 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, receivesdtin secondsphysicsLoop— called each frame, receives physics delta time in secondsphisicLoop— legacy alias forphysicsLoopmouseDown— any mouse button pressmouseUp— any mouse button releaseleftMouseDown,leftMouseUpmiddleMouseDown,middleMouseUprightMouseDown,rightMouseUpmouseMotion— mouse movementmouseWheel— wheel scrollingkeyDown,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,yleft,right,top,bottomwidth,heightfor rectangles and ellipsesradiusfor circles and squarespointsfor lines and polygonsanglefor rotated shapescolor
Example:
rect.x += 5
rect.color = "blue"
print(circle.radius)
Event data
Mouse callbacks receive a parameter dictionary with values like:
pos— mouse positionrel— relative movementbuttons— button statetouch— touch input datawindow— window event datax,y— wheel delta values
Keyboard callbacks receive:
unicodekeymodscancode
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
511c75d894ac8ca2f059e733176c1999246f1d596c1a026d223b6c2997ca6159
|
|
| MD5 |
13ff194c984276132e87dc8a0050bff5
|
|
| BLAKE2b-256 |
a9607e8fb6792986be1d8485932293f4a00c8dfb7d95b1df5c6662dc7adf7911
|
File details
Details for the file blu_easypygame-0.1.dev39-py3-none-any.whl.
File metadata
- Download URL: blu_easypygame-0.1.dev39-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
486a015c74359826d306e177030fa116c1b8b68de3e5b0f1c2747293ad0d73f2
|
|
| MD5 |
7e83d346ffd49ad50d11c62fbd462518
|
|
| BLAKE2b-256 |
99f77c329d6c32bb569fd50d590d2ede9b2e844679349ab8ab77fd0e704495ec
|