Pure-Python single-file library for writing simple games
MIT License
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)
gamelib.py
shouldpip
.Just download
gamelib.py
and place it alongside your project :)
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
$ python3 example-01-hello-world.py
play_sound()
, based onsay()
and input()
).