game design lecture 3

32
1 CMSCD1012 – Lecture 3 CMSCD1012 – Lecture 3 Game Design and Game Design and Tokenisation Tokenisation Abdennour El Rhalibi Abdennour El Rhalibi

Upload: pardipali

Post on 22-Oct-2014

40 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Game Design Lecture 3

1

CMSCD1012 – Lecture 3CMSCD1012 – Lecture 3Game Design and TokenisationGame Design and Tokenisation

Abdennour El RhalibiAbdennour El Rhalibi

Page 2: Game Design Lecture 3

22

Game DesignGame Design

Now we Now we start taking a game design and converting it start taking a game design and converting it into something workable that a developer can into something workable that a developer can understandunderstand, and that will be easy to expand, debug, , and that will be easy to expand, debug, and maintain.and maintain.

A good design can A good design can turn technical "issues" into turn technical "issues" into complete non-issuescomplete non-issues, and produce a good , and produce a good architecture. architecture.

The object of a good architecture design The object of a good architecture design (accompanied with the good dissemination of (accompanied with the good dissemination of information) is to make it obvious how to do information) is to make it obvious how to do something.something.

How can we do this? Well, for a start, we can exploit How can we do this? Well, for a start, we can exploit certain factors that are common to the architecture certain factors that are common to the architecture of virtually all games. of virtually all games.

Page 3: Game Design Lecture 3

33

*What Is A Game? – Revisited (I)*What Is A Game? – Revisited (I)

Let's take a random walk through a list of games and Let's take a random walk through a list of games and see if we can spot any commonality:see if we can spot any commonality:

Pong, Frogger, Pac-Man, Elite, The Sentinel, Missile Pong, Frogger, Pac-Man, Elite, The Sentinel, Missile Command, Tetris, The Legend of Zelda, Virtual Fighter, Command, Tetris, The Legend of Zelda, Virtual Fighter, Carmageddon, Defender, Chess, Warcraft, Zork, Doom, Carmageddon, Defender, Chess, Warcraft, Zork, Doom, FreeCell, Scrabble, Tennis, Tom Raider,…FreeCell, Scrabble, Tennis, Tom Raider,…

What do all these games have in What do all these games have in commoncommon? The first ? The first thing is that they thing is that they all have a playerall have a player. .

All games also All games also have discrete elementshave discrete elements that are directly that are directly or indirectly manipulated by the player. For the time or indirectly manipulated by the player. For the time being, we shall call these being, we shall call these tokenstokens. .

These tokens are the elements of the game that are These tokens are the elements of the game that are supervised and managed by the computer. For supervised and managed by the computer. For example, let us consider example, let us consider PongPong. What are the tokens in . What are the tokens in this game?this game?

Page 4: Game Design Lecture 3

44

What Is A Game? – Revisited (II)What Is A Game? – Revisited (II)

PongPong

What are the tokens in this game?What are the tokens in this game?

Page 5: Game Design Lecture 3

55

What Is A Game? – Revisited (III)What Is A Game? – Revisited (III)

Pong has two playersPong has two players (represented by bats and a (represented by bats and a score), a ball, and some walls. Which of these are score), a ball, and some walls. Which of these are tokens? Conceptually, they all are. Each player tokens? Conceptually, they all are. Each player controls a bat, and the players' prowess with this controls a bat, and the players' prowess with this bat will improve their score. bat will improve their score.

Therefore, it could be said that the Therefore, it could be said that the players' batplayers' bat and and score score are are subtokens subtokens of the token representing the of the token representing the player. The player. The ballball is another token, as it is indirectly is another token, as it is indirectly influenced by the players and, aside from small influenced by the players and, aside from small interactions, is essentially managed by the interactions, is essentially managed by the computer. computer.

The The wallswalls of the play area themselves are tokens. of the play area themselves are tokens. They interact with both the They interact with both the batsbats and the and the ballball, in , in order to prevent them escaping from the top and order to prevent them escaping from the top and bottom of the screen.bottom of the screen.

Page 6: Game Design Lecture 3

66

*What Is A Game? – Revisited (IV)*What Is A Game? – Revisited (IV)

