There are 4 main concepts for object orientated design; these are Encapsulation, Inheritance, Polymorphism and Abstraction.
Encapsulation is like what is sounds like; it’s keeping it all within a “capsule”. The capsule is in the form of a class, this keeps all of your code neat and tidy and you can find all of it in one place. For
example in the “Sniper” class it will contain all of the data about the sniper, but none about the “Ak-47”. This image shows all of the weapon variables in one part, his keeps its all neat, tidy and easy to edit or find the variables of the weapon.
Inheritance is basically just sub classes taking things from the main class. The main class has all of the properties and behaviours that you’ve chosen for it, and then there are sub classes that can “inherit” all of the properties and behaviours from the main class. For example let’s say a there is a “Parent” class which contains height, age, weights etc.. then the sub class called “Child” can inherit some of these properties. like in the images, the first class made was “Fruit” this was just a general name for all the different types of fruit, then the child class is “Apple” and it is part of the fruit parent class. There can then be more child classes like “Orange” or “banana”. After this there could be even more classes like “Apple Slice” or “Apple Stick” furthering the inheritance.
Polymorphism comes into the script after inheritance is used. Basically a class for “Car” might have a certain set of properties like a certain top speed; however the “Super Car” sub class might want a higher top speed so you can change the properties and behaviours because of polymorphism. The images below show the polymorphism, the “fruit” is the parent and the “apple” is the child class. The words changed from the “fruit” to the “apple” has been chopped, this is polymorphism because it has inherited it but changed to suit itself more.
Abstraction is basically just keeping everything in the class relevant. You don’t want irrelevant things in the subclass which will just slow it down, so for example you don’t put things like age or weight in the height sub class. for example like this image shows all of the
The objects in OOD are what is how you do things within the game world, however you cannot see them at first. This is where sprites come into it, by adding a texture or sprite to the object they become visible, making things visible means you can interact with them and play as them. The image shows sprites of video games, it shows them from different angles and this is how they will appear in game.
Almost every game has characters in them, whether they’re played by the user or controlled by AI. The characters are the things in the games like the people, animals or monsters. The user normally plays as a human which they control and this is how they interact with the game world. Most games have enemies, or some form of opposition which you have to defeat, these will most likely be AI. The AI is specially programmed to defeat you and stop you beating the game. Characters are the people you play as like the image of Pac man.
In games there is a variety of different weapons depending on the genre, ranging from melee weapons like swords and knives to things like guns which can be used from range. These weapons will be used to defeat enemies and the opposition in fighting games. An example of a weapon is just a sword or a gun.
Properties are the details of the of an object or its characteristics. They control what its made up of and how it acts. For example if the object is a car then its properties will be its speed, age, weight etc. The image below shows the properties of the “m4” weapon, it shows the different characteristics of it like the fire rate of 3 and how many bullets it can hold.
Events are something that happens which triggers something else. The controls for games are basically lots of events that just need to be triggered by the player. For example if the space button is pressed then it might trigger the “Jump” action in a game. It’s not just the keyboard which triggers the events it’s also things like your mouse, the mouse can have a different event for each button. For example if you move the mouse wheel down then it scrolls out, or if you click then it selects an item in game. These events give the player full control of a character in game. As you can see from the image that on mouse click an event will happen, when the button is clicked the screen width changes.
An object or class might inherit something from another object or class, this means that it will have some of the traits. For example in animals if a sheep is a certain height, weight, colour etc then the lamb should inherit some of those factors