Gamelib is a pure-Python single-file library/framework for writing simple games.

Overview

Gamelib

Gamelib is a pure-Python single-file library/framework for writing simple games. It is intended for educational purposes (e.g. to be used in basic programming courses).

Here is a "hello world" example:

import gamelib

def main():
    gamelib.resize(300, 300)

    gamelib.draw_begin()
    gamelib.draw_text('Hello world!', 150, 150)
    gamelib.draw_end()

    # wait until the user presses any key
    gamelib.wait(gamelib.EventType.KeyPress)

gamelib.init(main)

And this example shows a rectangle moving around the screen:

import gamelib

def main():
    gamelib.resize(300, 300)

    x, y = 150, 80
    dx, dy = 5, 5

    while gamelib.loop(fps=30):
        for event in gamelib.get_events():
            if event.type == gamelib.EventType.KeyPress and event.key == 'q':
                return

        gamelib.draw_begin()
        gamelib.draw_rectangle(x-10, y-10, x+10, y+10, fill='red')
        gamelib.draw_end()

        x += dx
        y += dy
        if x > 300 or x < 0:
            dx *= -1
        if y > 300 or y < 0:
            dy *= -1

gamelib.init(main)

Goals

  • Easy to learn: Writing a simple game should be almost as easy as writing console programs. It should not require knowledge about inheritance, components, double-buffering, color channels, blitting or actors.
  • Simple, basic API: Support drawing stuff and maybe playing sounds, nothing more.
  • Portable Support Windows / Mac OS / Linux desktop.
  • Easy to install: See relevant XKCD. gamelib.py should not depend on anything that's not available in a fresh Python installation. That rules out pip.

Installation

Just download gamelib.py and place it alongside your project :)

Documentation

First, look into the provided examples!

Gamelib library reference: https://dessaya.github.io/python-gamelib/

To generate the HTML documentation:

$ pip3 install pdoc3
$ bash docs/generate.sh

Run the examples

$ python3 example-01-hello-world.py

Limitations

  • Very limited drawing API (based on Tkinter Canvas).
    • Don't expect to be able to draw thousands of elements at 60 FPS.
    • The only image formats that are supported accross all platforms are GIF and PPM/PGM/PBM.
  • Very limited sound API (just a single function: play_sound(), based on playsound).
    • The only sound format supported accross all platforms is probably WAV.
  • Very limited GUI API (just two functions: say() and input()).
  • Supports only a single window.
  • No joystick support.
You might also like...
Python Interactive Mini Games
Python Interactive Mini Games

Python Interactive Mini Games Mini projects from Coursera's An Introduction to I

Find live blooket games easy with python.

Blooket-pin-finder Find live blooket games easy with python. info when you start you will see what looks like error DON'T STOP those are just the thre

AI plays games with python

AI-plays-games- To use it, you first need to create an img file and save the pic

Python game engine for 2D multiplayer online games.

LAN-Caster The goal of LAN-Caster is to provide an easy-to-use code base (game engine) for developing 2D multiplayer online games. LAN-Caster original

AI Games and its programming solution with Python.

Problem: Save the princess: Problem defination on Hackerrank: https://www.hackerrank.com/challenges/saveprincess About problem: Princess Peach is trap

A pure python implementation of a solver for the popular game wordle.

A pure python implementation of a solver for the popular game wordle.

A pure-Python Wordle and Absurdle solver

Pyrdle A pure-Python Wordle and Absurdle solver Find the originals here: Wordle Absurdle Basic solving: Wordle To solve today's Wordle, simply run: ./

A comprehensive, feature-rich, open source, and portable, collection of Solitaire games.
A comprehensive, feature-rich, open source, and portable, collection of Solitaire games.

PySol Fan Club edition This is an open source and portable (Windows, Linux and Mac OS X) collection of Card Solitaire/Patience games written in Python

To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.
To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.

To solve games using AI, we will introduce the concept of a game tree followed by minimax algorithm.

Comments
  • Deprecated reference to mouse buttons

    Deprecated reference to mouse buttons

    Dunno if this counts as an issue, but looking through the doc, I realized that it refers to the left, middle and right click buttons of the mouse as 0, 1 and 2 respectively.

    https://github.com/dessaya/python-gamelib/blob/9cb0d87ef88712091560deb5d74295ae78461fb0/gamelib.py#L649

    It may be because they updated it, but Tkinter actually refers to these buttons as 1, 2 or 3 respectively. This could lead to confusion.

    imagen

    Already confirmed this is the case testing it on my own project.

    opened by NLGS2907 0
  • Infinite looping print

    Infinite looping print

    https://github.com/dessaya/python-gamelib/blob/52f168a6b9fc0b3b83d33a2a40201c023ff18ff2/gamelib.py#L103

    I'm guessing it was for test use only. Would be nice to remove it.

    opened by mjsantoni 0
Owner
Diego Essaya
Diego Essaya
Datamining of 15 Days of (free) Games at the Epic Games Store (EGS).

EGS: 15 Days of Games This repository contains Python code to data-mine the 15 Days of (free) Games at the Epic Games Store (EGS). Requirements Instal

Wok 9 Dec 27, 2022
pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame is a Free and Open Source python programming language library for making multimedia applications like games built on top of the excellent SDL library. C, Python, Native, OpenGL.

pygame 5.6k Jan 1, 2023
An all-inclusive Python framework for the Riot Games League of Legends API. We focus on making the data easy and fun to work with, while providing all the tools necessary to create a website or do data analysis.

Cassiopeia A Python adaptation of the Riot Games League of Legends API (https://developer.riotgames.com/). Cassiopeia is the sister library to Orianna

Meraki Analytics 473 Jan 7, 2023
Overview: copain, your friendly AI framework to learn and play games

Overview: copain, your friendly AI framework to learn and play games Interface fceux with python and run reinforcement learning. Compatibility Current

fcharras 1 Dec 16, 2021
A networking library for multiplayer games.

Aerics A networking library for multiplayer games. Getting Started Install Python Open cmd/terminal and type: pip install Aerics Examples Creating a

Yusuf Rençber 3 Jan 4, 2023
TwoDMaker (2DMaker) - Simple engine for 2D games making!

TwoDMaker (2DMaker) - Simple engine for 2D games making! Create simple games (or ui) in one hour! About. This is a simple engine for game or gui app c

Ivan Perzhinsky. 1 Jan 3, 2022
Pong is one of the first computer games that ever created, this simple

Pong-Game Pong is one of the first computer games that ever created, this simple "tennis like" game features two paddles and a ball, the goal is to de

Lateefah Ajadi 0 Jan 15, 2022
Sukoku-solver Python About Sudoku is one of the most popular puzzle games of all time

Sukoku-solver Python About Sudoku is one of the most popular puzzle games of all time. As a logic puzzle, Sudoku is also an excellent brain game. Bein

Harshith VH 1 Nov 20, 2021
learn and have fun developing 2D retro games using python and pygame

Retro 2D Game Development Using Python + PyGame Skill up your programming skills with a walk down the memory lane. Learn how to create a retro 2D game

Marvin Trilles 1 Feb 23, 2022
Several implementations of classical games (ex: FlappyBird, Minesweeper etc.) using Python (pygame)

Mini Games with Pygame This projects implement several classic and popular games in Python, using python package -- pygame. Currently, 4 games are alr

null 1 Feb 14, 2022