By: J. Brandon George | [email protected] | twitter: @PyFryDay | medium.com: https://darth-data410.medium.com/ | youtube: https://www.youtube.com/@pyfryday source-code license found @: PyGames-Mars/LICENSE (Apache License Version 2.0 Janurary 2004) Art|Graphics Assest - license|usage found in 'External Attributions' as-well-as 'Graphics - License and Use'.
This open source project contains elements, source code, graphics, sounds, etc. that support my Medium.com series of post about python3 and pygame. Please refer to each sections 'Medium.com Links' named list.
You have landed a rover on Mars, named ROVI, and you are to survey the area in which ROVI can move in. In surverying the objective is to find all the minerals that exist, and record their cordinates for later phases that will mine said minerals. Contact with alien (or from their point of view, native) lifeforms may take place.
Each of the following sections, list specific, self-contained instances of the game. Each has a certain level of development advancemenet, and the next instance builds from the base of the previous. Each section below also has links to the corresponding medium.com post that make sure and reference code, elements, objects, walkthroughs, guides, etc.
-
Instance Overview
This instance focuses on getting started with creating the initial 'Mars' game. Introduction to concepts like the game loop, the main Game objects, Sprites (Player and Non), obstacles, basic movement, basic game interaction - including highlights and usage of pyguix.ui.elements.MessageBox and pyguix.ui.elements.SnapHUD heads up display elements. (Link to pyguix project on GitHub)
A detailed walk through for using ui.MessageBox and ui.SnapHUD instances can be found in the Medium.com Links section below, for this game instance. This includes an introduction to hte pyguix python3|pygame library and its corresponding GitHub project repo source.
-
Medium.com Links:
-
Instance Overview:
This instance is a clone of 01_Intro, with a focus on the pyguix.ui.elements.PopupMenu usage. Specifically how the 'player.Player'|(module.class) is targeted for contextof, via setup of '02_PopupMenu/pyguix/ui/context/Rover_menu.json'. In the 'Rover_menu.json' file player.Player is listed as the only 'targetclass(es)'. (Note: You can have multiple sprite classes targeted with the contextof the same right-click, PopupMenu.)
Further within the Rover_menu.json you find the actionclass = _ _ main _ _.RoverMenu|(module.class), which houses the menuitem.(menu item instance).popupmenuitem.action, which is a bound function on the actionclass, RoverMenu. The parts listed then, expect to be able to call the RoverMenu. action bound function, via reflection concepts of python3, and have the logic contained within that Actionclass.action|(class.bound function) execute, with the ability to reference the calling, 'active', pyguix.ui.elements.PopupMenuItem instance. This PopupMenuItem instance contains a .contextof variable which represents that sprite class instance that the right click action of the mouse took place on.
All related python3 code examples for the PopupMenu for the 02_PopupMenu game instance, can be found in 02_PopupMenu/main.py python file. The following is a list for quick reference: (note: developed in vscode, therefore code line numbers referenced are generated by vscode ide.)
- class RoverMenu(ui.PopupMenuActions) - Lines 20-41
- RoverMenu(...) (instance creation) - Line 61
- self.pu (Game.pu - game instance variable for PopupMenu) - Line 62
- if event.button == pygame.BUTTON_RIGHT: (Operate upon Right-Click mouse) - Line 108
- ui.PopupMenu.clearall(self.pu) - Line 109
- self.pu = ui.PopupMenu(...) - Lines 111-115
- elif event.button == pygame.BUTTON_LEFT: (Operate upon Left-Click mouse) - Line 117
- if isinstance(self.pu,ui.PopupMenu): self.pu.clicked(event_list) - Line 122
- if isinstance(self.pu,ui.PopupMenu): self.pu.update() - Line 129
-
Medium.com Links:
-
Instance Overview:
This instance is a clone of '02_PopupMenu', 'PyGames-Mars' game instance. It carries with it then all examples in place for MessageBoxes, SnapHUD and PopupMenu pyguix.ui.elements.
The major focus of this game instance is around setting up basic animation based on the player.Player movement. In doing so we are getting ready for enabling future instances to allow more user interface examples, game options, and other game concepts. Further adding enemy sprites to interact with during game play as well, the 'aliens' (Though technically the rover is an alien object on Mars and the 'aliens' are actually natives... but hey...)
In order to enable animations, movement of sprites, etc. this instance introduces the concept of sprite sheets, as well as a relating sprite sheet map file, in the format of JSON. This sprite sheet map tells a call found in the spritesheet.py python file, called SpriteSheet, what sprite sheet .png file to load, and how to break up that said sprite sheet, so that the different sprites can be subsurface()ed from the single loaded sprite sheet .png file.
This is for performance reasons, but also for management of graphic assests, so that you are managing just a single sprite sheet, vs. multiple files for the different frames in which a sprite animation is made up of. This is one approach for working with sprites and sprites sheets that, if used, allows for you to easily drop and plug in new sprites for game play / game design.
-
Medium.com Links:
The group behind the pygame library itself (pygame.org) can not be thanked enough for the continued effort in keeping the pygame library fresh, useful and relevant. Further the coding style, naming of classes and python (.py) files adhere (loosely) to standards set forth in examples provided by pygame.org site. Specifically in the Zelda Python example was used to he help jump start this work. Finally the graphics found in this game, are in part, jump started from Pixel-boy. (https://pixel-boy.itch.io/ninja-adventure-asset-pack). Specifically the background, rock and boulder objects.
Both the mentioned Zelda Python and Pixel-boy|ninja-adventure-asset-pack are released under the Creative Commons Zero (CC0) license. (Attributions paid forward, thanks!)
ROVI, the Mars rover and all aliens (or from their viewpoint natives), and all other images, art, graphic assests are 100% creations of mine, except for external attributions stated. All such assests can be used as packaged with this open source project for learning purposes. However NO RIGHTS are granted for use of any such images, art or graphic assests for sale, in a production system, or used in a way to generate ANY form of revenue within ANY format or in-part of ANY product, project, source that would be packaged and used for generating revenue OR profit.
Have fun with the project, be kind and give credit to sources when used, hopefully this helps YOU in your journey to learn more about python3 and pygame development.