Ultra-Minimalist Game Framework

This is an even more minimalist version of my minimalist game framework. It uses Python 3 and pygame.

A few decisions have been made to keep things simple:

Getting Started

Getting started with the ultra-minimalist game framework is easy!

  1. Download game.py and place it in the same folder as your Python script.
  2. Add import game to the top of your script.
  3. Start calling functions in the game module to create your game.

All functions and enums listed below are members of the game module. If you wanted to draw a line, you would call game.draw_line() from your code.

If you don't already have pygame installed, you can install it by running pip install pygame on the command line.


Example Screenshot

import game
import random


game.set_title('Bouncing Faces')

class Face:
    def __init__(self):
        self.x = random.randint(1, 141)
        self.y = random.randint(1, 90)
        self.vx = random.uniform(-1, 1)
        self.vy = random.uniform(-1, 1)

faces = []
for i in range(0, 20):

while True:
    # Move the faces:
    for face in faces:
        if face.x <= 0 or face.x >= 142:
            face.vx *= -1
        if face.y <= 0 or face.y >= 91:
            face.vy *= -1
        face.x += face.vx
        face.y += face.vy

    # Draw the screen:
    for face in faces:
        # Draw the face, using an alternate sprite if it's overlapping any other face:
        sprite = IMG_FACE_NORMAL
        for otherFace in faces:
            if face != otherFace and game.test_sprites(IMG_FACE_NORMAL, face.x, face.y, IMG_FACE_NORMAL, otherFace.x, otherFace.y):
                sprite = IMG_FACE_HIT
        game.draw_sprite(sprite, face.x, face.y)
        # Draw a box around the face when it's hovered, and beep when it's clicked:
        if game.test_sprite(sprite, face.x, face.y, game.get_mouse_x(), game.get_mouse_y()):
            game.draw_rect(game.Color.WHITE, face.x - 2, face.y - 2, 12, 13, False)
            if game.is_mouse_down(game.Button.LEFT):
                game.play_sound(game.Instrument.SQUARE, game.Note.C4, 0.2)

    # End of frame:


def wait_for_frame()

def wait_for_seconds(duration: float)

def wait_for_close()

def wait_for_input(prompt: str) -> str

def set_title(title: str)

Drawing and Sprites

def clear_screen(color: Color)

def draw_pixel(color: Color, x: int, y: int)

def draw_line(color: Color, x1: int, y1: int, x2: int, y2: int)

def draw_rect(color: Color, x: int, y: int, width: int, height: int, fill: bool)

def draw_circle(color: Color, x: int, y: int, radius: int, fill: bool)

def draw_triangle(color: Color, x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, fill: bool)

def draw_text(text: str, color: Color, x: int, y: int, alignment: Alignment) -> tuple[int, int]

def draw_sprite(sprite: str, x: int, y: int)

Collision Detection

def test_rect(x: int, y: int, width: int, height: int, test_x: int, test_y: int) -> bool

def test_circle(x: int, y: int, radius: int, test_x: int, test_y: int) -> bool

def test_sprite(sprite: str, x: int, y: int, test_x: int, test_y: int) -> bool

def test_sprites(sprite1: str, x1: int, y1: int, sprite2: str, x2: int, y2: int) -> bool

Sound Effects

def play_sound(instrument: Instrument, note: Note, duration: float, delay: float = 0.0, volume: float = 1.0)

Keyboard Input

def is_key_down(key: Key) -> bool

def is_key_held(key: Key) -> bool

def is_key_up(key: Key) -> bool

def get_typed_text() -> str

Mouse Input

def get_mouse_x() -> int

def get_mouse_y() -> int

def is_mouse_down(button: Button) -> bool

def is_mouse_held(button: Button) -> bool

def is_mouse_up(button: Button) -> bool

def set_cursor_visible(visible: bool)


class Color (Enum)

class Alignment (Enum)

class Instrument (Enum)

class Note (Enum)

class Key (Enum)

class Button (Enum)