In every PyGame program there needs to be a main loop that renders the graphics used in the program and that also controls input for the game via keyboard and/or mouse depending on the PyGame application being developed.
If you want to jump to a specific function in the code, instead of scrolling through lines and lines of code, just use the IDE’s search function (if it has one). It’s usually invoked by pressing (Ctrl+F). Type in your search term and then click the Search Next button.
Object orientated programming (OOP) is a paradigm based on the concept of classes, objects and associations that can contain both data and code, which determines how the objects behaves in the software system being created. Before an object is created, a template is first created to then instantiate an object. A template of an object is called a Class which, by using a concept called inheritance, can inherit other data and operations so that they don’t have to be re-written each time.
OUR EXPERT
Let’s take a look at the main loop implemented in this Dwarf Project.
Object Orientated Programming has been implemented in the Dwarf Game Project to implement the game characters for the game. There is a base class called Player that includes much of the properties and operations which are applicable for both the human player and computer-based players. Notice that in the base class there’s a method called processWalk_Anim() , which is used to process the walk animation of dwarf, whether it be the player’s dwarf or an enemy dwarf. After the base class Player, there are two derived classes called DwarfPlayer and DwarfAIPlayer, which both inherit the functionality and properties of the Player class. Both of the derived classes DwarfPlayer (used for the human player) and DwarfAIPlayer used for the computer player continue to define properties and operations unique to their application in the Dwarf Game Project
Andrew Smith is a software developer at NHS Digital, has a degree in software engineering and an MSc in computer networks (mobile and distributed).
while not programEnd: