Encontre seu próximo livro favorito

Torne'se membro hoje e leia gratuitamente por 30 dias.
Flash 10 Multiplayer Game Essentials

Flash 10 Multiplayer Game Essentials

Ler amostra

Flash 10 Multiplayer Game Essentials

Comprimento:
673 página
5 horas
Lançado em:
Jul 9, 2010
ISBN:
9781847196613
Formato:
Livro

Descrição

The book provides all the essentials needed to implement a fully featured multiplayer game in Flash. It begins by dissecting a basic hello-world example providing its code and an insight into each feature that is required. Following the book is easy because of the excellent illustrations and working code samples. Four complete game implementations with increasing complexity are discussed; each example is presented with detailed design, implementation code, and screenshots. This book discusses essentials for beginner to intermediate Flash Developers who have perhaps created a game or two in Flash and want to take the next step, and create something that can be played by two or more players over the internet. This book will appeal to professional and amateur developers with an inclination to build synchronous multiplayer games with Flash. No prior knowledge of networking or server-side programming is required.
Lançado em:
Jul 9, 2010
ISBN:
9781847196613
Formato:
Livro

Sobre o autor


Relacionado a Flash 10 Multiplayer Game Essentials

Livros relacionados
Artigos relacionados

Amostra do Livro

Flash 10 Multiplayer Game Essentials - Prashanth Hirematada

Table of Contents

Flash 10 Multiplayer Game Essentials

Credits

About the author

About the reviewers

Preface

What this book covers

Who this book is for

Conventions

Reader feedback

Customer support

Errata

Piracy

Questions

1. Getting Started

Development environment

Pulse SDK

Installing Flash Builder 4

Downloading the Pulse SDK

Installing Pulse SDK

Post-installation checks

Running the samples

Starting the server

Starting the client

A high-level architecture of multiplayer game server

Simple deployment architecture

Enterprise deployment architecture

The session server process

The balancer process

Server game programming

Zero server-side programming

Network programming paradigm

Client-to-client interaction

The server modules

Game server modules

Persistence

Session and session manager

Avatar manager

Lobby and room manager

Friends

Chat

Object synchronization

Object serialization

Security

Connection management and message dispatcher

Message

The game client

The overall structure of a multiplayer game

The main game loop

Processing messages from the server

The programming API

Summary

2. Game Interface Design

Overview of Pulse library components

The Pulse API design

Creating the Hello World sample

Setting up the project

The Hello World specification

The schema file

Code generator

Project directory structure

Introduction to PulseUI

Screen management in PulseUI

The PulseGame class

Exploring the Hello World sample

HelloGame.as

The login screen

The screen class

The skinner class

The outline class

Player registration

Exploring the game server deployment

Registration and login

Registration

The login

Dealing with multiple logins

Guest logins

Summary

3. Avatar and Chat

Introduction to Pulse modeler

Example schema

Design of a game avatar

Modeling the avatar

Avatar display in Hello World

Customizing Player Display

Avatar-related APIs

PulseGame client APIs

Pulse game client callbacks

Friends management

Friends in Hello World

The friends API

Customizing friends display

The chat feature

The chat API

Chatting in Hello World

Customizing chat display

Implementing high scores

High scores in Hello World

Skinning the user interface

Skinning for Hello World

Summary

4. Lobby and Room Management

Introduction to lobby and room management

Modeling game room

Game room management

Seating order

Room states

Player states

Kicking out a player

Room types

Audience

Room properties

The lobby screen implementation

Lobby screen in Hello World

Customizing lobby screen

Customizing game room display

Filtering rooms to display

Lobby and room-related API

New game screen implementation

New game screen in Hello World

Customizing the new game screen

New game room API

Designing the game screen

Implementing the game screen

Customizing the game screen

Summary

5. Game Logic

Gameplay implementation

Modeling game states

Game states types

Game states in Hello World

Code walk-through

GameStateSprite class

General flow of events

Game state schema

Adding a new game state

Updating game state

Removing a game state

Game state API

Miscellaneous classes

The Button Effect class

The Slider class

The ShakeEffect class

Summary

6. Multiplayer Game Example: Tic-tac-toe

Running the game from sample directory

The Pulse UI framework

Setting up the project

Getting started: Modeling the game

Project directory structure

Code walk-through

TictactoeGame

Overriding the constructor

Overriding the initNetClient method

Implementing a turn-based game

Sending and receiving player actions

TictactoeSkinner

TictactoeNewGameScreen

TictactoeGameScreen

Initializing the game screen

Displaying player turn

Letting the player make the move

Who won?