What about the What about the goal areasgoal areas? These are the areas ? These are the areas that the ball travels to when the player has failed that the ball travels to when the player has failed to deflect the ball in time. to deflect the ball in time.

When the ball reaches here, a When the ball reaches here, a point is awarded to point is awarded to the opposing playerthe opposing player, and the game begins again. , and the game begins again. These are tokens too - although they are defined These are tokens too - although they are defined by area and have no visible representation.by area and have no visible representation.

All the games mentioned above (in fact, All the games mentioned above (in fact, empirically speaking, all games) can be described empirically speaking, all games) can be described in terms of in terms of players and tokensplayers and tokens. .

Page 7: Game Design Lecture 3

77

Thinking In Tokens (I)Thinking In Tokens (I)

The Pong token hierarchyThe Pong token hierarchy

We can consider these tokens to be We can consider these tokens to be arranged in a form of arranged in a form of hierarchical structurehierarchical structure. .

The playing area, or game world, in itself The playing area, or game world, in itself is at the top of the hierarchy. is at the top of the hierarchy.

It is an essentially flat hierarchy. It is an essentially flat hierarchy.

The game world token contains all the The game world token contains all the other tokens. other tokens.

Obviously, Obviously, every token has to operate every token has to operate within the game world in order to form a within the game world in order to form a part of the gamepart of the game. .

The player avatar token is the The player avatar token is the representation of the representation of the playerplayer within the within the game world. It is effectively a channel for game world. It is effectively a channel for the user interface between the player and the user interface between the player and the game. the game.

The player avatar for Pong is very simple; The player avatar for Pong is very simple; it is merely a it is merely a batbat and and a scorea score. These are . These are how the player is represented in Pong. how the player is represented in Pong.

The other tokens - those manipulated by The other tokens - those manipulated by the computer -are the the computer -are the ballball, the , the wallswalls, and , and the the goal zonesgoal zones..

Page 8: Game Design Lecture 3

88

Tokenization Of Pong (I)Tokenization Of Pong (I)

Not all games will be so trivial, and, for some more Not all games will be so trivial, and, for some more complex games, there may be many ways, all of complex games, there may be many ways, all of which are equally valid.which are equally valid.

So now we have a set of tokens. On their own, they So now we have a set of tokens. On their own, they are not very exciting, as they do not interact with are not very exciting, as they do not interact with one another. But, as we know, in Pong there are all one another. But, as we know, in Pong there are all sorts of interactions going on. Well, one anyway: sorts of interactions going on. Well, one anyway: collisionscollisions..

We can now define an We can now define an eventevent - - the collision eventthe collision event. . Let's say that a collision event is generated Let's say that a collision event is generated when when two tokens collidetwo tokens collide. The net result of this event is . The net result of this event is that each token receives a message telling it that a that each token receives a message telling it that a collision has occurred, and the type of object it has collision has occurred, and the type of object it has collided with.collided with.

Page 9: Game Design Lecture 3

99

Tokenization Of Pong (II)Tokenization Of Pong (II)

The Pong token interaction matrixThe Pong token interaction matrix

The The token interaction matrixtoken interaction matrix is a very is a very important constructimportant construct. . It is a chart of all the It is a chart of all the interactions that take place interactions that take place in the game.in the game.

Note that, for very large Note that, for very large games (or basically anything games (or basically anything that's slightly more that's slightly more complicated than Pong), complicated than Pong), these matrices can become these matrices can become more complex (even three-more complex (even three-dimensional), and there can dimensional), and there can be more than one of them. be more than one of them.

The way to prevent this is to The way to prevent this is to produce several levels of produce several levels of token category matrixtoken category matrix, , where similarly behaving where similarly behaving tokens are lumped into a tokens are lumped into a category. This reduces the category. This reduces the number of effectively number of effectively duplicate entries.duplicate entries.

Page 10: Game Design Lecture 3

1010

Tokenization Of Pong (III)Tokenization Of Pong (III)Okay, so let's look at the Pong token Okay, so let's look at the Pong token interaction matrix. The matrix is interaction matrix. The matrix is arranged in a arranged in a triangulartriangular format, with format, with each token listed along the side and each token listed along the side and the bottom. the bottom.

An unusual feature of Pong is that An unusual feature of Pong is that tokens do not come into contact with tokens do not come into contact with other tokens of the same type. other tokens of the same type.

