Game Development Reference
In-Depth Information
Chapter 2
Game Programming Basics
This chapter covers the basic elements of programming games and provides a starting point for
the chapters that follow. First, you learn about the basic skeleton of any game, consisting of a
game world and a game loop . You see how to create this skeleton in JavaScript, by looking at
various examples such as a simple application that changes the background color. Finally, I talk
about clarifying your code by using comments, layout, and whitespace in the right places.
Building Blocks of a Game
This section talks about the building blocks of a game. I discuss the game world in general and then
show you the process of changing it using an update-draw loop, which continuously updates the
game world and then draws it on the screen.
The Game World
What makes games such a nice form of entertainment is that you can explore an imaginary world
and do things there that you would never do in real life. You can ride on the back of a dragon,
destroy entire solar systems, or create a complex civilization of characters who speak in an
imaginary language. This imaginary realm in which you play the game is called the game world .
Game worlds can range from very simple domains such as the Tetris world to complicated virtual
worlds in games such as Grand Theft Auto and World of Warcraft.
When a game is running on a computer or a smartphone, the device maintains an internal representation
of the game world. This representation doesn't look anything like what you see on the screen when you
play the game. It consists mostly of numbers describing the location of objects, how many hit points an
enemy can take from the player, how many items the player has in inventory, and so on. Fortunately, the
program also knows how to create a visually pleasing representation of this world that it displays on the
screen. Otherwise, playing computer games would probably be incredibly boring, with players having to
sift through pages of numbers to find out whether they saved the princess or died a horrible death.
19
 
Search WWH ::




Custom Search