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.
Owner
Diego Essaya
Diego Essaya
Pygame Raycaster made by me.

Pygame Raycaster made by me.

Sable 0 Jan 10, 2022
Python Knots and Crosses game, with customizable markers and more!

Knot-and-Crosses Python Knots and Crosses game, with customizable markers and more! Features: Ability to change your marker Ability to change how many

4 Nov 07, 2021
A python game engine.

PursuedPyBear, also known as ppb, exists to be an educational resource. Most obviously used to teach computer science, it can be a useful tool for any topic that a simulation can be helpful.

PPB 235 Jan 08, 2023
The Turtle Race Game built in Python with Turtle module.

Turtle Race Game The Turtle Race Game built in Python with Turtle module. Installation If you don't have Turtle module on your computer. You can downl

Aytaç Kaşoğlu 1 Nov 09, 2021
A Higher-Lower web game made in Python using Flask framework.

Higher Lower Web Game Guess the random number from 0 to 9 in this web game made with Python and Flask Framework Modules that were used Random Flask In

Yago Goltara 1 Oct 27, 2021
Minecraft Bedrock Server Control GUI

A control dashboard to monitor and control your minecraft bedrock dedicated server through an easy user interface. Created by Nathan-Busse 13 January 2022 Made with Python 3.8

Nathan Busse 3 Dec 11, 2022
🌍🍓 A better MCPi Launcher

Planet Launcher A better, maintained launcher for the Minecraft: Pi Edition Reborn mod. Report Bug | Request Feature Planet is a maintained, feature-r

15 Oct 19, 2022
3D online shooter written on Panda3D 1.10.10 and Python 3.10.1

на русском itch.io page Droid Game 3D This is a fresh game that was developed using the Panda3D game engine and Python language in the PyCharm IDE (I

Marcus Kemaul 5 Jun 04, 2022
A python script that uses pygame to display fractals.

Pygame-Fractals A python script that uses pygame to display interactive fractals. There are 3 fractals on the script. They can be displayed on the col

michel 2 Feb 09, 2022
A tool for the creation of rooms used in maps in the game Wastelands

Wastelands Room Data editor A tool for the creation of rooms used in maps in the game Wastelands Creates .wrd files, that get loaded by the map genera

Avant 6 Jul 12, 2021
Lucky Balls is gambling game where user try to guess 6 numbers from 1 to 48 that computer has picked.

LUCKY BALLS Lucky Balls is gambling game where user try to guess 6 numbers from 1 to 48 that computer has picked. INSTRUCTIONS User input his bet, tha

rile037 2 Dec 28, 2021
Flappy Bird clone utilizing facial recognition to move the

Flappy Face Flappy Bird clone utilizing facial recognition to move the "bird" How it works Flappy Face uses Facial Recognition to detect your face's p

Brady McDermott 1 Jan 11, 2022
Minesweeper clone with 3 modes of difficulty, UI scaling and custom games feature.

Insect Sweeper Minesweeper clone with 3 modes of difficulty, UI scaling and custom games feature. Mines are replaced with random insects that a player

Piotr Data 1 Nov 05, 2021
An algorithm to reach a correlated equilibrium in multiplayer games.

Correlatedpy: a python library for distributed learning of correlated equilibrium in multiplayer strategic games. View Demo · Report Bug · Request Fea

Omar Boufous 2 Feb 01, 2022
A python snake game based on pygame.

PySnake A python snake game based on pygame. Requirements Package version pygame = 2.1.2 opencv-python = 4.5.1.48 Run Windows python main.py Linux &

2 Jan 31, 2022
2DMC is an abrrieviation for 2 Dimensional Minecraft.

2DMC 2DMC is an abrrieviation for 2 Dimensional Minecraft. This idea is originally created and implemented by Griffpatch on Scratch. This is a persona

DaNub 5 Nov 06, 2022
A visualization of how much Manchester United fans enjoyed each game from the first half of the 21/22 Premier League season.

Man-Utd-Fan-Satisfaction-Levels-First-19-games A visualization of how much Manchester United fans enjoyed each game from the first half of the 21/22 P

1 Jan 19, 2022
游戏中按TAB键查看所有玩家分数的小程序

DDNet-show-points-in-game DDRaceNetwork 游戏中按TAB键查看所有玩家分数的小程序

3 Oct 13, 2022
SuperChess is a GUI application for playing chess.

About SuperChess is a GUI application for playing chess. It is written in Python 3.10 programming language, uses PySide6 GUI library, python-chess lib

Boštjan Mejak 1 Oct 16, 2022
To be easier to create backup files for the game StoneShard

StoneShard_save_backup_tool A tool to create backups and load them. Setup Configure the program by opening the "config.json" file. In this file you wi

Lucas V. Moog Brentano 6 Sep 15, 2022