Finding the winner

Other screens and features

Lobby screen

Chat

TopTen

Registration screen

Summary

7. Multiplayer Game Example: Jigsaw

Setting up the project

Files in the project

The game graphics

DisplayManager

Managing pieces—Group

The PieceSprite class

Creating a piece

Dragging of pieces

Checking for matches

Multiplayer and networking

Code generation

Screen classes

The JigsawGame class

Overriding the constructor

Overriding the initNetClient method

Server communication

The JigsawSkinner class

The NewJigsawGameScreen class

The JigsawGameScreen class

Summary

8. Card-based Racing Game Tutorial

Implementation

Graphics

The map and frog movement

The step class

The frog class

Card management

Screen management

Class Skin

Class JJF

Class NewGame

Multiplayer design

Card distribution

Frog position

Assigning player color

Schema

Gameplay implementation

Assigning colors

Determining the initial frog positions

Getting the initial three cards

Playing the game

Summary

9. Real-time Racing Game Tutorial

Game design

The game client

The main game loop

The spaceship class

Controlling movement

Skinning the ship

The racetrack module

Mapping coordinates

Loading quadrants

The mini-map class

The Radar class

Implementing items

Detecting collisions

Implementing the shield

Finishing the race

Multiplayer implementation

Designing the schema

The ShipMask class

The ShipPos class

The item class

The ShipWin class

Assigning ship color

Putting items on the map

Ship prediction and interpolation

Winning the race

Summary

A. Introduction to FlashBuilder and AS3

Installing Flash Builder 4

AS2 versus AS3

Exploring Flash Builder 4

Hello World!

Defining a class

Classes—defining game objects

Creating game objects

Variables and properties

Magic numbers and constants

Methods

Property and method access

Taming the inheritance monster

Interface class

Static properties and methods

B. Graphics Programming in AS3

Flash object hierarchy

Object

EventDispatcher

DisplayObject and DisplayObjectContainer

InteractiveObject

Sprite, in detail

Which way is up?

Let the fun begin

Events

Timers

Trace

Embedding pictures

Mouse events

What do we need to handle mouse events for?

How to register for a mouse event

What are the events we can handle in Flash?

Handling mouse events in many objects

Where is the Mouse?

Drag-and-drop

Keyboard events

Arrow key handling: The basics

Arrow key handling: The professional way

Labels, text fields, and sprite buttons

Filters: Adding effects to sprites

Transparency: Playing with the alpha channel

Cool fading screens

Cutting up assets

Index

Flash 10 Multiplayer Game Essentials


Flash 10 Multiplayer Game Essentials

Copyright © 2010 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: July 2010

Production Reference: 1020710

Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK.

ISBN 978-1-847196-60-6

www.packtpub.com

Cover Image by Vinayak Chittar (<vinayak.chittar@gmail.com>)

Credits

Author

Prashanth Hirematada

Reviewers

Ali Raza

Bruce Wade

Acquisition Editor

David Barnes

Development Editor

Dhwani Devater

Technical Editor

Pallavi Kachare

Copy Editor

Lakshmi Menon

Indexer

Rekha Nair

Editorial Team Leader

Akshara Aware

Project Team Leader

Lata Basantani

Project Coordinator

Jovita Pinto

Proofreader

Aaron Nash

Production Coordinator

Alwin Roy

Cover Work

Alwin Roy

About the author

Prashanth Hirematada, ia the founder of Gamantra, a game technology company focused on Network engines and server platforms. Prior to founding Gamantra in 2006, he was a Chief Architect at Shanda Interactive Entertainment Ltd., where he was responsible for creating a common game development platform for all MMOG initiatives at Shanda. He joined Shanda in 2004 through Shanda's acquisition of Zona, Inc., a MMOG game technology company, headquartered in Santa Clara, USA. At Zona, as a Technical Chief Architect, he was responsible for server-side architecture and implementation of MMOG framework. Prior to joining Zona in 2001, Prashanth worked in various Silicon Valley based technology start-up companies developing software at various levels for well over seven years.

His master's thesis was a distributed implementation of the Message Passing Library (MPI) on a heterogeneous network of workstations including Solaris, HP-UX, OpenStep, and Windows-NT. He received his MS in Computer Science from the California State University, Sacramento, California, in 1994 and his BS in Computer Science from Bangalore University, Bangalore, India in 1992. You can contact him at <prash@gamantra.com>.

This book would not have been possible without the constant blessings, encouragement, and belief received from my parents throughout my entire life. I would like to acknowledge the constant support of my loving wife, Jessie who puts up with all my long hours in front of the computer. I also thank Tony Chen and Wilson Wu for their dedicated support with the implementation of GNet and Pulse SDK.

