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
Chess Game using Python

Chess Game is a single-player game where the objective is same as the original chess game. You just need to place your chess piece in a correct position. The purpose of the system is to provide some

Yogesh Selvarajan 1 Aug 15, 2022
A small, Pygame-based library project intended for personal use.

EzyGame Version 0.0.1 A simple library project intended for personal use with Pygame. Warning: I am a very amateur programmer, so the code will probab

Dorbell 1 Jan 08, 2022
A Pygame game made in 48 hours

Flappuccino Flappuccino is a game created in 48 hours for the PyGame Community New Years Jam using Python with Pygame. Screenshots Background Informat

PolyMars 242 Jan 02, 2023
Aftermath is an anti token grabber written in Python3.

🎈 Aftermath 🎈 Aftermath is an anti token grabber written in Python3. This tool with a GUI setup is checking the Downloads folder to search for token

Billy 39 Dec 16, 2022
2D Minecraft Clone made with Python & Pygame & OpenGL

2D Minecraft Clone This is a 2D clone of the well-known game Minecraft made in Python using Pygame and ModernGL I started this mostly as a self-improv

Kadir Aksoy 2 Sep 25, 2022
🎅 Celebrating 2021 Christmas with the development of this game

ChristmasGame (DEVELOPING) 🎅 Celebrating Christmas with the development of this game You can also use this engine to create your game too, just empty

Érik Freitas 5 Jan 10, 2022
Utility to find games owned by all (or at least some) of the passed players.

SteamCommonGameFinder Utility to find games that are owned by all (or at least some) of the players you pass into this programm. You can already find

Daniel O'Grady 4 Jan 04, 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
Bingo game now in python play as much you want :) no need to give me credit it's open as fuck

Bingo-py-game A game coded with Python Introduction This is a Terminal-based game currently in its initial stage. I am working on adding more efficien

Frey 5 Aug 12, 2021
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 07, 2023
Chesston (Chess+Python) is a two-player chess game with graphical user interface written in PyQt5

♟️ Chesston (Chess+Python) is a two-player chess game with graphical user interface written in PyQt5. 💿 Dependencies This program uses Py

6 May 26, 2022
中文版本的ai地牢,一个使用GPT-2的文字冒险游戏,使用清源CPM预训练模型finetune而成。

中文版本的ai地牢,一个使用GPT-2的文字冒险游戏,使用清源CPM预训练模型finetune而成。

icybee 178 Jan 03, 2023
2d war game single player

WarGame-third-version-0.0.4- 2d war game single player Hi ! Today, I publish on GitHub the version 0.0.4 of "WarGame". In this version, you can find a

Edouard Vincent 2 Apr 08, 2022
Game-of-life - A simple python program to simulate and visualise the Conway's Game of life

Conway's game of life A simple python program to simulate and visualise the Conw

Dhravya Shah 3 Feb 20, 2022
Historical battle simulation package for Python

Jomini v0.1.4 Jomini creates military simulations by using mathematical combat models. Designed to be helpful for game developers, students, history e

Ümit Kaan Usta 36 Dec 08, 2022
Command-line Hangman game

Hang-_an-game-python-build Hangman C command-line Hangman game. Compilation Navigate to the root of the repository from your Terminal and run make to

Hemant Choudhary 3 Jan 16, 2022
offline bot for game on chrome

Бот офлайн игры браузера CHROME В автоматическом режиме запускает браузер Chrome под ОС windows, так же автоматически определяет разрешения экрана, на

Andrej Marinchenko 19 Dec 17, 2022
Continuous form of the game Wits & Wagers

wager Continuous form of the game Wits & Wagers Requires: Pygame, Pygame_gui

1 Nov 22, 2021
This is a simple rock paper scissor game created with python.

This is a simple rock paper scissor game created with python.

Fayas Noushad 3 Feb 04, 2022
Inject custom C++ code into GameMaker Studio 2 YYC builds

YYC Boost Inject custom C++ code into GameMaker Studio 2 YYC builds! WARNING: This tool is currently in an early stage of development and it is not gu

Patrik Kraif 7 Dec 30, 2022