Package: pyRetroGame
PyRetroGame ( Beta )InstallationpipinstallpyretrogameGetting StartedCreate a file and import the libraryimportpyRetroGameDeclare the game variablegame=pyRetroGame.game.Game(size=Vector2(15,15))And start the gamegame.start()Congrats! Now you can initialize the game window.Initialize PlayerCreate a Player class and extend pyRetroGame.objects.gameEntityclassPlayer(pyRetroGame.objects.gameEntity):def__init__(self,*args,**kwargs):super().__init__(*args,**kwargs)def__str__(self):# return the Player Texturereturn'X'Declare the player variable# Must return game var to the playerplayer=Player(position=Vector2(0,0),game=game)Spawn the playergame.spawn(player)Congrats! You've spawned the Player.Player Movements and Keyboard InputsTo move the Player we use the move function that accepts the direction argument as Vector2(x, y)player.move(Vector2(1,0))In pyRetroGame for getting inputs we use Decorators, Here's an example:@game.inputHandler('w')defmoveUp():player.move(Vector2(0,-1))You can also use a list of key, but you need to pass a key argument to the function@game.inputHandler(['w','s','a','d'])defmovements(key):ifkey=='w':player.move(Vector2(0,-1))Here's a total movements function@game.inputHandler(['w','s','a','d'])defmovements(key):ifkey=='w':player.move(Vector2(0,-1))ifkey=='s':player.move(Vector2(0,1))ifkey=='a':player.move(Vector2(-1,0))ifkey=='d':player.move(Vector2(1,0))Congrats! Now you have a Player who moves in the game window.Custom BackgroundTo change the background of the game window you need to use a Background class that return the background textureclassBackground():def__str__(self):# return the Background Texturereturn'0'And pass the Background class to gamegame=pyRetroGame.game.Game(background=Background,size=Vector2(15,15))Congrats! You have changed the background of the game window.Game Objects and CollisionsTo create a game object you need to create a class and extend pyRetroGame.objects.gameObjectclassSolidBlock(pyRetroGame.objects.gameObject):def__init__(self,*argvs,**kwargs):super().__init__(*argvs,**kwargs)# Game Objects has an argument called solid, if you want to make the object solid you need to set it to Trueself.solid=Truedef__str__(self):# return the SolidBlock Texturereturn'B'Declare the solidBlock variablewall=SolidBlock(position=Vector2(5,2),game=game)And spawn the solid blockgame.spawn(wall)Now, when the player collides with the solidBlock, it will be stoppedIf you want to check when the player collides with the solidBlock, you can use the collisionHandler decorator@player.collisionHandler(wall)defonCollideWithWall():# Do something when the player collides with the wallpassIf you want to check when the player collides with the solidBlock, you can use the limitHandler decorator@player.limitHandler()defonCollideWithLimit(side):# side argument return 'right' - 'left' - 'top' - 'bottom'# Do something when the player collides with the limit of the game windowpassCongrats! Now you have a solid block that stops the player when it collides with it.Game ProcessIf you need a loop you can use the @game.process decorator@game.process()defprocess():deltaTime=0.1whileTrue:# Insert your Code Here# Very important to declare a delay if you won't the game crashtime.sleep(deltaTime)Congrats! Now you have a game loop.Congrats! You've finished the tutorial. You're now ready to start your own game.Other FunctionalitiesIn the game var you can pass the fixedSize argument to set the window size perfectly match with the game sizegame=pyRetroGame.game.Game(background=Background,size=Vector2(15,15),fixedSIze=True)In game.start() you can pass the fps argument to set the game FPSgame.start(fps=60)And you can also pass a debugging argument to set the debug modegame.start(fps=60,debugging=True)If you need to print some Text you have 2 built-in functions:game.printText(text="Hello World",timeout=2)game.printAnimatedText(text="Hello World",animationTimeout=0.05,timeout=2)If you need for some assets you can import the assets packagefrompyRetroGame.assetsimport*TextAssets.FilledBlock# 'â–ˆ'TextAssets.BlankSpace# ' 'If need for some calculations you can import the gameMath packagefrompyRetroGame.gameMathimport*# Return the distance beetween two Vector2gameMath.distance(Vector2(0,0),Vector2(1,1))# 1.4142135623730951