About the reviewers

Ali Raza is a fresh and invigorated aspirant in the field of design, development, and authoring. He became part of the IT field from quite an early age and worked up from designing business cards, flyers, books, websites, digital maps, software interfaces, and almost all design-related things to audio and video editing, animation, and even minor 3D modeling in Autodesk Maya. Later, playing with code became his passion, which compelled him to work in various programming languages including C++, Java SE, Actionscript 3, and PHP.

Ali is pursuing a Master of Science degree in Computer. He is also an Adobe Certified Instructor, Adobe Certified Expert, and Sun Certified Java Programmer.

He is currently a senior developer at 5amily Ltd, a London-based, forthcoming genealogy-related social networking rich Internet application. Previously, he has worked with different national and international advertising, telecommunication, and IT firms.

Ali is authoring Adobe Flex 3 with AIR exam guide from the platform of ExamAids. He is also a regular author in Flash and Flex developer magazine and writes project-based articles, predominantly on Data Visualization, and also loves writing book reviews.

In his spare time, you will find him either engulfed in design and development related books or envisaging the accomplishment of a series of certifications in ACE Flash and ACE Dreamweaver after his masters. You can contact him at <manofspirit@gmail.com>.

I would like to express my gratitude to the packet publishing for bringing unique titles. I would also like to thank to Dhwani Devater and Jovita Pinto.

Bruce Wade got started in software development using Flash early on in his web development career. After going to school for game programming he quickly found himself leveraging Flash for online game development. He works around the clock implementing new Flash games and tools for his website Warply Designed, which is dedicated to independent game developers.

I would like to thank all the authors for the sleepless nights I had reading their books to help improve on my skill sets.

Preface

There are plenty of Flash games on the web, but what about multiplayer Flash games and moreover real-time multiplayer games? Not that many!

The Pulse SDK presented in this book abstracts the standard set of features required for any multiplayer game, which is leveraged throughout the book. As you will see, writing multiplayer becomes quite straightforward with all the standard set of features such as room and lobby management, friends, top ten, registration, among others, all taken care of, allowing the developer to focus only on the game.

What this book covers

The reason that one does not see that many real-time multiplayer games is due to the fact that development and deployment requires a great deal of knowledge about networking and server programming. The developer must also be well aware of the performance bottlenecks along the way when the game is played by several thousands of players at the same time. There is also the issue of dealing with the database in order to save the scores, achievements, friends, and other attributes of a player.

All of these present a high barrier for the developer attempting to write a multiplayer game.

This book presents all the features required for any multiplayer game, their design and implementation. All of the implementation presented in this book is based on the Pulse SDK framework.

Chapter 1, Getting Started, sets up all the required software, namely, Flash Builder 4 and Pulse SDK. We will also fire up the game server and test drive a few multiplayer game samples. The server and the client may be run all on one machine and on separate physical machines. We will go through the high-level design and architecture of a game server and its modules that must be implemented in order to support any typical multiplayer game. We will also see an enterprise architecture that is capable of serving thousands of concurrent players.

We will also touch upon the communication paradigms between game clients, namely peer-to-peer and the client-server architectures. The book follows the client server exclusively.

Throughout the book, we will work at a higher level of abstraction in developing our games. To make things even simpler, we will use a paradigm and a set of APIs provided by Pulse SDK that does not require us to write a single line of code on the server and yet we will implement, turn-based and non turn-based games, puzzle games as well as fast action racing games.

Chapter 2, Game Interface Design, mainly deals with the game UI required by a typical multiplayer game. The UI is leveraged by the Pulse UI framework bundled along with Pulse SDK. From Login screen, lobby screen for creating a new game room, game screen itself. The UI also involves friends display, players display within the game room, chat, and more. The chapter is presented with the Hello World sample in the backdrop. The complete source code for Hello World sample comes with the Pulse package, so you can modify the sample and experiment as you progress through the chapter.

Chapter 3, Avatar and Chat, starts to model our game objects starting with avatar for the game. We will explore what it means to model the game entities. We will learn how to design the avatar in this chapter. We will explore the different kinds of objects (entities) that may be modelled within the Pulse Modeller, also the property types that may be defined within each class (entity). We will also explore the game UI in greater detail as related to the friends display and player display. We will also see how we can customize them from the default behaviour as offered by the Pulse UI framework. You will learn the Pulse APIs that deal with customizing the avatar for the player, making friends, and chat.

