63,59 €
This book guides you through the basic game development process using Python, covering essential topics such as graphics, sound, artificial intelligence, animation, and game engines. Real games are created as you progress through the text, and significant parts of a game engine are built and made available for download. New chapters on card games and a side-scroller are included. The companion files contain all the resources described in the book, including example code, game assets, video/sound editing software, and color figures.
The course begins with an introduction to how games work, followed by in-depth chapters on graphics and images, the game loop, and game AI, specifically focusing on collision detection. It then moves on to navigation, control, and sound, guiding you through creating a jet boat race game. Advanced topics such as animation, networking, and platformers are covered, providing a comprehensive understanding of game development.
Designed for both beginners and those with some experience, this book equips readers with the skills needed to develop their own games. It emphasizes practical application, ensuring you can implement what you learn. By the end of the course, you will have a solid foundation in game development and the ability to create engaging, interactive games using Python.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 521
Veröffentlichungsjahr: 2024
GAME DEVELOPMENTUSING PYTHON
Second Edition
LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY
By purchasing or using this book and disc (the “Work”), you agree that this license grants permission to use the contents contained herein, including the disc, but does not give you the right of ownership to any of the textual content in the book / disc or ownership to any of the information or products contained in it. This license does not permit uploading of the Work onto the Internet or on a network (of any kind) without the written consent of the Publisher. Duplication or dissemination of any text, code, simulations, images, etc. contained herein is limited to and subject to licensing terms for the respective products, and permission must be obtained from the Publisher or the owner of the content, etc., in order to reproduce or network any portion of the textual material (in any media) that is contained in the Work.
MERCURY LEARNING AND INFORMATION (“MLI” or “the Publisher”) and anyone involved in the creation, writing, or production of the companion disc, accompanying algorithms, code, or computer programs (“the software”), and any accompanying Web site or software of the Work, cannot and do not warrant the performance or results that might be obtained by using the contents of the Work. The author, developers, and the Publisher have used their best efforts to insure the accuracy and functionality of the textual material and/or programs contained in this package; we, however, make no warranty of any kind, express or implied, regarding the performance of these contents or programs. The Work is sold “as is” without warranty (except for defective materials used in manufacturing the book or due to faulty workmanship).
The author, developers, and the publisher of any accompanying content, and anyone involved in the composition, production, and manufacturing of this work will not be liable for damages of any kind arising out of the use of (or the inability to use) the algorithms, source code, computer programs, or textual material contained in this publication. This includes, but is not limited to, loss of revenue or profit, or other incidental, physical, or consequential damages arising out of the use of this Work.
The sole remedy in the event of a claim of any kind is expressly limited to replacement of the book and/or disc, and only at the discretion of the Publisher. The use of “implied warranty” and certain “exclusions” vary from state to state, and might not apply to the purchaser of this product.
(Companion files are also available for downloading from the publisher at [email protected].)
GAME DEVELOPMENTUSING PYTHON
Second Edition
JAMES R. PARKER
MERCURY LEARNING AND INFORMATION
Dulles, Virginia
Boston, Massachusetts
New Delhi
Copyright ©2021 by MERCURY LEARNING AND INFORMATION LLC. All rights reserved.
This publication, portions of it, or any accompanying software may not be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means, media, electronic display or mechanical display, including, but not limited to, photocopy, recording, Internet postings, or scanning, without prior permission in writing from the publisher.
Publisher: David PallaiMERCURY LEARNING AND INFORMATION22841 Quicksilver DriveDulles, VA [email protected]
James R. Parker. Game Development Using Python, Second Edition.ISBN: 978-1-68392-627-6
Library of Congress Control Number: 2020951967
The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks, etc. is not an attempt to infringe on the property of others.
212223321 This book is printed on acid-free paper in the United States of America.
Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc. For additional information, please contact the Customer Service Dept. at 800-232-0223(toll free).
All of our titles are available in digital format at academiccourseware.com and other digital vendors. Companion files (figures, code listings, etc.) for this title are also available by contacting [email protected]. The sole obligation of MERCURY LEARNING AND INFORMATION to the purchaser is to replace the disc, based on defective materials or faulty workmanship, but not based on the operation or functionality of the product.
CONTENTS
Preface
Chapter 0Games
Virtual Reality
Game Genres
Strategy
Sports
Simulation
Role Playing
Action
Adventure
Other Genres
Common Aspects of Computer Games
Platforms
Desktop Computers
Tablets
Game Consoles
Portable Consoles
Cellular Phones
Aspects of Interesting Games
Venue
Conflict
Graphics and Sound
Props
Interface
Pace/Scale
Fidelity/Accuracy
Exercises
Resources
References
Chapter 1Introduction to How Games Work
Video Game Architecture
The Graphics System
Object Level
Geometric Level
Rasterization
Comments on Optimization
The Audio System
Game Design
Mechanics
Playing the Game by the Rules
Most of a Computer Game Is Hidden
The Artificial Intelligence
Game State
Global State
Push/Pull (client server)
Managers
Broadcast-listener
Shared and Global Entities
Pong
The Game Design Document
C2H6O Jet Boat Race
C2H6O Jet Boat Race Design Document
Exercises
References
Chapter 2Graphics and Images
Pygame Essentials
Simple Static Drawing
Pixel Level Graphics
Example: Create a Page of Note Paper
Example: Creating a Color Gradient
Lines and Curves
Example: Note Paper Again
Polygons
Blitting
Drawing Text
Transparent Colors
Images
Pixels
Example: Negative Image
Image Transformations
Rotation
Pixels and Color
The C2H6O Jet Boat Race Game
Exercises
Resources
References
Chapter 3The Game Loop
Time and Intervals
The pygame.time Module
Game Loop: Bouncing a Simulated Ball
Events
The Mouse
The Keyboard
An On-Screen Button
A Simple Game
A Better Game
Randomness in Games
Randomness Generally
Randomness in Games: Dice, Cards
Probability for Beginners
Probability Calculations
Generating Random Values
Pseudorandom Numbers
Simulating Reality and Intelligence
Exercises
Resources
References
Chapter 4Game AI: Collisions
Collision Detection
Polygonal Objects
An Example
Broad Phase Collision Detection
“Operational” Methods
Geometric Tests
Using Enclosing Circles
Sphere vs. Plane Collision (Circle – Line)
Circle-Circle Collisions
Finding the Closest Point on a Line to a Specified Point
Using Bounding Boxes
Object Oriented Bounding Boxes
Space Subdivision
Narrow Phase Collision Detection
Ray/Triangle Intersection
Collision Detection in the Boat Race
Ray Casting
Exercises
References
Chapter 5Navigation and Control
Basic Autonomous Control
How to Control a Car
Cruising Behavior
Avoidance Behavior
Waypoint Representation and Implementation
Finite State Machines
FSA in Practice
State and the “What Do We Do Now” Problem
Other Useful States
Pathfinding
A* Search
Stochastic Navigation
Exercises
Resources
References
Chapter 6Sound
Basic Audio Concepts
Introduction to Sound in Pygame
Sound Options
Sound Volume
Channels
Creating Your Own Sounds
Recording Using Cell Phones and MP3 Devices
A Small Studio
Audio Software
Positional Audio
Example: Distance Attenuation
Example: 2D Positional Sound
Exercises
Resources
References
Chapter 7C2H6O Jet Boat Race
Implementing the Game: Prototypes
Prototype 0
Prototype 1
Screens
Buttons
Start Screen
Options Screen
Play Screen
End Screen
Prototype 2
The Play Screen
User Control
The Boat Class
Artificial Intelligence
Collisions
Navigation
Waypoints
Avoiding a Boat
Colliding with the Shore
Sound
Engine Sounds
Collisions and Explosions
Starting Gun
Finish
Testing
Summary
Exercises
Resources
Sound Effects
Sound Editing
Graphics Editing
References
Chapter 8Animation
Creating Elementary Animations
Animation Math
Motion Equations
Reactive Animations
Using Real Images
Ambient Animations
Character Animation
Cut Scenes
Animations in the Boat Race Game
Wakes
Summary
Exercises
Resources
References
Chapter 9C2H6O − Final Steps
Animations
Wakes
Explosions
Determining a Boat Collision
Sounds
Engine Sounds
Starting Gun
Finish
Bing
Audience
Gameplay
Completing the Race
Start
Timer
Intermediate Goals
Finish
Mini-Map
Game Data
Tuning
Exercises
Resources
References
Chapter 10Networking
The Game: Python Pong
The Paddle Class
The Ball Class
Communication between Processes
Example: Moving a Ball on the Screen
Network Pong
The Client
The Server
Blocking and Non-Blocking
Messages
The Pong Client
The Pong Server
Playing the Game
Resources
References
Chapter 11Card Games
Whist
Basic Design
The Table
The Deck
Card Implementation
Deck Implementation
First Playable
The Rules
Opening Play
Second Playable
The Play Packet
The Computer Player—NPC Play
Audio
Summary
Exercises
References
Resources
Sound Effects
Graphics
Chapter 12Platformers: Methods for Building a Side-Scrolling Game
Mechanic 1—Jumping
Mechanic 2—Capturing and Colliding
Barriers
Omnidirectional Pickup
Platforms
Mechanic 3—Active NPCs
Mechanic 4—Scrolling
Object Management
The Game
Exercises
Resources
References
Appendix A: A*in Python
Appendix B: C2H6O Jet Boat Race Game Design Document
Appendix C: The NPC (Boat) Class for the Example Game
Index
PREFACE
This book is about computer games. It’s about how to develop them using the Python language, but the book also includes some design instruction, ideas about handling assets, and a host of things that should be useful for a game developer.
Python is a programmer’s language in that it provides features that programmers usually want and often recode again and again in their various programs. Lists, dictionaries, sets, arbitrary precision integers, dynamic typing – it’s an encyclopedia of the tools a programmer uses all the time, or would if it were convenient. Well now it is. PyGame, the module used to help a programmer create games, adds to that, a surface on which to draw, many graphics primitives, sound, animation, and interaction. It’s a wonderful palette on which game developers can dip their brushes.
If you look up my name on the Internet you will see that I am a professor of Art. That’s true, but I feel like a bit of a fraud, and the reason is that I have no training as an artist. I studied mathematics and computer science at university. So how did I end up in art?
I was known for work in image processing and vision in the 1990’s as an academic. For some reason, the Game Developer’s Conference interested me. In 1998 I registered and attended, and my life was changed. The energy there was incredible. People everywhere were completely enthralled by their work. They were having fun. They were doing things and speaking about things that I had not heard about in my academic venues, and those things were fascinating. Moreover, their work had an immediate impact on people.
True, the companies were in competition for a share of the commercial games market, but the people at the conference were excited about what they knew and about sharing it. Sharing means, in this context, bringing back something as well as giving something to the others. Moreover, the group contained computer programmers, musicians and audio specialists, artists, designers, and business folks. A true meeting of multidisciplinary minds.
This book arose from my experience at GDC and my love of computer programming. I have written other books on game development, but for a casual programmer or home developer, I think that Python is a great way to proceed. Python is easy to learn, and PyGame has everything a 2D developer needs.
I do presume you have some proficiency in Python. That’s necessary to keep the book under 1000 pages; to program games, one first needs to be a programmer. What the book will teach is still significant. Computer science degrees are useful, but few degree programs offer any treatment of assets: art, sound, graphics objects. Handling those is essential to any game, and assets are a key component of many practical computer programs.
This new edition has two new chapters, and two new games. An implementation of whist is the subject of Chapter 11 and is intended as an example of how card games can be implemented, and how they differ from other types of games. Chapter 12 deals with platformer games as a genre and specific implementation details that can be adapted to other games of the same type.
The main project in this book is by necessity incomplete. It is a boat race, 2D, and seen from above; but is has sound, animation, interaction, AI, and everything that a simple game should have. It could be more fun. It could have more features. I leave these things to you. As an instructional device I think it has everything that you need. As a game it still needs your touch.
There is a lot of code in the book. The code is also included in the companion files, along with the color figures and some very useful tools for asset creation. The programs are included so that you can play with them, modify them, and experiment. If you do not, then you are missing an element of the instruction that this book offers.
Playing games is fun. Making games is fun too, but can also be profitable, educational, and useful in a great many ways. The information you glean from studying game development applies also to other digital media. That’s a bonus. As a marketer, web developer, artist, or app developer, what you can learn by studying game development is enormous.
And, of course, it’s fun. If you are not having fun, then you are doing it wrong.
Jim ParkerDecember 2020
CHAPTER 0
GAMES
For all of recorded history, humans have played games. The earliest board game is possibly the Royal Game of Ur, named after one of the oldest human cities, having been established at about 3800 BC. This is what is called a two-player chase game, similar in basic concept to Parcheesi and likely a predecessor to Backgammon.
Why are people so interested in games? There are likely many reasons: a need to keep our minds occupied during periods of inactivity, an interest in social contact, and a desire for achievement are three. For whatever reasons, games have always been a part of human society.
But what is a game?
FIGURE 0.1(Left) The Royal Game of Ur. (Right) Knuckle bone dice.
By BabelStone (Own work), CC0,
HTTPS://COMMONS.WIKIMEDIA.ORG/W/INDEX.PHP?CURID=10861909,HTTPS://COMMONS.WIKIMEDIA.ORG/WIKI/FILE:BRITISH_MUSEUM_ROYAL_GAME_OF_UR.JPG,HTTPS://WWW.SHAPEWAYS.COM/PRODUCT/LE3XNVQQM/KNUCKLEBONE-DICE-SET.
Creating a perfect definition of the word game is not a profitable activity unless it leads to something practical. Here a game should be defined in a way that leads to a practical design and implementation process, and not more philosophical concerns. Some things that some people may consider to be a game may not be included in the definition, but the idea is not to exclude any particular thing. The idea is to include as many things as possible that we think of as games, and to provide clues for how one might begin to make one.
A game involves play, another term that is hard to define. Let’s say that a game is an activity that people engage in voluntarily. A game is a structured activity, in that a game has rules and at least one goal. A game should involve variation or chance. Many simple games, like snakes and ladders, are purely games of chance; such games are often played by children, possibly as an introduction to how to play games. Most games have some chance and some skill, meaning players develop, over a period of time, a strategy for playing the game. Games like chess have very little chance. Chess uses chance to select the player who will move first, but that is all.
A game is entertaining. It can be other things also, but it must at least provide some degree of engagement for the player. As in other forms of entertainment, the feelings that a game imparts need not always be happy ones, but the game must encourage the player to continue playing in some interesting way.
By this definition catch is not a game, as there are no rules. A ball is simply thrown around. Yet it is an activity, and it is entertaining.
FIGURE 0.2 A play bow.
HTTP://WWW.PATRICIAMCCONNELL.COM/THEOTHERENDOFTHELEASH/A-NEW-LOOK-AT-PLAY-BOWS.
Games all use a mutual acceptance of the fact that what is occurring is play. The implication of this is that there should be no real-world ramifications. While the game is being played, the players are operating under the game rules and not the rules of the world or society. Some people refer to this as being in the magic circle. This explains how a king and a peasant or an employer and employee can play chess together.
Games are also used to teach. This happens in the animal kingdom, where games played by cats, for example, teach hunting skills. This appears to contradict the “no consequence” rule, but it is always true that playing a game frequently makes one better at playing the game. Dogs also play, and that brings up the magic circle again. When a dog wishes to play with another, they begin with a play bow where the chest drops to the ground, the forelegs are extended, and the eyes are looking at the potential partner.
If the invitation is accepted, two dogs of differing status can play, and that means they can do things not normally allowed: staring, growling, even biting. The game can end quickly, though, if one of the dogs goes too far, perhaps biting too hard or taking the wrong toy. Then the magic circle disappears, and real life has resumed.
There are a few general game classes. Kinetic games are usually played outdoors with little in the way of equipment and, again, are often played by children. Tag and hide and seek are examples. However, charades could be in this category too. Such games involve the motion of the players.
Board games use a set of objects or pieces that are placed on a relatively small playing surface, a board. Players usually take turns moving the pieces to locations on the board following a set of rules.
Card games use a collection of paper or wooden chips that are marked in some way. The chips (cards) are usually handed out randomly at the outset of the game, and through following the rules they are collected into sets where some sets are more valuable than others. Dice games and games like dominos can be placed in this class.
FIGURE 0.3 Examples of mathematical games.
Word games include guessing games, such as Yes and No (also called 20 questions); I Spy; How, When, and Where (from A Christmas Carol); and a host of others. These games use no props and can be played anywhere.
Mathematical games can use properties of shapes, numbers, or relationships to create puzzle-like games that can be very complex indeed. They are often played using a pencil and paper. Nim and Sprouts are two such games.
There are some other classes of games, but one that has developed in the past few decades is the computer game. These are not merely computer implementations of the other kinds of games, but they are games that use the specific characteristics of a computer to engage in play. Those properties include the ability to do many calculations each second, multimedia capabilities (images and sound), and many different ways of accepting use input. This means that a computer can display images and sounds under the control of a user (player). Objects that do not really exist except as images on a screen can be moved about and can interact with each other and a player. This opens a whole new range of possibilities for play.
It has been estimated that 69% of the human beings on this planet have played a video game. This seems a reasonable number given the popularity and ubiquity of games as observed in shopping malls, in movies, and in media generally. It amounts to about five billion people. What these players know about games varies quite a lot, but common knowledge concerns rules of specific games, interface issues such as what keys to press or buttons to push, and some tactical information about game play, like where to hide, when to jump, and so on. Very few of these people know how the games work at an implementation level though. The internal actions of the game, from key press to avatar motion, are a mystery to most people.
VIRTUAL REALITY
The term virtual means “almost” or “nearly.” Virtual reality presents a form of reality that is not quite real but seems like it. Modern computer games often present a three-dimensional view of the game area and permit the player to navigate through this space, encountering friends and obstacles as they go. This presentation is similar to the virtual reality of books and films such as The Lawnmower Man and reached the peak of its form in the Holosuite of Star Trek. In Star Trek the suite is used for entertainment. Complex games are played and complex characters are created with which to interact in a natural way. Computer games are not yet at that stage, but they seem to be approaching it.
Both computer games and virtual reality are in some sense simulations. They are computer programs that present a realistic view of a nonexistent world, but a world that has the same or similar laws as the real one. This may include gravity, time, speed, physical contact, sounds, and even human reactions. All of these aspects of the virtual world must be simulated by the computer program that implements the game. When a character lets go of its grip on an object, the object falls to the ground because the software describes that process. When the object strikes the ground, the computer program plays a sound effect, because a sound would be produced by the impact. Nothing that happens in a computer game happens unless a computer program implemented it.
When we play cards or chess, there is really no discussion about how the game is implemented. Two people set up the board or deal the cards, and away you go. A computer game, on the other hand, has a very complex underlying implementation which is really the subject of the entire discussion here. How are computer games made? The nature of virtual reality gives some idea of what is needed. A video game needs what virtual reality needs:
–A video (graphical) display
–An audio display (speakers, sound card)
–A way for a player to communicate their moves to the computer
–A way for the computer to remember positions and make moves
If you examine what people do know about games, some internal structure can be inferred. That players know rules of games implies that games have a consistent set of rules that will be implemented by a computer program somehow. The players’ knowledge of the user interface implies a level of consistency there too. We observe, for example, that the arrow keys, or sometimes the keys “W,” “A,” “S,” and “D,” are used to move the player’s avatar, but not the keys “R,” “G,” “N,” and “M”; there are conventions for user interfaces. The video game screens display images that move, and game actions result in sounds that the player can hear and use as cues. Thus, a video game must be able to display images and sounds and do so in response to user commands or internal events in the game.
On the other hand, what we need to know to design and build an original game is significantly more than that. There’s only so much that you can learn from examining a game from the outside. Games are complex systems involving computer devices and software, art (textures, 3D models, sprites), music, sound effects, video and animation, story, and a designed structure for play. There are a great many existing games, and techniques and tools that will help a game developer in their task have evolved over the last few decades. If we’re going to build a game, we should become familiar with at least some of those things.
Not all computer games are high-resolution, immersive (i.e., virtual reality), real-time games. In fact, each type or genre of game has a preferred style of representation.
GAME GENRES
Video games can be classified according to how the game is played rather than what the game is about, just as we did for games in general. A genre is defined by the kind of challenge the game offers to the player rather than the story it presents, if any. The games in a genre need not occur in the same locations, in the same time periods, or even have the same graphical style, although presentation style is more similar between games within a genre than in general. There are quite a few genres in the literature, but these are the most common ones.
Strategy
These games give the player a singular position in the game where they know nearly everything about the current state. By using plans involving placing and moving their objects (forces), the player opposes other player-controlled or game-controlled objects. Objects have specific powers within the game, and by clever opposition to the objects seen the player achieves a goal, which is usually domination of the other players. There is often an economy within which the player can acquire more objects.
Sub-genres include tower defense games, in which the player sets out static defenses along a path traveled by their opponent and real-time strategy games in which players act in real time against a dynamic game state (Warcraft, Age of Empires).
These games often use a medium-level resolution and have a point of view from above the playing area.
Sports
Sports games are the easiest to understand, because they reflect an activity that most people already know about, that being sports. Any sport can be made into a game. Golfing games use the rather clumsy mouse-keyboard interface to permit a player to control a golfer on a course, which is something of a solo activity. Team sports like football and hockey present more variation to the player, and often permit the switching of point of view between the individual team members. The games try to simulate the style of play of actual athletes so that a player can compete against their favorite individuals.
Racing games fall into this category. Actual racetracks are used in many of these, as are actual drivers and cars. A number of special interfaces have been devised to permit players to use a steering wheel and pedals, modeling the way cars are really driven.
Sports games are the most difficult to create. They tend to use high-resolution graphics to mimic what would be seen on television, which is the way many people view sports. Sport fans know quite a lot about their sport, so the game must be quite accurate. The fans in particular know how the real players actually play, and they will be critical of mistakes in this area. Each year players move between teams and new ones enter the sport, so the game must be regularly updated. And if that is not enough, the physics involved in sports games is very sophisticated. Consider the complexity of a collision between two hockey players skating at high speed (rag doll physics) or how a race car behaves when it crests a hill, leaves the ground, and then lands in a wet spot on the track.
Simulation
Simulation games have become more popular in the first part of the twenty-first century. While all games contain a simulation at their heart, a simulation game exposes that simulation and permits a player to manipulate it directly. The most obvious type of game in this genre is a flight simulator, in which the player flies an aircraft. As in sports games, flight simulators use real-world features: real airports, aircraft, and terrain. Air combat can sometimes be an aspect, as well as the distinct nature of each aircraft. There are also ship simulators and train simulators.
However, there are more complex simulation games where one simulates an ecosystem or an entire human or other lifetime. Games like SimCity allow the player to build and manage an entire city. Tycoon games (Zoo Tycoon, Roller Coaster Tycoon) are simulations of businesses and economies.
Role Playing
These games are referred to with an abbreviation, RPG. They are in some sense derived from the original non-computer game Dungeons and Dragons and cast the player in a role where they can pretend to be one of a number of characters, each having specialized abilities. There is a storyline and a set of goals, but the manner with which the player achieves the goals is up to them.
Action RPGs focus on combat and can be solo games (Dragon Slayer), multiplayer, or massively multiplayer (MMORPG), using the Internet to gather hundreds or more players into the same game at the same time (Final Fantasy XI, Elder Scrolls Online).
Action
This genre actually began the video game phenomenon. Action games are sometimes called twitch games because they require the player to respond quickly to the visual and auditory stimuli provided by the game. The player’s viewpoint is central to these games, which often involve fighting of some kind.
Platformers have a two-dimensional presentation as seen from one side. The player controls a character who runs and jumps while collecting objects, fighting, and avoiding traps and enemies. Donkey Kong is the best known of these games. They require little in the way of complex graphics and can be played on very small, low-powered computers. Shooters are very popular because the game play is so obvious: enemies approach and you shoot them. They, of course, shoot back. Game developers like these because they are so simple in concept and easy to build, although more modern ones do have much better graphics and even complex narratives. First-personshooters (Doom) follow the player precisely, whereas third-person shooters render the scene from a distance.
Fighting games focus on individual combat. Various key press combinations correspond to actions that the avatar makes in a combat situation: punches, kicks, jumps, and so on. Memorizing the key sequences and speedy presses under real time actions make this style difficult for some.
Adventure
Adventure games use gameplay style that is relatively sedate. The player has some rather general goals and achieves them by solving puzzles and by interacting with game elements like other characters, terrain, or objects. These games use non-confrontation more than violence. Some of the earliest computer games were text-based adventures (Advent, Zork) that could be played on the early dumb terminals and telex interfaces. Myst is probably the best known of these games in the modern era.
Other Genres
There are many other genres in common use: kinetic or rhythm games (Dance Dance Revolution), horror and survival horror (Silent Hill), casual, puzzle games, trivia games, and others. Each has a typical implementation style in terms of the interface, and a preferred graphical presentation that is an advantage for that genre.
COMMON ASPECTS OF COMPUTER GAMES
Computer games have common requirements which have implications for the design of games. The need for participation and rules implies the existence of objects. A player manipulates some kind of object according to the rules, which defines play. The object could simply be the player’s hand, or a ball, or a stone. There can be multiple objects and multiple object types. An object is manipulated by the player and can, in turn, affect the player, which provides interaction.
The way a player manipulates the objects is called mechanics, or game mechanics. The basic mechanics for basketball is make the ball go through a hoop from above, for example.
A game designer really designs mechanics.
The existence of objects implies the existence of some kind of playing area, volume, or space within which the game activity takes place. A game object needs space within which to act. A game space could be a board, as in checkers, or a table for card games, or a simulated 3D world for computer games like Portal, Silent Hill, or Planetside.
The game has a purpose, goal, or end point. The player must manipulate the objects according to the rules so as to accomplish the goal or reach the end point. The goal could be temporary, to be replaced by another goal when the old one is achieved. There could be multiple goals to be achieved, either collectively or optionally. Or, in some rare but popular instances, the goals could be selected by the player. That is the case in The Sims, where there is no designer-specified goal, but the players can manipulate the virtual worlds to achieve goals they have devised themselves. This the one of the most popular games ever made, but the concept of the sandbox, a place where players can manipulate the world freely, has relatively few examples. Most games have designer-specified goals and a way of keeping score.
A game should have these characteristics. What does this say about how a game, especially a computer game, should be built? What are the things that a computer game needs to implement, at a generic level? First, there must be a way of interacting with the game. How does a player interact? Usually by manipulating an object, or multiple objects, within the gameplay space. Interaction when using a personal computer usually means using a keyboard or mouse, although special-purpose game devices do exist. So, a computer game needs a straightforward way to accept input from those devices and use it to update the game.
Next, we require an object in an abstract sense. An object is manipulated by the user, so its location and state must be modifiable. The object might be able to interact with other objects. For example, it may collide with a wall. It should be able to create new objects (bullets, missiles, money, food) and destroy or drop objects (money again, traps, tools).
In the virtual space defined by the game, an object has a location and an orientation. It will normally have at least one graphical representation within that space so that the player can see its location and orientation and modify it as wanted.
While most games have these characteristics, computer games certainly do. They define the structure of a video game as a piece of software, and that structure is referred to as the architecture. In order to visualize how a computer game works, we’ll look at a specific game and then generalize what is learned there to all video games in the next chapter.
PLATFORMS
Computer games are played using a computer—everyone knows that. But there are many kinds of computers, and each one presents special advantages and disadvantages for hosting a game. The features of importance include the speed of the processor; the nature of the graphics area, including its size, color, space, and speed of access; the nature of the user interface; speed and cost of Internet access; and the amount of memory available. Games are usually developed for a particular platform, but they may expand their range of platforms with time.
Desktop Computers
PCs and Macs are good devices on which to play games. PCs in particular have a large variety of devices that can be used to supplement the gaming interfaces. Desktops typically have a large amount of memory, run at 3 GHz and more, and multiple processors and most importantly possess a high-powered graphics card. Modern graphics cards are much faster than the processors on the computer and are programmed to respond to a game’s specific needs. Programming a PC can be done in any of dozens of languages.
PCs have a range of video and audio output devices. Color quality of monitors is now excellent, although each monitor is just a little different from the others. Multiple high-quality speakers can be fed by 5.1 and 7.1 channel sound cards to create a compelling 3D sound display. By the way, the “.1” in “5.1” refers to the subwoofer, which is not really a distinct channel. The quality of the displays places a responsibility on the developers to provide good sound and images. Defects will be obvious.
Of course, computers are all sold with high-speed Ethernet cards, so Internet access is not a problem. Also, games are now often downloaded to a PC from the Internet using services such as Steam. This means that software updates to games, something that was once impossible, are now done while the player sleeps.
There are some pitfalls when using desktop computers as gaming devices. After someone has owned a computer for a few weeks, it is unlike any other computer in the world, because users always customize them. New programs are installed, special devices are connected to the bus, security measures are taken, and a host of small modifications are made. The fact that no two PCs are the same does make it difficult for developers to guarantee that their games will work. Then there are software upgrades from the system vendors and the simple variation in operating system levels and versions. What can the developer depend on? Not much. So, they must provide it for themselves.
Tablets
Tablets are not quite computers. They have a smaller, slower processor, less memory, and no extendability. The screens are small and have small, slow graphics cards. Their Internet is restricted to wireless. There is no keyboard or mouse, usually just a touch screen.
This means that the touch screen has to be used for most user input. A touch screen maps onto a mouse pretty easily in terms of the operations it can perform, but avatars are usually controlled using the “w,” “a,” “s,” and “d” keys, which are not available.
Tablets have sound capability but are limited to stereo. Headphones would be the rule. Some tablet games have been downsized from a desktop, but the advanced ones simply will not work.
Game Consoles
A game console is a specialized computer designed to run games. The system is optimized for game performance in every regard. Because a console has no other job, it has limited customizability and a much smaller range of things it can do, but it does those things very fast. It generally has multiple processors, an advanced graphics card, and some disk space so as to store a few games and high scores. Games can be distributed on disks and on the Internet.
A computer game that executes on a console is sometimes called a video game, possibly because they used to use the television as a monitor.
Programming a game for a console is actually a quite complex task involving a lot of specific knowledge of the architecture of the machine and some parallel programming. The results can be spectacular.
Popular consoles are the PlayStation (now at version 4), Xbox (multiple versions), and Nintendo Switch.
Portable Consoles
Portable consoles are handheld computers that only play video games. The king of the portables is the Game Boy by Nintendo. That version has sold over 118 million units, although it is no longer made. It has an 8-bit computer, meaning the graphics and sound were very primitive indeed. However, you could play it on a school bus or in a subway.
The Game Boy has been replaced by the DS and 3DS with 32-bit processors, which have sold 152 million units. The bestselling game was Super Mario Bros. at 31 million copies. Financially this would be the device to create games for, but Nintendo keeps a very tight reign on who can create for these devices. They keep control partly because they own the patent on the game distribution device, a small chip that fits into the body of the console. Nobody else can make those.
Other portables include the PlayStation Vita and the Sony PSP Slim.
FIGURE 0.4 The original Game Boy.
Cellular Phones
Cell phones are ubiquitous and have multiple purposes, so it makes sense that games would be created for them. The problem is that they are really just very small tablets. This means that the screen size (what developers call “real estate”) is a limiting factor. Playing a game like Civilization or World of Warcraft could be tricky. It would certainly be constraining. Yet the advantages are clear. A phone has Internet access, it has many built-in devices like GPS, tilt sensors, and accelerometers, and it has sound.
Cellular phones are frequently based on the Android operating system, although iPhones are not. This means that a developer has some clear choices to make when building a game, and the Android operating system is upward compatible for at least a few versions.
Building a game for a phone must take into account the specific constraints, although there are a few games that can be played on nearly any device; Angry Birds comes to mind.
ASPECTS OF INTERESTING GAMES
Games that have had an enduring quality tend to have things in common. Very few games have all of these, and some have only one, but these are things that should be thought of when designing and building a new game. Genre is an important consideration when incorporating features, as is the style and quality level of the graphics, the nature of the sound, and so on.
Venue
Some games take place in interesting locations, often real places that you may have visited: San Francisco, New York, Paris. People like to see new and interesting places, and people who have been to those places like to see spots they can recognize within the game. Of course, many people have seen these places in movies and on television, so that gives the sites an extra degree of familiarity. This is important, and not just because the locations are often distant and exotic to many of us. If we could create a game that would drive through your own hometown, for instance, that might interest you. The makers of the Monopoly game have done this by customizing their game for various cities, and it seems to work.
Naturally, simply placing the action in an exciting place is not good enough—you must portray that place using graphics and sound well enough so that the player can identify it. This is an implementation issue more than a design issue, but is important, and it will be discussed in more detail.
If the game is a driving game, then placing it on a racetrack is an obvious thing to do and can actually take away from the fun unless that track is familiar to the player. The track at Indianapolis is well known, for example, and a racing fan would identify it in a moment. In a basketball or hockey game, the designers and implementers go to some significant efforts to try to make the players look and act like the real players and to have the venues be accurate representations of the real thing. Fans know their sport and can be very critical when the game does not look right.
It is a little unusual to permit the player to get too far away from the path that the game designers have set out. In some games you can go anywhere in the simulated world and manipulate objects—this is an essential aspect of play in The Sims, for instance. Such games are sometimes called sandboxes, because the player, rather than the designer, defines the way the game is played. It is a feature of most games that the player appears to have much more freedom than they really do; they appear to have choices, but for simplicity’s sake the choices all seem to lead to the same few consequences. This appearance of freedom is very important to computer games in general, not just racing games. It is necessary because we just can’t simulate the entire universe.
Not yet, anyway.
Conflict
A game most often has winners and losers; games keep score. Clearly the goal is to win, and any game that does not allow the player to win will not be popular. This is the minimum conflict requirement of any game, even ones that involve collaboration. Perhaps the term challenge should be used in place of conflict. In any case, a game presents the player with obstacles to be overcome, and success is a matter of learning how to deal with these obstacles.
There are a variety of conflict sources in games, and variety can be essential to game play. Indeed, any narrative depends on a degree of conflict to be interesting. While narrative in some games is usually there only to provide background, or an excuse for the action, other times the conflict is fundamental to the story (World War II, for instance) as it defines both the goals and the means of achieving them.
So, what kind of conflict are we talking about? First-person shooters have one of the obvious forms of conflict, where the goals are achieved by shooting your opponents. Sports games have obvious conflicts, as do racing games: to defeat an opponent using the rules of the sport. In Crazy Taxi we have customers refusing to pay if we get there late, and they berate us for going too fast or slow. In the Tycoon series of games (e.g., Zoo Tycoon), conflict is created by forcing the player to balance costs and income through building attractions. Not all games use competition as conflict, but most do. Little Big Planet is a cooperative game in which the players can create new content, but there are still goals to be achieved that present challenges; it lacks the incentive to defeat an opponent, and so in that way it is not competitive.
Graphics and Sound
All really good games excel in some aspects of graphics or sound or both. Graphics do not have to be high resolution and three dimensional, but they do have to be appropriate for the specific game. Games like Halo offer high-quality graphics and good animation, but we should not mistake “high resolution” for “interesting.” The SimpsonsHit & Run offers the players the ability to explore a town that they know fairly well—Springfield, home of the Simpsons. Do not underestimate the value of sandbox mode; if the world is interesting, then just looking around can be entertaining.
Sound may be more important than graphics, especially for imparting mood. This includes excitement, and a fast-moving rock and roll audio background adds energy to a game in the same way the ethereal themes from Half Life make its world seem dangerous and spooky. It is not usually a trade-off, and we can have good graphics and audio if we just have the wherewithal to create them.
Naturally some games require better graphics, because they need to be more faithful simulations, whereas others can be very cartoony, like Double Dash, and still offer a huge degree of entertainment value. As a result of these considerations, the best games have in common an appropriate level of detail in graphics, with good audio and appropriate and entertaining objects and backdrops rendered predictably.
Props
Props are items that can be manipulated in the game. All games have props of some kind. Sports games in general have fewer props than most games, and simulation games often have many. A ball is a prop; so is a bullet or a missile, and they can move on their own. Power-ups and penalty objects are props too. Props have an immense potential for making a game more interesting. Without the possibility of picking up weapons and speedups, the Double Dash game is just a cartoon race game. Being able to slow down an opponent from a distance, and having him be a threat from behind, adds an element of excitement.
Props also allow a more interesting narrative, since entire missions and levels can depend on moving props from one place to another. They can impart important properties that remain from level to level, like magic icons, fuel, and skill points. This leads to the conclusion that complexity makes a game more interesting. There is some truth to this, so long as the game remains playable, but it is more likely that a degree of unpredictability makes the game more interesting. The game must be consistent, but it is best if it does not repeat itself exactly each time it is played. Props can be used both to make a game more complex and to make it less predictable. The location of the props can change along with a repeatable character that otherwise could become dull. A pattern of play can be useful sometimes, but it’s rarely entertaining.
Interface
Games are fundamentally an interactive medium, and interfaces are at the heart of interaction. There has been a significant effort to standardize some game interfaces. For example, on consoles we find very similar controls doing similar jobs, especially on games that run on multiple consoles. Also, games of a specific genre tend to use consistent control sequences, like arrow keys for motion. Games vary a little on use of keys/buttons and mouse gestures, and there is still too much variation generally for identical mechanics.
Some racing games use the mouse to control speed and direction. The mouse has more degrees of freedom in directional control, and the faster the car goes, the harder it is to control it with a mouse. One tends to oversteer, and mouse position is relative, not absolute. Still, given the popularity of games for tablets and smartphones, the use of the mouse is increasing. The touch gestures on tablets translate into mouse clicks and motions directly. Anyway, most tablets and phones don’t have keyboards, so using keys is a bad idea.
There are now many special game interfaces available at low cost, most of which use the USB interface. This is much better than the old parallel port or, even older, the “game port” that used to be available on PCs. These were almost always used to plug in a “joystick,” a curious term for a game control.
One such special-purpose interface is the steering wheel-pedal set that converts wheel and pedal motions into character sequences. The fact that they can be configured to send any sequence you like means that game interfaces don’t have to be standard anymore, at least in the long run. More and more people will acquire the special interfaces until the keyboard becomes old-fashioned. Figure 0.5 shows one particular brand, the Logitech.
Another USB interface device is the flight stick; the idea is to make the interface look more like that of an airplane by giving it a similar control device. The Logitech Wingman shown in Figure 0.5 is one example, which again can be configured to provide specific control sequences for any possible action.
FIGURE 0.5 Special-purpose game controllers for specific genres. (Left) A driving controller that emulates a steering wheel. (Right) A flight stick for aircraft and other vehicle simulations.
A problem is that there is no “feel,” in that the action is from the player to the game only. In a real airplane or car, the control—wheel or stick—provides a force that counters the player’s actions, and that can be relative to the speed, direction, driving surface, or even wind. Few game controllers do this. Some can vibrate, which gives a limited feedback. The Reactive Grip controller (Provancher, 2012) simulates responses of various weapons, like swords and guns, and is probably the best example of a reactive device right now.
There are many other possibilities, and progress is proceeding rapidly. At a recent Game Developer’s Conference, for example, there was an interface for sale that input brain waves from a couple of small electrodes attached to the skull and used the signals to play some simple games. The price? One hundred dollars. There is university research that includes some work on hand gesture recognition as applied to controlling games on the PC—hand motions are interpreted as requests to move, pick something up, and so on. Ultimately games will become an invisible technology, like telephones and TV. They will be anywhere we like and will require no special knowledge or hardware to play.
Pace/Scale
The driving games that are the most fun typically allow you to go fast. Submarines move slowly but inevitably and cannot turn or stop in any reasonable time. The pace of the game must be appropriate (that word again) for the kind of situation being simulated by the game. In addition, as the player gains experience, the game should present more and more difficulties. In some games this means that the game speeds up; other times there are more or stronger opponents.
An impression of speed can be given by placing objects near the player that move past at a high speed. Buildings are good for this because they have a lot of detail that flashes past in a similar way to what we’d see on movies or in real life. In fact, a variety of objects in a range of distances is effective in conveying the illusion.
Sound is crucial as well. Play a fast tempo game with the sound off to see the difference. A fast-moving music track helps a lot, as does a good set of speed implying sound effects: positional sound, Doppler effects, and so on.
One nice idea that is simple to implement and is now a standard in games is a backdrop with scenery painted on it. This effect is used in movies too; the shots of the inside of Borg ships on Star Trek are actors in front of paintings, and quite a lot of science fiction depends on paintings to convey distance and strange environments. The use of drops in a game can add depth that is noticed if absent, but usually draws no comment otherwise.
A 3D game consists of a terrain model on top of which we have both moving and stationary objects. There is usually a distance beyond which objects will not be rendered (far clipping plane), and as objects get closer they seem to “pop” into existence when they pass that distance. In the far distance we have an image painted on a surface that passes for the horizon. This often has hills and sky painted on it, or an urban backdrop. In any case, the drop has no real depth. A game will have the drop rotate as the player turns so as to give the illusion that the car changes direction.
Fidelity/Accuracy
When we create a game, we create an entire universe. We get to decide where things are, how big they are, what they eat, and so on. In particular, the rules of physics as we understand them in the real universe are flexible, and we decide how they work in our universe. In many kinds of games, the accuracy of the physics takes a back seat to playability and entertainment value. So, if you have ever played Doom, you will probably know that the player can seem to run pretty quickly through a level. You may not know that if you measured it, you would see the character has a top speed of 60 mph! This does not detract from the fun; on the contrary, restricting game objects to normal speeds will slow the game down a lot.
Physics includes a variety of topics, including how collisions are handled, how fuel is consumed, how fast the vehicles can accelerate and what the top speeds are, how fast cars can enter a turn before they skid, and how a vehicle can become airborne if it reaches the peak of a hill. Most games do take liberties with physics to enhance game play, especially the more cartoon-style games. We will discuss this further after there has been a chance to look at how physics is implemented in a game. Just remember that any rule can be violated if it makes the game more fun.
EXERCISES
The following problems will exercise your knowledge of the material in this chapter, and they will sometimes require that you do some more research before you are able to complete them.
1.Describe the venue, conflict, pace, scale, and fidelity of two games that you currently play. Think about other games you enjoy—do they have common elements?
2.The game Nim has a known strategy for winning. Any game for which a win or draw can be forced is said to be strongly solved. What other games are strongly solved? Name two.
3.A serious game is one that has some function in addition to entertainment, such as education. Name at least one serious game.
4.Describe the interface to Angry Birds. How does the interface contribute to the fact that the game can be found on so many different platforms?
5.Art style can be an important aspect of a game. Sketch two possible visual interfaces for a computer-based Nim game.
6.The game Snakes and Ladders is purely random. There is no strategy that can be used; it all depends on the throw of the dice. Suggest rules that would allow some degree of strategy in this game.
7.Consider the kind of materials that can be found in a dollar store or craft store. Make up a game that uses such easily found materials, write a set of rules, and play the game with at least two other people. Did the game play the way that you thought it would?
RESOURCES
Yale Game Theory class, http://oyc.yale.edu/economics/econ-159.
MIT course on Computer Games and Simulations for Investigation and Education, https://ocw.mit.edu/courses/urban-studies-and-planning/11-127j-computer-games-and-simulations-for-education-and-exploration-spring-2015/
MIT Game Design course, http://ocw.mit.edu/courses/comparative-media-studies/cms-608-game-design-fall-2010/.
Raph Koster, Theory of Fun for Game Design, http://www.theoryoffun.com/theoryoffun.pdf.
https://www.archimedes-lab.org/game_nim/play_nim_game.html.
REFERENCES
1.Elwyn R. Berlekamp, John H. Conway, and Richard K. Guy. (2001). Winning Ways for Your Mathematical Plays, Vol. 1–4. A K Peters/CRC Press. Boca Raton, FLA.
2.Johann Huizinga. (2016). Homo Ludens: A Study of the Play-Element in Culture. Kettering, OH: Angelico Press.
3.Aki Järvinen. (2008). Games without Frontiers: Theories and Methods for Game Studies and Design. Tampere, Finland: Tampere University Press.
4.William Provancher. (2011). Multidirectional controller with shear feedback. US Patent 13/269,948, filed October 10, 2011, and issued August 14, 2013, Publication number US 2012/0038468 A1.
5.Miguel Sicart. (2008). “Defining Game Mechanics.” The International Journal of Computer Game Research 8, no. 2 (December). http://www.gamestudies.org/0802/articles/sicart
6.John von Neumann and Oskar Morgenstern. (1947). Theory of Games and Economic Behavior, 2nd edition. Princeton, NJ: Princeton University Press.
7.Dan Whitehead. (2018). Game Over: The Games We Loved to Play and the Consoles Time Forgot. Studio Press.
CHAPTER 1
INTRODUCTION TO HOW GAMES WORK
Computer games are first of all games, and second computer based. A good way to begin as a student of game development is to examine a real game to see how it functions in some detail. We can take it apart and take a look at how a computer game is structured at the design and implementation level. A simple game that everyone knows is ideal for this purpose. Pong is one of the first computer games, and it has all of the elements of other games, except that it is simple enough to understand completely. First, let’s take a look at how a game operates at the computer level.
VIDEO GAME ARCHITECTURE
The word “architecture” can be defined as construction or structure generally; any ordered arrangement of the parts of a system: the architecture of the universe.1