object oriented analysis & design game patterns 3

33
Object Oriented Analysis & Design Game Patterns 3

Upload: francis-parrish

Post on 29-Dec-2015

239 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Object Oriented Analysis & Design Game Patterns 3

Object Oriented Analysis & Design

Game Patterns 3

Page 2: Object Oriented Analysis & Design Game Patterns 3

2

Contents Iterator Handle Model Database Appearance Map Magnetism Shield Visual state Automatic mode cancellation Focus Progress

Page 3: Object Oriented Analysis & Design Game Patterns 3

3

Iterator Description

Allows access to members of a container in an organized fashion without requiring any knowledge of the structure of the container.

Motivation Programmers want to store objects in containers and

be able to access each of them once If the programmer has to understand how the

container is implemented This takes extra effort The programmer will structure his program using this

knowledge The developer of the container will not be able to change

his implementation

Page 4: Object Oriented Analysis & Design Game Patterns 3

4

Iterator Solution

Provide an iterator which Returns every member of the container once Allows you to determine when you are at the end Visits the members in a pre-defined order Provides a way to move on to the next member of the

container

The Standard Template Library has a nice implementation Container::iterator is a type used to declare an

iterator Container::begin() returns an iterator to the first

member Container::end() returns a past-the-end iterator

Page 5: Object Oriented Analysis & Design Game Patterns 3

5

Iterator STL Iterators

operator++() – moves to next member operator*() – retrieves value of current member operator==() – compares iterators operator!=() – compares iterators

UsageContainer::iterator iter;Container c;while(iter=c.begin(); iter != c.end(); iter++) {

GameObject o = *iter;}

Page 6: Object Oriented Analysis & Design Game Patterns 3

6

Iterator

Page 7: Object Oriented Analysis & Design Game Patterns 3

7

Handle Description

Provide access to another object without revealing how the identity of the other object is represented.

Motivation We have a container and want to allow the user

access to the members of the container via a reference

However, the container might reorganize its storage or change its implementation

Therefore we need the user to have a reference to an object without knowing how the reference is implemented

Page 8: Object Oriented Analysis & Design Game Patterns 3

8

Handle Solution

Declare the class in the Handle header, obscuring the implementationclass HandleImplementation;class Handle {private:

HandleImplementation *impl;public:

Handle();operator=();operator==();

};

The details of HandleImplementation are in the .cpp file

Page 9: Object Oriented Analysis & Design Game Patterns 3

9

Model Database Description

Provides centralized storage for all models in the game so that there is one place where models can be found.

Motivation Models are needed by various parts of the game

The level loader loads them The logic attaches them to the scene graph and

detaches them The renderer draws them on the screen

It can become confusing To know where a model is located Whether a model has already been loaded or not To ensure all parts of the game can access the models

Page 10: Object Oriented Analysis & Design Game Patterns 3

10

Model Database Solution

Maintain a central repository of all models Ensure that each model is in the database only

once Allow models to be retrieved in several ways

Via an iterator Via an opaque handle By name

Being able to reference models by name is handy when the models are stored in files and loaded by a level loader rather than the code which will use them

Page 11: Object Oriented Analysis & Design Game Patterns 3

11

Model Database

Page 12: Object Oriented Analysis & Design Game Patterns 3

12

Appearance Map Description

Isolates the state of an object from the visual appearance of an object

Motivation An object in a game can change its appearance

when It is in motion There is some change to the object state which must be

shown visually Having the logic for this in the controller can make

the control logic overly complex

Page 13: Object Oriented Analysis & Design Game Patterns 3

13

Appearance Map Solution

It is better to create a table which lists the appearance based on Object state The time

The state and time information can be passed to the map and the map will return the image which is needed at a particular time in a particular state

Page 14: Object Oriented Analysis & Design Game Patterns 3

14

Appearance Map

Page 15: Object Oriented Analysis & Design Game Patterns 3

15

Mini Kernel Description

The control logic for each game object is moved into the object to reduce the complexity of the control logic in the game loop.

Motivation As the number of objects in a game increase, the game loop