This immediately means that the This immediately means that the token, token interactions for token, token interactions for bat-batbat-bat, , ball-ballball-ball, , wall-wallwall-wall, , goal-goalgoal-goal, and , and score-scorescore-score can be discounted. can be discounted.

Due to the nature of the game, the Due to the nature of the game, the following interactions can also be following interactions can also be discounted: discounted: bat-goalbat-goal, , wall-goalwall-goal, , score-batscore-bat, , score-ballscore-ball, and , and score-wallscore-wall..

The Pong token interaction matrixThe Pong token interaction matrix

Page 11: Game Design Lecture 3

1111

Tokenization Of Pong (IV)Tokenization Of Pong (IV)There are two main types of interaction in the matrix: There are two main types of interaction in the matrix: symmetricsymmetric and and asymmetricasymmetric. . Symmetric interactions are the same both ways. Symmetric interactions are the same both ways.

For example, the behavior of the ball and the bat are not For example, the behavior of the ball and the bat are not different depending on how we consider the collision. That is, if different depending on how we consider the collision. That is, if we say that the we say that the ball collides with the batball collides with the bat, we would expect , we would expect exactly the same results to occur as if we had said the exactly the same results to occur as if we had said the bat bat collides with the ballcollides with the ball. The semantics do not matter. Symmetric . The semantics do not matter. Symmetric interactions are shown as interactions are shown as squares in the matrixsquares in the matrix..

Asymmetric interactions are shown in the matrix as a Asymmetric interactions are shown in the matrix as a square square split into two trianglessplit into two triangles. An asymmetric . An asymmetric interaction is different interaction is different depending on the directiondepending on the direction. .

In this case, the semantics do matter. In this case, the semantics do matter. Each triangle Each triangle represents one direction of the interactionrepresents one direction of the interaction. . Taking the solitary case from the Pong matrix as an Taking the solitary case from the Pong matrix as an example, we could say that a example, we could say that a goal causes the score to goal causes the score to increment by oneincrement by one, but the , but the score incrementing by one score incrementing by one does not cause a goal to occurdoes not cause a goal to occur. .

Page 12: Game Design Lecture 3

1212

*Tokenization Of Pong (V)*Tokenization Of Pong (V)

So what can we use this matrix for? The So what can we use this matrix for? The matrix allows matrix allows us to perform a visual check on our interactionsus to perform a visual check on our interactions. .

We can check that they are what we would expect, We can check that they are what we would expect, and we can see if we have and we can see if we have missed any or made any missed any or made any errorserrors..

We may be able to We may be able to spot unexpected chain reactionsspot unexpected chain reactions (the sort of things that in some cases will enhance a (the sort of things that in some cases will enhance a game, but in other cases will render it virtually game, but in other cases will render it virtually unplayable). unplayable).

These things will be picked up in playtesting, but the These things will be picked up in playtesting, but the sooner it is spotted, the cheaper it is to fix.sooner it is spotted, the cheaper it is to fix.

Page 13: Game Design Lecture 3

1313

Tokenization Of Pong (VI)Tokenization Of Pong (VI)

Propagation of events when a Propagation of events when a goal is scoredgoal is scored

One token that is not included One token that is not included in the Matrix is the in the Matrix is the game world game world itselfitself. This can be considered a . This can be considered a token and, for games more token and, for games more complex than Pong, probably complex than Pong, probably would be included in the matrix. would be included in the matrix.

This is because the game world This is because the game world token needs to be informed of token needs to be informed of certain events, so that it can act certain events, so that it can act as an intermediary between as an intermediary between different tokens and also different tokens and also respond to certain events itself respond to certain events itself (such as the goal event in order (such as the goal event in order to reset the game). to reset the game).

This shows how the game world This shows how the game world token would respond to the goal token would respond to the goal event.event.

Page 14: Game Design Lecture 3

1414

Tokenization Of Pac-Man (I)Tokenization Of Pac-Man (I)

Pac-ManPac-Man

For most of the rest of this presentation, we will run For most of the rest of this presentation, we will run through the same process for another well-known game, through the same process for another well-known game, Pac-Man.Pac-Man.

