Having now demonstrated your understanding to the use of UML we will now be applying this knowledge to our ideas of games and game design.
found on http://superprofundo.com/, written by Mathew Preziotte.
What is Object Oriented Programming?
OOP is a programming paradigm. Not all languages support OOP, but most major languages do at this point. It exploits the idea that sometimes a computer programmer might want to code a “thing.” Let’s call that thing an object. That object might need to exist more than once, so why bother explaining it more than once? An “object” in this context, is a collection of data, functions, and logic that ties a single idea together. When an object is created, the blueprints for making that object is consulted, and some initial configurations might need to be set. These blueprints are called a class, and creating an object from this class is considered an instance of the object. Each class has a constructor, the function that runs by default when an object is created.
But when is this useful?
Example Videogames lend themselves nicely to a quick example. Super Mario World is full of objects! Let’s take that item block for example:
There are hundreds of shiny question mark blocks floating around Mario levels. It would be pretty wasteful and redundant not to use OOP here. In order to do so, we must ask ourselves what kind of data each block must hold. It needs a position (x-coordinate, y-coordinate), it needs to store the contents of the box itself (a mushroom, a coin?) , and it must have a state (has it been opened yet?). The item box also has several images associated with it, an animation, and a sound effect.
Now, how can this box be interacted with? It can be hit from underneath in order to open it. This would call a single function that will play the appropriate sound, trigger the appropriate animation, change the state of the box, reveal the contents of the box, and change the contents of the box to nothing. While the actual syntax for creating a class will vary from one language to another, the same general concepts will always apply.
See the Pen BjBKZV by james farrington (@jamesfarrington) on CodePen.
This basically encapsulates everything that would need to be in the blueprints for an item block. Now that we have our blueprints, how would we go about creating a new block? We must simply ask ourselves, what needs to be specified in order to create one? Each box needs a position in the level, and an item inside of it (most likely a coin). This tells us the parameters that need to be passed while declaring a new object. The following could be a declaration of a new item block containing a fire flower (which could itself, be thought of as an item object):
new ItemBlock("900px", "37px", "Fire Flower");
Well there you have it. We have successfully abstracted the concept of an item box. Maybe this will change the way you see videogames forever.
Some Vocab
A class can be thought of as the blueprints for an object. It contains all the data structures, logic, and functions associated with creating that object.
An object is an instance of the thing you can make with the blueprint. You can make multiple objects from the same blueprints, obviously.
Methods are simply the functions that a class has. They are sometimes also called subroutines. The concept of inheritance should be taken quite literally. It is the idea that one class can extend the definition of another. A trout might inherit a more generic “fish” class, which it can use to build from.
Programmers will often try to isolate specific ideas and functions from one another, in a concept known as abstraction. This is thought of as an ideal in computer science, which makes code more accessible for others to manipulate.
Polymorphism is a feature built in to programming languages that allows one type of variable to appear as, and be treated like, another type.
A constructor is the function in a class that runs by default when an object is created.
Discussion:
Is Object Oriented Desgin (OOD) really worth it? is it better to just get on with it and develop the game/project/product?
How do these drawings help?
The Use of Object Orriented programming can be found in Adobe Flash
Using the game above list the objects that could be considered in the level, identify how many times that instance appears in the game.
This is a task that may work well in small groups, organise your selves in to teams and select the objects that you will be counting to support the task.
Using the link below impliment some of the code snippets in to Flash
Adobe Flash OOD and OOD
Using the link below use Alice and create an anmiation
Alice OOD and OOP
To further explore the implimentation of OOD in practice we are able to use programming languages like Java to create objects, of which can have many instances and polymophs of them, whilst having libruarys of pre-defined methods and behaviours that can be accessed when required without the need to create them.
To see this and to play with a form of programming language use the button below
Game Development
Links to Learning Outcomes |
Links to Assessment criteria |
|
---|---|---|
Anonymous Assessment - Learners assess an anonymous piece of work containing deliberate mistakes against given success criteria.