APress - Net Game Programming With Directx 9.0 (2003).pdf

(1286 KB) Pobierz
*0511_ch00_FINAL
.NET Game Programming
with DirectX 9.0
ALEXANDRE SANTOS LOBÃO
AND
ELLEN HATTON
30369311.002.png
.NET Game Programming with DirectX 9.0
Copyright ©2003 by Alexandre Santos Lobão and Ellen Hatton
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN (pbk): 1-59059-051-1
Printed and bound in the United States of America 12345678910
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewer: David Jung
Editorial Directors: Dan Appleman, Gary Cornell, Simon Hayes, Karen Watterson, John Zukowski
Managing Editor: Grace Wong
Project Manager: Sofia Marchant
Copy Editor: Ami Knox
Production Manager: Kari Brooks
Compositor: Diana Van Winkle, Van Winkle Design Group
Artist and Cover Designer: Kurt Krames
Indexer: Lynn Armstrong
Manufacturing Manager: Tom Debolski
Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 175 Fifth
Avenue, New York, NY, 10010 and outside the United States by Springer-Verlag GmbH & Co. KG,
Tiergartenstr. 17, 69112 Heidelberg, Germany.
In the United States, phone 1-800-SPRINGER, email orders@springer-ny.com , or visit
http://www.springer-ny.com .
Outside the United States, fax +49 6221 345229, email orders@springer.de , or visit
http://www.springer.de .
For information on translations, please contact Apress directly at 2560 9th Street, Suite 219,
Berkeley, CA 94710.
Phone 510-549-5930, fax: 510-549-5939, email info@apress.com , or visit
http://www.apress.com .
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
30369311.003.png
CHAPTER 4
River Pla.Net:
Tiled Game Fields,
Scrolling, and
DirectAudio
I N THIS CHAPTER we’ll apply the
concepts learned in the pre-
vious chapter about Direct3D
to implement DirectX gaming
classes (such as GameEngine
and Sprite ), so we’ll easily be
able to create high-speed
graphics games. We’ll also
introduce basic DirectAudio
concepts that will allow us to
include sound effects and
background music in our
games.
We’ll also examine the
concept of tiled game fields
and scrolling in games, and
start implementing a clone of
Activision’s River Raid game, a
popular title for Atari 2600 and VCS. Our sample game, shown in Figure 4-1, will be
finished in the next chapter, where we’ll introduce DirectInput and the use of
force-feedback joysticks.
Scrolling games and tile-based games have been around since earlier video
game consoles and home computers hit the shelves, and we often see games that
use both techniques. We’ll discuss some interesting points about each in the next
sections.
211
Figure 4-1. River Pla.Net, a River Raid clone, is this chapter’s
sample game
30369311.004.png
Chapter 4
Scrolling Games
Although the basic concept of scrolling games is very simple, there are many inter-
esting variations we must consider when we start creating a new game. We can
define scrolling games as the games in which the background moves in a con-
tinuous way. It’s a very loose definition, but it’ll suffice for our goals here.
Some of the typical choices we must make when coding scrolling games are
discussed next.
Scrolling Direction
All scrolling games are either vertical scrollers, horizontal scrollers, or full scrollers,
meaning that the background on these games scroll in a vertical direction, in a
horizontal direction, or in any direction. We’ll discuss some variations of these
movements in this section.
The most common choice is to implement vertical “up-down” scrollers (as
does the sample game for this chapter), where the background moves from the top
to the bottom of the screen, and horizontal “right-left” scrollers, where the back-
ground moves from right to left. We don’t see many scrolling games using the
opposite direction schemes because using these directions makes our games seem
more natural to players.
Full scrollers are harder to implement and to play, but when made correctly,
they can lead to very interesting gameplay. Just imagine a game in which players
can move their character in any direction: This might be an interesting feature, but
the player could become disorientated, and the game objective would be less clear.
Parallax Scrolling
Parallax scrolling is an ingenious trick that gives players the feeling of being in a
3-D environment, even with flat images.
The basic idea is to create different layers of background objects, each one
moving at different speeds. For example, if we are controlling a monkey in a
jungle, we can create some bushes and trees that scroll at the same speed as the
terrain, trees a little farther off that move a little slower, distant mountains that
move very slowly, and maybe a fixed moon in the sky.
212
30369311.005.png
River Pla.Net: Tiled Game Fields, Scrolling, and DirectAudio
This approach creates a more lifelike game, but must be used with care
because it can lead to visual clutter and confusion for the player. A good tip is to
make distant objects with less vivid colors. This adds to the ambience without
distracting the player.
Player or Engine-Controlled Scrolling
When coding the scrolling for our game, we need to decide whether the back-
ground will always be moving (except, perhaps, when facing some end-of-level
bosses), if it will move depending solely on the player’s input, or if the movement
will be a combination of both.
In some scrolling games, the player is always in the same position on the
screen (usually the middle), and the background rolls according to the player’s
movement: When a player moves the joystick to the right, his or her character
walks to the right (moving in a fixed position), while the background moves to the
left. Many race games use this approach.
Some games use a similar solution: A player walks freely in a restricted area,
and when he or she gets near any border, the background starts to move until the
player starts walking back toward the center of the screen.
Some other games use a combination of automatic scrolling with player-
controlled scrolling; the player controls scrolling right or left, but is always
moving from the top to the bottom of the screen.
One last group of games comprises the auto-scrolling ones, such as the
sample we’ll code in this chapter: The background simply goes on scrolling
without player intervention, creating a nonstop action game.
Choosing the Scrolling Type
Even a topic as simple as choosing the scroll type we should use in our game may
lead to extensive discussion. Of course there’s a lot more we can do when coding
scrolling games; don’t be reluctant to try new ideas. For example, we can split the
screen and make two areas with different scrolling behaviors, such as in the old
arcade game Olympics, where the computer controls a character running in the
upper middle of the screen and the player runs in the lower middle; each half-
screen scrolls with its own speed.
The most appropriate type of scrolling will vary from game to game, and it will
be up to us to make the final choice between code complexity and game playability.
213
30369311.001.png
Zgłoś jeśli naruszono regulamin