Here is a brief description of the game: You play a Here is a brief description of the game: You play a greedy, little, round, yellow, blob-thing called Pac-Man greedy, little, round, yellow, blob-thing called Pac-Man and have to travel around a maze, eating all the pellets. and have to travel around a maze, eating all the pellets.

The maze has warp tunnels on the left and the right so The maze has warp tunnels on the left and the right so that you can leave the screen on the left to reappear on that you can leave the screen on the left to reappear on the right, and vice-versa. You are being chased by four the right, and vice-versa. You are being chased by four ghosts. ghosts.

Each ghost is differently colored and each has his own Each ghost is differently colored and each has his own individual personality. If they catch the Pac-Man, he individual personality. If they catch the Pac-Man, he deflates and dies. if, however, the Pac-Man manages to deflates and dies. if, however, the Pac-Man manages to eat one of the four "power pills" in each maze, then the eat one of the four "power pills" in each maze, then the ghosts turn blue, and, for a short time, he can eat them. ghosts turn blue, and, for a short time, he can eat them.

Every so often, a bonus fruit will appear that can be Every so often, a bonus fruit will appear that can be eaten for varying amounts of points. Once the maze is eaten for varying amounts of points. Once the maze is cleared of pellets, the level is over, and another level cleared of pellets, the level is over, and another level starts, (identical to the last, except for being slightly starts, (identical to the last, except for being slightly faster and having a different fruit). Every five or so faster and having a different fruit). Every five or so levels, an amusing cut scene takes place as a reward for levels, an amusing cut scene takes place as a reward for the player.the player.

Page 15: Game Design Lecture 3

1515

Tokenization Of Pac-Man (II)Tokenization Of Pac-Man (II)

First attempt at a token First attempt at a token interaction matrix for interaction matrix for

Pac-ManPac-Man

The attempt at a token The attempt at a token interaction matrix for Pac-Man interaction matrix for Pac-Man is significantly more complex is significantly more complex than that for Pong.than that for Pong.

This is because the tokens may This is because the tokens may exist in one or more states, exist in one or more states, and the interactions between and the interactions between tokens depend on the state of tokens depend on the state of the token.the token.

For example, the ghosts can be For example, the ghosts can be in one of three states (hunter, in one of three states (hunter, hunted, or eaten).hunted, or eaten).

Page 16: Game Design Lecture 3

1616

Tokenization Of Pac-Man (III)Tokenization Of Pac-Man (III)

Some events are not directly included on the Some events are not directly included on the matrix itselfmatrix itself

The most important event that is not included is The most important event that is not included is the the resurrect eventresurrect event, which is experienced by a , which is experienced by a ghost that has been eaten on returning to base. ghost that has been eaten on returning to base.

To simplify the diagram slightly, I left out the To simplify the diagram slightly, I left out the "eaten" ghost token. I have also left out the ghost "eaten" ghost token. I have also left out the ghost homebase (which we are going to add later, homebase (which we are going to add later, because we will discover that we need to enhance because we will discover that we need to enhance the abilities of the homebase). the abilities of the homebase).

Page 17: Game Design Lecture 3

1717

Tokenization Of Pac-Man (IV)Tokenization Of Pac-Man (IV)

The ghost homebase acts as a resurrection point for The ghost homebase acts as a resurrection point for ghosts once they have been eaten. Once ghosts once they have been eaten. Once resurrected, they stay there for a small while before resurrected, they stay there for a small while before rejoining the chase. rejoining the chase.

The only other item of note is the door to the ghost The only other item of note is the door to the ghost homebase, which allows passage for the ghosts, but homebase, which allows passage for the ghosts, but not for the Pac-Man himself. not for the Pac-Man himself.

These could also be dealt with wing separate These could also be dealt with wing separate diagrams that portray the way events affect the diagrams that portray the way events affect the token. token.

These are known as These are known as finite-state machine diagramsfinite-state machine diagrams. .

A finite-state machine is a system that is commonly A finite-state machine is a system that is commonly used in game Al (and lots of other systems). used in game Al (and lots of other systems).

Page 18: Game Design Lecture 3

1818

Tokenization Of Pac-Man (V)Tokenization Of Pac-Man (V)

