HTML and CSS Reference
In-Depth Information
database (or other persistence layer such as a key-value store such as Redis). Keeping the architecture simple
means that you can continue to add web servers to handle an increased load, and the only area in which you
need to worry about having a scaling problem is at the database layer.
This type of architecture has served the web well for the past couple of decades and can be a suitable archi-
tecture for building multiplayer games provided it's used appropriately. It's not a great architecture for games
that need to have a lot of direct interactions between different players because the server can't immediately no-
tify one player of something another player does.
This act of periodically requesting information from the server is called polling because the client periodic-
ally polls the server for new information. Doing AJAX polling frequently can give the appearance of a pseudo-
real-time multiplayer in which things happen even when the player isn't explicitly taking an action.
The best types of multiplayer games for polling are ones in which the actions of each player are mostly
autonomous and the multiplayer aspect of the game doesn't involve players interacting too much with each oth-
er. These include games where players play primarily by themselves, but a central server keeps players honest
by running a lot of the game logic on the server. Games in the older generation of social games, such as Mob
Wars , are a good fit for this.
The other option, discussed in Chapter 21, “Going Real Time,” is to use a socket-based technology, such as
Websockets, Flash sockets, or a pseudo-socket workaround such as long-polling to allow the server to initiate
requests. Chapter 21 explains these terms and concepts in depth.
Planning a Simple Social Game
The best way to understand how to create an HTTP-based multiplayer game is to build one. You could build lots
of complicated social games, but building a simple game that serves as an example of how the various pieces of
a multiplayer game connect should be enough to get you started on something more involved.
The game that you build is a simple game based on Ian Bogost's social game parody Cow Clicker . The point
of Cow Clicker is, as you may have guessed, to click your cow at regular intervals and get points for doing so.
The game built in this chapter builds a similar game but with an exciting twist: You click a blob instead of a
cow. The blob in question is the enemy blob from the platformer game built in Chapter 18, “Creating a 2-D
Platformer.”
Although the game is quite simple, it requires all the pieces of a typical HTTP-based multiplayer game: a
server to run the game, an authentication system to log in users, a database to store the user's progress, and
game logic that resides on the server to control the actions a player can take.
The server used is a simple Node.js application running the Express framework. Being a social game, it uses
Facebook as an authentication system to allow users to log in without entering their e-mail address or creating a
password. To store progress, the game connects to a NoSQL database named MongoDB. The server will be set
up to allow only the players to click on their blob at some specified interval to prevent them from accumulating
points too quickly.
Search WWH ::




Custom Search