Chapter 4, Lobby and Room Management, discusses the central feature to any multiplayer games, lobby and room management. You will continue to use the Pulse Modeller to design the rooms that is required for the game. We will learn about the different room properties and their status during its existence. We will also see how players may join, leave, or kick a player out of a room. Again we will leverage the Pulse API to manage all these features within our game.

Chapter 5, Game Logic, is the heart of the game—the game itself! We will review all the different Pulse game state APIs that deal with implementing the game logic. We will learn how we can design the game states required for the game via the Pulse Modeller and use them through an innovative set of Pulse APIs. We will see how we can use the unique set of APIs that makes any game logic implementation possible without writing a single line of server code.

Chapter 6, Multiplayer Game Example: Tic-Tac-Toe, has the complete source for Tic-Tac-Toe included in the Pulse package; in this chapter, we will do a complete walk-through of the code. Tic-tac-toe is of course a real-time multiplayer game. Multiple clients may connect to the server, create a room or join a room, and play the game. We will go through the different screens such as login screen, lobby, top-ten, and registration. The game is implemented in completeness, and includes friend-making and chat.

Chapter 7, Multiplayer Game Example: Jigsaw walks through a non-turn-based game, a multiplayer jigsaw (unlike tic-tac-toe, which is a turn-based game), where multiple players collaborate to solve the same jigsaw puzzle. The player matching the most pieces wins. The chapter will walk you through in detail to first make the client part work, leaving the multiplayer implementation to the latter part of the chapter.

The walk-through includes cutting any given picture into jigsaw pieces and then managing them during game play. We will learn how to detect the correct matching pieces when they are next to each other. We will also see how all the matched pieces are kept synchronized among all the players that are currently playing the game.

Chapter 8, Card-based Racing Game Tutorial: Jump Jump Frog, is a fun card-based racing game. The chapter will teach you a commonly occurring game implementation, namely card distribution. Here we make heavy use of unique game state concept available in Pulse SDK. Similar to other game implementation tutorials in this book, we will first start with the design of the schema for the game and then we will learn the graphics part of the game client and finally explore the multiplayer implementation.

Chapter 9, Real-time Racing Game Tutorial: AstroRace, teaches to implement the most exciting game genre, a racing game. We will see what we need to design in the schema for the game. The exciting game to play has its challenges set for the developers. In this game, the players will race against one another in a spaceship. Along the racetrack the players will have avoid items that may work against them or pickup items that will help them get faster to the finish line.

Appendix A: This part of the book introduces Flash Builder and coding in AS3. It is a great start for those programmers who are novice AS3 programmers. Here the basic AS3 syntax is presented in a relatively few number of pages, letting starters get proficient in flash programming in a short amount of time. For those of you getting into object oriented programming for the first time, this appendix is a great start.

Appendix B: Having a good handle on the AS3 syntax, this appendix presents the basics of flash graphics programming. It starts with the basic building block, sprite. Readers will also learn to draw and move them around on stage. In depth discussions of essential techniques to any flash game development such as events, timers, event listeners, mouse and keyboard handling are also presented. Interesting things like transparency, added cool effects to sprites are also part of this exciting appendix. Plenty of examples with complete code that will jump start you into your next game development.

Who this book is for

This book is written for game developers that are either starting out with game development in Flash or professional game developers wanting to write the next hot real-time multiplayer game.

If you are starting out new in Flash, you will find the appendix very useful as they teach working with Flash Builder 4, learning to program in AS3, and lots of programming examples required for game programming, including sprite basics, keyboard and mouse handling, and a lot more.

Professional game developers, who are comfortable writing single player games, find it challenging when it comes to multiplayer games, a lot of distracting tasks to take care of before a line of code for the game is written. Armature multiplayer game developers would appreciate the challenges that befall when writing their first game. The book discusses each of the challenges.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: The two environment variables that all of Pulse SDK depends on are GAMANTRA and GNET_JAVA.

A block of code is set as follows:

HelloGameState parent=GameState classId=601 >

0 name=x count=1 type=int/>

1 name=y count=1 type=int/>

2 name=color count=1 type=int/>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public function MyGame() {

s_instance = this;

new MySkinner();

 

super();

}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: Clicking Next will take you to a standard UCLA screen.

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <feedback@packtpub.com>, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Note

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded

Você chegou ao final desta amostra. Inscreva-se para ler mais!
Página 1 de 1

Análises

O que as pessoas pensam sobre Flash 10 Multiplayer Game Essentials

0
0 avaliações / 0 Análises
O que você acha?
Classificação: 0 de 5 estrelas

Avaliações de leitores