Skip to content

Easy Game

py_simple.easy_game

easy_game is built on top of pygame to simplify the tricky parts of building games.

EasyGameError

Bases: Exception

Raised when a pygame window/game can't be set up.

Wraps whatever pygame raises internally (bad dimensions, display driver issues, etc.) so py_simple functions can fail with one consistent, easy-to-read exception instead of a random builtin or pygame-specific one.

Parameters:

Name Type Description Default
message str

Human-readable description of what went wrong.

required

basic_game_setup(width, height, title='My Game')

Sets up a pygame window and clock in one call, handling the pygame.init(), display, caption, and clock boilerplate every pygame project needs before the game loop can start.

Parameters:

Name Type Description Default
width int

Width of the game window, in pixels.

required
height int

Height of the game window, in pixels.

required
title str

Text shown in the window's title bar. Defaults to "My Game".

'My Game'

Returns:

Name Type Description
tuple tuple

(screen, clock), where screen is the pygame Surface returned by pygame.display.set_mode() and clock is a pygame.time.Clock instance.

Raises:

Type Description
EasyGameError

If pygame fails to initialize or set up the window (e.g. invalid width/height, display driver issue).

Example
from py_simple import basic_game_setup

screen, clock = basic_game_setup(800, 600, "My Game")
import pygame

pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()

check_if_quit()

Checks the pygame event queue for a quit event (e.g. the window's close button), saving you from writing the for event in pygame.event.get() loop yourself every frame.

Returns:

Name Type Description
bool bool

True if a quit event was found in the queue, False otherwise.

Example
from py_simple import check_if_quit

running = True
while running:
    if check_if_quit():
        running = False
import pygame

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

get_mouse_position()

Gets the current position of the mouse cursor, saving you from remembering the exact pygame call.

Returns:

Name Type Description
tuple tuple

(x, y) coordinates of the mouse cursor, in pixels, relative to the top-left corner of the window.

Example
from py_simple import get_mouse_position

x, y = get_mouse_position()
import pygame

x, y = pygame.mouse.get_pos()

is_left_mouse_button_clicked()

Checks whether the left mouse button is currently held down.

Returns:

Name Type Description
bool bool

True if the left mouse button is being pressed, False otherwise.

Example
from py_simple import is_left_mouse_button_clicked

if is_left_mouse_button_clicked():
    print("Left click!")
import pygame

if pygame.mouse.get_pressed()[0]:
    print("Left click!")

is_middle_mouse_button_clicked()

Checks whether the middle mouse button (scroll wheel) is currently held down.

Returns:

Name Type Description
bool bool

True if the middle mouse button is being pressed, False otherwise.

Example
from py_simple import is_middle_mouse_button_clicked

if is_middle_mouse_button_clicked():
    print("Middle click!")
import pygame

if pygame.mouse.get_pressed()[1]:
    print("Middle click!")

is_right_mouse_button_clicked()

Checks whether the right mouse button is currently held down.

Returns:

Name Type Description
bool bool

True if the right mouse button is being pressed, False otherwise.

Example
from py_simple import is_right_mouse_button_clicked

if is_right_mouse_button_clicked():
    print("Right click!")
import pygame

if pygame.mouse.get_pressed()[2]:
    print("Right click!")