Skip to main content

A lightweight sprite-based game and graphics framework

Project description

automatic build status with Travis

ggame

The simple sprite and game platform for Brython Server (Pygame, Tkinter to follow?).

Ggame stands for a couple of things: "good game" (of course!) and also "git game" or "github game" because it is designed to operate with Brython Server in concert with Github as a backend file store.

Ggame is not intended to be a full-featured gaming API, with every bell and whistle. Ggame is designed primarily as a tool for teaching computer programming, recognizing that the ability to create engaging and interactive games is a powerful motivator for many progamming students. Accordingly, any functional or performance enhancements that can be reasonably implemented by the user are left as an exercise.

Please visit the detailed documentation page for ggame. This is generated automatically from the ggame sources.

Functionality Goals

The ggame library is intended to be trivially easy to use. For example:

from ggame import App, ImageAsset, Sprite
# Create a displayed object at 100,100 using an image asset
Sprite(ImageAsset("bunny.png"), (100,100))
# Create the app, with a default stage
app = App()
# Run the app
app.run()

Another Example

The following example illustrates the more common use case in which the basic ggame classes, Sprite and App, are subclassed as Bunny and DemoApp and given event handlers and step (i.e. poll) functions.

from ggame import App, ImageAsset, Sprite, MouseEvent
from random import random, randint

class Bunny(Sprite):

    asset = ImageAsset("bunny.png")

    def __init__(self, position):
        super().__init__(Bunny.asset, position)
        # register mouse events
        App.listenMouseEvent(MouseEvent.mousedown, self.mousedown)
        App.listenMouseEvent(MouseEvent.mouseup, self.mouseup)
        App.listenMouseEvent(MouseEvent.mousemove, self.mousemove)
        self.dragging = False


    def step(self):
        """
        Every now and then a bunny hops...
        """
        if random() < 0.01:
            self.x += randint(-20,20)
            self.y += randint(-20,20)


    def mousedown(self, event):
        # capture any mouse down within 50 pixels
        self.deltax = event.x - (self.x + self.width//2)
        self.deltay = event.y - (self.y + self.height//2)
        if abs(self.deltax) < 50 and abs(self.deltay) < 50:
            self.dragging = True
            # only drag one bunny at a time - consume the event
            event.consumed = True

    def mousemove(self, event):
        if self.dragging:
            self.x = event.x - self.deltax - self.width//2
            self.y = event.y - self.deltay - self.height//2
            event.consumed = True

    def mouseup(self, event):
        if self.dragging:
            self.dragging = False
            event.consumed = True


class DemoApp(App):

    def __init__(self):
        super().__init__()
        for i in range(10):
            Bunny((randint(50,self.width),randint(50,self.height)))

    def step(self):
        """
        Override step to perform action on each frame update
        """
        for bunny in self.spritelist:
            bunny.step()


# Create the app
app = DemoApp()
# Run the app
app.run()

Installing ggame

Before using ggame with your Python source repository on Github, you may add the ggame source tree to your repository. If you are executing your code in http://runpython.com, then the current ggame repository is already added to your import search path and no installation is required.

Contributing to ggame

Environment

Set up the development environment with Python 3.7+. For example, with this procedure.

Create a virtual environment with venv and activate it:

$ python3.7 -m venv venv
$ source venv/bin/activate

Install the requirements:

$ pip install -r requirements-headless.txt

Test your environment by running the tests:

$ scripts/run_tests.sh

Code Quality

Python sources in ggame should be passed through black. For example:

$ black ggame/app.py

Python sources should also be tested with pylint. For example:

$ python3 -m pylint -r n ggame/app.py

You can perform all of these checks in concert with a full Sphinx build by executing the script:

$ scripts/run_tests.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ggame-1.0.11.tar.gz (226.2 kB view details)

Uploaded Source

Built Distribution

ggame-1.0.11-py3-none-any.whl (231.4 kB view details)

Uploaded Python 3

File details

Details for the file ggame-1.0.11.tar.gz.

File metadata

  • Download URL: ggame-1.0.11.tar.gz
  • Upload date:
  • Size: 226.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for ggame-1.0.11.tar.gz
Algorithm Hash digest
SHA256 b9793c9c7fa4b51b01dc1d14b4ce5dc2a081915bd07a75ca2a1f32eb782d117a
MD5 b210d299f76c458786dc54e786c8db90
BLAKE2b-256 b470e6ac3d23235e6f1ddd7d6a944b991e677708e21da60ac1f9493c6509a65a

See more details on using hashes here.

File details

Details for the file ggame-1.0.11-py3-none-any.whl.

File metadata

  • Download URL: ggame-1.0.11-py3-none-any.whl
  • Upload date:
  • Size: 231.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for ggame-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7b2f706fb8dadcb64161c8f0548021b6d28f59d3fae9c8c051204b64ea06d0cd
MD5 21ec7429bdb1a0fdc0dd23299ecd0deb
BLAKE2b-256 f3f871240974af3faf9e2357b479dcf9a6fc85a4317cd6a5f58e6bb53dbf1971

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page