Pac-Man example is more sophisticated than the Pac-Man example is more sophisticated than the Pong example, where we were concerned only Pong example, where we were concerned only with events. Events had instantaneous effects and with events. Events had instantaneous effects and did not force any of the tokens into different did not force any of the tokens into different states. Essentially, Pong is a stateless states. Essentially, Pong is a stateless environment. environment.

However, in Pac-Man, the events that affect the However, in Pac-Man, the events that affect the tokens can cause them to shift into different tokens can cause them to shift into different states. We have moved from a purely states. We have moved from a purely event-event-based modelbased model (the E model) to an (the E model) to an event and event and state-based modelstate-based model (the ES model). (the ES model).

Page 19: Game Design Lecture 3

1919

Tokenization Of Pac-Man (VI)Tokenization Of Pac-Man (VI)If we look at the interaction matrix in more detail, we If we look at the interaction matrix in more detail, we can describe in more detail through some of the more can describe in more detail through some of the more complicated interactions. complicated interactions. Most of the events in the matrix are pretty Most of the events in the matrix are pretty straightforward (if you're familiar with Pac-Man), but straightforward (if you're familiar with Pac-Man), but some require a little more explanation. some require a little more explanation. For example, the interaction of the "power pill" with the For example, the interaction of the "power pill" with the ghosts. When the Pac-Man eats a power pill, this ghosts. When the Pac-Man eats a power pill, this generates a power pill event. generates a power pill event. The game world token then disseminates this event to The game world token then disseminates this event to all the ghosts. If a ghost is in the "hunter" state, then it all the ghosts. If a ghost is in the "hunter" state, then it immediately switches into the "hunted" state for a immediately switches into the "hunted" state for a defined period of time. If a ghost is already in the defined period of time. If a ghost is already in the "hunted" state, (i.e., if the Pac-Man has eaten a power "hunted" state, (i.e., if the Pac-Man has eaten a power pill recently), then the ghost reenters the "hunted" pill recently), then the ghost reenters the "hunted" state, and the state timer is reset.state, and the state timer is reset.

Page 20: Game Design Lecture 3

2020

Tokenization Of Pac-Man (VII)Tokenization Of Pac-Man (VII)

The other interactions that require some The other interactions that require some description are those involving the score token. description are those involving the score token.

The power pills, food pellets, and fruits are fairly The power pills, food pellets, and fruits are fairly simple: when these are eaten by the Pac-Man, a simple: when these are eaten by the Pac-Man, a score event is generated and routed to the score score event is generated and routed to the score token. The amount added to the score does not token. The amount added to the score does not vary for the pellets. vary for the pellets.

The ghosts, however, are a different story. The The ghosts, however, are a different story. The score for a ghost depends on how many others score for a ghost depends on how many others have been eaten: 200 for the first ghost, 400 for have been eaten: 200 for the first ghost, 400 for the second, and 800 and 1600 for the third and the second, and 800 and 1600 for the third and fourth. This is reset when the Pac-Man eats fourth. This is reset when the Pac-Man eats another power pill.another power pill.

Page 21: Game Design Lecture 3

2121