looks like:void update() {

for(int i = 0; i < numTanks; i++) {updateTankPhysics(tank[i]);updateTankAI(tank[i]);

} for(int i = 0; i < numSoldiers i++) {

...}

This gets very complicated

Page 16: Object Oriented Analysis & Design Game Patterns 3

16

Mini Kernel Solution

Move the control logic for each object into the object itself

Have the central controller Maintain a list of active game object Ask each object to update itself when needed

This has the advantages Main controller is simpler Objects can add themselves to controller or remove

themselves at any time Adding a new object type does not require a change to

main controller Logic in main controller is simpler

Page 17: Object Oriented Analysis & Design Game Patterns 3

17

Mini Kernel

Page 18: Object Oriented Analysis & Design Game Patterns 3

18

Mini Kernel

Page 19: Object Oriented Analysis & Design Game Patterns 3

19

Usability Patterns The concept of patterns has been extended

beyond pure programming Patterns are now used to describe solutions to

User interface design Game mechanics

One area is the usability patterns that try to make games more usable for the player

Page 20: Object Oriented Analysis & Design Game Patterns 3

20

Magnetism Description

Provide magnetism on hit detection so that when the user selects near a target, the selection point will be drawn towards the target as if by magnetism. This will make it much easier to hit a target.

Motivation Games often implement highly accurate hit

detection on small targets with the result that players find it difficult to hit a target. This becomes very frustrating to the player and reduces the fun in playing the game.

Page 21: Object Oriented Analysis & Design Game Patterns 3

21

Magnetism Solution

The solution is to make the hit detection less accurate.

The simplest way to do this is to expand the bounding area for the object to make it easier to hit.

The result is that the game will be much easier and more fun to play.

This can also speed up the game since a simpler hit detection algorithm can be used.

Page 22: Object Oriented Analysis & Design Game Patterns 3

22

Magnetism

Accurate bounding boxwith sub boxes. This makes the target hardto hit.

Accurate bounding boxis a little easier to hit. Larger bounding circle

is easiest to hit.

Page 23: Object Oriented Analysis & Design Game Patterns 3

23

Shield Description

Game controls which can cause undesirable consequences, such as terminating the game, are protected from accidental use.

Motivation Many times, there are controls or gestures which

cause operations to take place Sometimes, these can be accidentally triggered

when not intended For example, clicking the mouse to fire the

weapon can be dangerous when using a trackpad There needs to be a way to prevent accidental

triggering of operations

Page 24: Object Oriented Analysis & Design Game Patterns 3

24

Shield Solution

The solution can take several forms When the user is in a mode where a control is not

needed, it can be disabled and greyed out Some operations, like terminating the game, can require

the user to confirm his or her actions before they actually take place

Other operations could only be activated by double clicking the mouse or a key instead of using a single click.

Page 25: Object Oriented Analysis & Design Game Patterns 3

25

Visual State Description

Allows information about the state of the game to be conveyed to the user via visual clues so that the user does not have to remember the state of the game.

Motivation Characters can have power-ups, be carrying

weapons, be under the influence of a spell or be in good or poor health

The player has to be aware of this state information and be able to see it at a glance

If the information is not readily visible, the player must remember and track it all, placing a significant load on the player’s memory and detracting from the game

Page 26: Object Oriented Analysis & Design Game Patterns 3

26

Visual State Solution

The solution is to make the information readily visible on the screen

There are numerous way to do this The image of the player can be altered to show state Part of the screen can be used to display state

information Billboards in urban settings could be used to indicate

state information Buttons can be used to temporarily show state

information The interface can be configurable to show and hide

various state information depending on what the player needs to see

Head up displays can show a wealth of information and can be ignored when the information is not immediately needed

Page 27: Object Oriented Analysis & Design Game Patterns 3

27

Visual State

Head-up displays are very useful for some types of games, like flight simulators

Page 28: Object Oriented Analysis & Design Game Patterns 3

28

Automatic Mode Cancellation Description

Mode based games should allow the mode to be cancelled and the user automatically switched to another mode when commands which are inappropriate to a mode are used.

Motivation In a real-time strategy game, the player can move a

character by Clicking on the character to select it Selecting the move operation Clicking on the destination location for the character

If the player decides he or she does not want to do the move, they should be able to click on another command and automatically cancel the move.

Page 29: Object Oriented Analysis & Design Game Patterns 3

29

Automatic Mode Cancellation Solution

The solution is to design the controls such that When the user is in a mode The control class watches for commands outside the

controls for that mode Ejects the user from the mode when one of the other

commands is given Passes the command onto a more general-purpose

control class

Page 30: Object Oriented Analysis & Design Game Patterns 3

30

Focus Description

The amount of information presented to the player is reduced to just what is relevant so the user can focus on the task at hand.

Motivation The player is presented with a large number of

options, many of which are not relevant to the task the user is performing

The user is distracted by information from other parts of the game

The user is overwhelmed by the sheer amount of information and spends valuable time determining what is relevant

Page 31: Object Oriented Analysis & Design Game Patterns 3

31

Focus Solution

The solution is to reduce the amount of information and choices presented to the player Buttons which cannot be used can be grayed out The character in a sports game that is being

manipulated can stay in sharp focus and the other characters can be blurred

State information that is temporarily irrelevant can be hidden until it is needed again

The player can zoom into one area of the game world so the larger world can be ignored

Page 32: Object Oriented Analysis & Design Game Patterns 3

32

Progress Description

To visually depict the progress of an operation so that the player can readily see the state

Motivation When the game is initializing or loading a new

level the player is often left for a long period not knowing what is happening

Values like the strength of the character are not immediately visible

The progress in attaining a goal can be difficult to discern

Page 33: Object Oriented Analysis & Design Game Patterns 3

33

Progress Solution

Display a progress bar Change the image or shape of a character to show

health Use an hour glass Show bottles with various fractions full Use a numeric counter Display various number of things, like weapons