Skip to main content

An easier way to use pygame

Project description

Blu Easy Pygame

Blu Easy Pygame is a small library built on top of pygame that simplifies the process of starting basic games. Instead of writing the same setup code repeatedly, you can just set up a window, create shapes, bind events, and start the game loop.

It includes:

  • Easy window setup
  • A built-in game loop
  • Simple event binding
  • Built-in shapes like rectangles, circles, ellipses, squares, lines, and polygons

Installation

First, install pygame.

python -m pip install pygame

If you're working on the project locally:

python -m pip install -e .

If it's uploaded to PyPI, you can install it with:

python -m pip install Blu_easypygame

Quick Start

import Blu_easypygame as epy

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

# Make some 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")
triangle = 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 clicked(event):
    print("Mouse clicked!", event)

epy.bind("mainLoop", update)
epy.bind("leftMouseDown", clicked)

epy.run()

Main Functions

epy.init()

Creates the game window and starts pygame.

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

Returns the values from pygame.init().


epy.run()

Starts the game loop.

It continues until the window is closed or you call:

epy.stop()

epy.bind()

Lets you connect your own functions to events.

Example:

epy.bind("mainLoop", update)
epy.bind("leftMouseDown", clicked)

Some supported events:

  • mainLoop
  • physicsLoop
  • mouseDown
  • mouseUp
  • leftMouseDown
  • leftMouseUp
  • middleMouseDown
  • middleMouseUp
  • rightMouseDown
  • rightMouseUp
  • mouseMotion
  • mouseWheel
  • keyDown
  • keyUp

Other useful functions

epy.unbind("mainLoop")
epy.stop()

epy.getWidth()
epy.getHeight()

epy.getFPS()
epy.getGameTime()

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

epy.sleep(1000)

Shapes

All shapes are created through epy.graphics.

They are automatically drawn every frame, so you don't need to draw them manually.

Rectangle

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

Circle

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

Ellipse

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

Square

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

Line

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

Polygon

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

Shape Properties

Most shapes have properties you can change anytime.

Some common ones are:

  • x
  • y
  • left
  • right
  • top
  • bottom
  • color
  • angle

Some shapes also have:

  • width
  • height
  • radius
  • points

Example:

box.x += 5
box.color = "blue"

print(circle.radius)

Event Data

Mouse events give you a dictionary with information such as:

  • mouse position
  • which buttons are pressed
  • movement
  • wheel scrolling

Keyboard events include information like:

  • key
  • unicode
  • modifiers
  • scancode

Example:

def on_click(event):
    print(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(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.dev44.tar.gz (137.2 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.dev44-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blu_easypygame-0.1.dev44.tar.gz
  • Upload date:
  • Size: 137.2 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.dev44.tar.gz
Algorithm Hash digest
SHA256 fa24de80c9ae5b687aa331ae6546fee70afe1e5a0a397510bbd2e2b939847c0c
MD5 08e96a3ecfaa633469c6465672d561ed
BLAKE2b-256 91adec4513b0ed3b566b94f18f21e5ae629c3fa812169d7ed061a006f2a4496e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blu_easypygame-0.1.dev44-py3-none-any.whl
Algorithm Hash digest
SHA256 3b41b8a89127d43c97172162cfa5fc6199236fc06ddb6d94cca515f62af82fa8
MD5 f121f3152d936b529d046cd273b3651c
BLAKE2b-256 564320a08a63fcd1280d710f4ba5e1bb1de3d65d20ba9349a34ab661fa18df8a

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