Package: ggame
ggameThe 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 withBrython Serverin concert with
Github as a backend file store.Ggame isnotintended 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 thatcanbe reasonably implemented
by the user are left as an exercise.Please visit thedetailed documentation page for ggame.
This is generated automatically from the ggame sources.Functionality GoalsThe ggame library is intended to be trivially easy to use. For example:fromggameimportApp,ImageAsset,Sprite# Create a displayed object at 100,100 using an image assetSprite(ImageAsset("bunny.png"),(100,100))# Create the app, with a default stageapp=App()# Run the appapp.run()Another ExampleThe 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.fromggameimportApp,ImageAsset,Sprite,MouseEventfromrandomimportrandom,randintclassBunny(Sprite):asset=ImageAsset("bunny.png")def__init__(self,position):super().__init__(Bunny.asset,position)# register mouse eventsApp.listenMouseEvent(MouseEvent.mousedown,self.mousedown)App.listenMouseEvent(MouseEvent.mouseup,self.mouseup)App.listenMouseEvent(MouseEvent.mousemove,self.mousemove)self.dragging=Falsedefstep(self):"""Every now and then a bunny hops..."""ifrandom()<0.01:self.x+=randint(-20,20)self.y+=randint(-20,20)defmousedown(self,event):# capture any mouse down within 50 pixelsself.deltax=event.x-(self.x+self.width//2)self.deltay=event.y-(self.y+self.height//2)ifabs(self.deltax)<50andabs(self.deltay)<50:self.dragging=True# only drag one bunny at a time - consume the eventevent.consumed=Truedefmousemove(self,event):ifself.dragging:self.x=event.x-self.deltax-self.width//2self.y=event.y-self.deltay-self.height//2event.consumed=Truedefmouseup(self,event):ifself.dragging:self.dragging=Falseevent.consumed=TrueclassDemoApp(App):def__init__(self):super().__init__()foriinrange(10):Bunny((randint(50,self.width),randint(50,self.height)))defstep(self):"""Override step to perform action on each frame update"""forbunnyinself.spritelist:bunny.step()# Create the appapp=DemoApp()# Run the appapp.run()Installing ggameBefore 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 inhttp://runpython.com, then the current
ggame repository is already added to your import search path and no installation is required.Contributing to ggameEnvironmentSet up the development environment with Python 3.11.Create a virtual environment with venv and activate it:$ python3.11 -m venv env
$ source env/bin/activateInstall the requirements:$ python3.11 -m pip install -r requirements-headless.txtTest your environment by running the tests:$ scripts/run_tests.shCode QualityPython sources in ggame should be passed throughblack. For example:$ black ggame/app.pyPython sources should also be tested withpylint. For example:$ python3.11 -m pylint -r n ggame/app.pyYou can perform all of these checks in concert with a full Sphinx build
by executing the script:$ scripts/run_tests.sh