Game Development Reference
In-Depth Information
Changing the class name for iteration 4
We have a new file name for the game demonstration, so now, we will need to change the class
name to match. We will also need to change the name of the constructor function. First, we
change the class name.
public class GameDemoIteration4 extends Sprite
{
And as before, we next change the constructor.
public function GameDemoIteration4() {
Updating the variable definitions for iteration 4
We need to add some variables to indicate the extreme top, bottom, left, and right of our game
screen. These are needed because all of the game characters are actually positioned at 16-pixel
tileWidth and tileHeight offsets. These offsets were added to compensate the Bitmap inside
the BlitSprite being positioned at -.5*tileWidth for x and -.5*tileWidth for y (to center it over
the Sprite 's registration point). We also set up some variables to hold the maximum and
minimum positions ( xMax , ymax , xMin , and yMin ) for the game characters inside the tunnels.
For instance, the actual horizontal minimum is 16 (not 0) because the player and enemy tanks
are offset -16 pixels on the BlitSprite to allow them to rotate around the center. If we used 0 as
the minimum horizontal movement, half the tank would actually be off the screen at x=0 for the
top left corner of the tank. The maximum horizontal movement location is 624 (624 + 16 = 640)
for the same reason. The vertical maximum and minimum movement locations are similar.
The tunnel movement locations indicate how far off the screen to move the object before it should
appear on the opposite side of the screen.
Add the following variables to the variable definition section of the GameDemoIteration4.as file:
//** added iteration #4
private var xMin:int = 16;
private var yMin:int = 16;
private var xMax:int = 624;
private var yMax:int = 464;
private var xTunnelMin:int = -16;
private var yTunnelMin:int = -16;
private var xTunnelMax:int = 656;
private var yTunnelMax:int = 496;
//** end iteration #4
You will soon see how these numbers will be used to confine the maximum and minimum
movements for the game objects and allow the tunnel warping effects to look the same on all
sides of the game level.
Updating the runGame function for iteration 4
We need to add two simple function calls to the runGame function to call the soon to be defined
update and render functions. Here is what the entire new runGame function should look like:
Search WWH ::




Custom Search