Tokenization Of Pac-Man (VIII)Tokenization Of Pac-Man (VIII)It is not easy to handle this situation with the It is not easy to handle this situation with the interaction matrix in its current form. In, stead, we interaction matrix in its current form. In, stead, we need to modify it by adding another token to the need to modify it by adding another token to the matrix that would represent the homebase of the matrix that would represent the homebase of the ghosts. ghosts. Then, when a ghost is eaten, instead of sending a Then, when a ghost is eaten, instead of sending a score event, it sends an "I've been eaten" event to score event, it sends an "I've been eaten" event to the ghost homebase. When a power pill has been the ghost homebase. When a power pill has been eaten, the homebase also receives the event eaten, the homebase also receives the event (meaning that the homebase knows how many (meaning that the homebase knows how many ghosts have been eaten since it received the last ghosts have been eaten since it received the last power-pill event. power-pill event. With this information, the homebase can calculate With this information, the homebase can calculate the score for eating that ghost, and it forwards the the score for eating that ghost, and it forwards the information on as a score-increment event to the information on as a score-increment event to the score token. score token.

Page 22: Game Design Lecture 3

2222

Tokenization Of Pac-Man (IX)Tokenization Of Pac-Man (IX)

In the game itself, the score for the ghost is In the game itself, the score for the ghost is displayed briefly where the ghost was eaten, so an displayed briefly where the ghost was eaten, so an event would also need to be sent to the ghost event would also need to be sent to the ghost telling it how much it was worth. telling it how much it was worth.

If this was not the case, then the homebase would If this was not the case, then the homebase would need to know where the ghosts were when they need to know where the ghosts were when they were eaten, and this sort of thing does not make were eaten, and this sort of thing does not make for a clean architecture. for a clean architecture.

All of this indicates the importance of thinking All of this indicates the importance of thinking through the game design fully: an incorrect through the game design fully: an incorrect interaction matrix will not help you produce the interaction matrix will not help you produce the best possible architecture. best possible architecture.

Page 23: Game Design Lecture 3

2323

*The Machine In The Ghost (I)*The Machine In The Ghost (I)

As you can see, even for a relatively simple As you can see, even for a relatively simple seeming game such as Pac-Man the seeming game such as Pac-Man the interaction interaction matrix can be quite complexmatrix can be quite complex. .

Finite-state machine (FSM) diagramsFinite-state machine (FSM) diagrams can help to can help to show some of the show some of the interrelationships more clearly interrelationships more clearly than just the interaction matrix alonethan just the interaction matrix alone..

The strength of the interaction matrix is that it The strength of the interaction matrix is that it allows you to focus on the big picture, whereas the allows you to focus on the big picture, whereas the advantage of an annotated FSM diagram is that it advantage of an annotated FSM diagram is that it allows you to allows you to focus more clearly on a specific area focus more clearly on a specific area of the matrixof the matrix. .

Page 24: Game Design Lecture 3

2424

The Machine In The Ghost (II)The Machine In The Ghost (II)

Finite-state machine Finite-state machine diagram for the ghostdiagram for the ghost

It's a different way of looking at It's a different way of looking at the same information. The the same information. The interaction matrixinteraction matrix looks at the looks at the system system from the viewpoint of from the viewpoint of the interactions between the interactions between tokenstokens, and the FSM diagram , and the FSM diagram looks at the system from the looks at the system from the viewpoint of a viewpoint of a single token and single token and how the rest of the system how the rest of the system interacts with itinteracts with it. .

The figure shows the FSM The figure shows the FSM diagram for the ghosts.diagram for the ghosts.

The notation in the FSM diagram The notation in the FSM diagram in the figure makes it slightly in the figure makes it slightly easier to read and removeseasier to read and removes any any ambiguity in the interpretation. ambiguity in the interpretation.

Page 25: Game Design Lecture 3

2525

*The Machine In The Ghost (III)*The Machine In The Ghost (III)

I have not come across any standard notation for I have not come across any standard notation for FSM diagrams that isn't too complex for my needs. FSM diagrams that isn't too complex for my needs. So we use a simple notation devised specifically So we use a simple notation devised specifically for this purpose.for this purpose.

Each individual state of a token is shown in a boxEach individual state of a token is shown in a box..

Incoming events are shown as large circlesIncoming events are shown as large circles. .

A line leads from an event and terminates at a state boxA line leads from an event and terminates at a state box. .

The smaller "connector" circle at the end of the line acts The smaller "connector" circle at the end of the line acts as an identifier. as an identifier.

In the case of two or more events entering the same state In the case of two or more events entering the same state box: each event will have a uniquely marked connector box: each event will have a uniquely marked connector circle.circle.

The usual effect of an event is to cause a shift in state. The usual effect of an event is to cause a shift in state.

A line will lead from the current state to the new state. A line will lead from the current state to the new state.

Page 26: Game Design Lecture 3

2626

*The Machine In The Ghost (IV)*The Machine In The Ghost (IV)In cases with more than one event leading into the state box, In cases with more than one event leading into the state box, the correct state shift line will be the one that has the same the correct state shift line will be the one that has the same color connector circle as that of the incoming event. color connector circle as that of the incoming event. The only other symbol of note is the circular arrow with the The only other symbol of note is the circular arrow with the "mini" event. The event is one that can cause entry into that "mini" event. The event is one that can cause entry into that state. This notation indicates that, if that event occurs, the state. This notation indicates that, if that event occurs, the state is reset to new, even though we are already in that state is reset to new, even though we are already in that state.state.If there were no such notation, then, unless explicitly shown, If there were no such notation, then, unless explicitly shown, the state would not be affected by further events of the the state would not be affected by further events of the same type. same type. Note also that we have not included events such as collisions Note also that we have not included events such as collisions with the maze wall, as these are more-generic events that with the maze wall, as these are more-generic events that affect every object, and do not cause a state change.affect every object, and do not cause a state change.

(This is true at least for Pac-Man: if this were a car (This is true at least for Pac-Man: if this were a car racing game, we may expect the collision event to racing game, we may expect the collision event to cause damage, in which case it would probably be cause damage, in which case it would probably be shown in the FSM diagram.)shown in the FSM diagram.)

Page 27: Game Design Lecture 3

2727

The Machine In The Ghost (V)The Machine In The Ghost (V)So let's examine the FSM diagram again in So let's examine the FSM diagram again in more detail. The first thing to notice is that more detail. The first thing to notice is that we have we have not included any events that are not included any events that are triggered by the ghosttriggered by the ghost. .

For example, For example, when the ghost is eatenwhen the ghost is eaten, it will , it will trigger a score eventtrigger a score event. This is . This is not indicatednot indicated on on the diagram due to personal preference. the diagram due to personal preference.

I prefer my FSM diagrams to I prefer my FSM diagrams to show only show only incoming eventsincoming events. There is no reason not to . There is no reason not to include them, but I would show the ghost-include them, but I would show the ghost-eaten event as an incoming event in the FSM eaten event as an incoming event in the FSM diagram for the score token.diagram for the score token.

Okay, back to the ghost FSM diagram: the Okay, back to the ghost FSM diagram: the three state boxesthree state boxes indicate the ghost in the indicate the ghost in the

"hunter," "hunter," "hunted," "hunted," and "eaten" states.and "eaten" states.

Look first at the Look first at the "hunter" state"hunter" state. In this case, . In this case, the event is Pac-Man eating the power pill. the event is Pac-Man eating the power pill. The power pill event has a black connector, so The power pill event has a black connector, so we look at the "hunter" state box to see which we look at the "hunter" state box to see which outgoing connection has the same connector.outgoing connection has the same connector.

Finite-state machine Finite-state machine diagram for the ghostdiagram for the ghost

Page 28: Game Design Lecture 3

2828

The Machine In The Ghost (VI)The Machine In The Ghost (VI)Following this connection leads to the Following this connection leads to the "hunted" state"hunted" state. The only other connection for . The only other connection for the "hunter" state does not have a connector the "hunter" state does not have a connector circle, indicating that it is incoming only.circle, indicating that it is incoming only.

The "hunted" state is slightly more complex. The "hunted" state is slightly more complex. Two events can affect the ghost while it is in Two events can affect the ghost while it is in the hunted state: the hunted state:

a timer event, which happens when the a timer event, which happens when the power pill runs out (shown by a white power pill runs out (shown by a white connector), and connector), and the "eaten by Pac-Man" event (black the "eaten by Pac-Man" event (black connector). connector).

Tracing the event route for the timer event Tracing the event route for the timer event shows that the ghost reverts back to the shows that the ghost reverts back to the "hunter" state when this event is triggered. "hunter" state when this event is triggered. The The "eaten by Pac-Man""eaten by Pac-Man" event puts the ghost event puts the ghost into the into the "eaten" state"eaten" state..

The circular arrow indicates the effects of The circular arrow indicates the effects of Pac-Man eating a power pill while the ghost is Pac-Man eating a power pill while the ghost is already in the "hunted" state. already in the "hunted" state.

In this case, the countdown for the timer In this case, the countdown for the timer event will reset to zero, so the ghost remains event will reset to zero, so the ghost remains in the "hunted" state for a longer period.in the "hunted" state for a longer period.

Finite-state machine Finite-state machine diagram for the ghostdiagram for the ghost

Page 29: Game Design Lecture 3

2929

The Machine In The Ghost (VII)The Machine In The Ghost (VII)

Finite-state machine diagram for the Pac-ManFinite-state machine diagram for the Pac-Man

The The "eaten" state"eaten" state is fairly is fairly simple, as there is only one simple, as there is only one event that affects the ghost in event that affects the ghost in this state.this state.

As soon as a ghost is eaten, it As soon as a ghost is eaten, it heads straight for the ghost heads straight for the ghost homebase. When the ghost homebase. When the ghost reaches homebase, it receives reaches homebase, it receives a a "resurrect" event"resurrect" event, which , which causes it to reenter the causes it to reenter the "hunted" state."hunted" state.

This is a closed FSM diagram, This is a closed FSM diagram, meaning that there are no meaning that there are no dead ends: there is no state dead ends: there is no state that a ghost can enter from that a ghost can enter from which it cannot escape. We which it cannot escape. We should contrast this with the should contrast this with the FSM diagram for the Pac-Man.FSM diagram for the Pac-Man.

Page 30: Game Design Lecture 3

3030

The Machine In The Ghost (VIII)The Machine In The Ghost (VIII)You should be able to follow this FSM You should be able to follow this FSM diagram yourself (It's very similar to diagram yourself (It's very similar to the ghost FSM diagram.) The the ghost FSM diagram.) The difference is that there are only a difference is that there are only a limited amount of limited amount of "resurrect" events"resurrect" events for the Pac-Man. for the Pac-Man.

Once he is dead, he is dead, unlike Once he is dead, he is dead, unlike the ghosts. This is the ghosts. This is an example of an an example of an open FSM diagramopen FSM diagram, because there is , because there is a way to escape the state network a way to escape the state network during the game. during the game.

This FSM diagram is actually pivotal This FSM diagram is actually pivotal to the entire game: it to the entire game: it represents the represents the transitions in state for the main transitions in state for the main player tokenplayer token. Most of the events . Most of the events that occur in this FSM will also be that occur in this FSM will also be handled by the game world token. handled by the game world token.

For example, it will For example, it will reset the level reset the level when the Pac-Man loses a lifewhen the Pac-Man loses a life and and will end the game when all lives will end the game when all lives have run out.have run out.

Finite-state machine diagram for the Pac-ManFinite-state machine diagram for the Pac-Man

Page 31: Game Design Lecture 3

3131

The Machine In The Ghost (IX)The Machine In The Ghost (IX)The most important token not yet The most important token not yet covered is the game world token. covered is the game world token.

This isn't as pretty as the other This isn't as pretty as the other diagrams, but it does show how diagrams, but it does show how the ES model translates nicely to the ES model translates nicely to the non-game aspects of the the non-game aspects of the game design. This game world game design. This game world token need not be specific to Pac-token need not be specific to Pac-Man. Man.

In fact, on a fairly general level, In fact, on a fairly general level, most games use this model for most games use this model for their user interface. The specifics their user interface. The specifics of the options screen or the cut of the options screen or the cut scenes may vary, but the scenes may vary, but the essential structure shown in the essential structure shown in the FSM diagram is the same for most FSM diagram is the same for most games.games.

Finite-state machine diagram for the Finite-state machine diagram for the game world tokengame world token

Page 32: Game Design Lecture 3

3232

The Machine In The Ghost (X)The Machine In The Ghost (X)This is the most complex FSM diagram that we have looked This is the most complex FSM diagram that we have looked at so far. It introduces the concept of modeling the majority at so far. It introduces the concept of modeling the majority of the game as a finite-state machine. of the game as a finite-state machine.

On analysis, most games can be broken down into a On analysis, most games can be broken down into a hierarchical set of finite-state machines-large finite-state hierarchical set of finite-state machines-large finite-state machines in which each state is a smaller finite-state machines in which each state is a smaller finite-state machine in its own right, and so on, down to the finest machine in its own right, and so on, down to the finest granular level. granular level.

Managed correctly, these diagrams, in combination with the Managed correctly, these diagrams, in combination with the interactivity matrix, can be used to document and design the interactivity matrix, can be used to document and design the architecture for the most complex undertakings. architecture for the most complex undertakings.

Once the notation is learned, these sorts of charts and Once the notation is learned, these sorts of charts and diagrams help developers to visualize what is needed far diagrams help developers to visualize what is needed far better than any amount of dry prose.better than any amount of dry prose.