Game Development Reference
In-Depth Information
The left and right method applies the change in the ship's speed. The speed changes
by a delta ( m_speedDelta ) each time the key press is processed. This determines the
acceleration or deceleration of the ship. There is a lot of scope for game design right
on this variable. The m_speedDelta could depend on the ship type that a player
owns or buys in the game. The delta can also be affected by the pick-ups along the
track. Further, this change may be temporary for a certain amount of time, again
depending on other factors, such as the kind of pick-up.
Note that the x and y are limited by MAX_X and MAX_Y . This is done to keep the ship
visible on the screen. The maximum value of x for the ship could be 800 , the screen
width, that is at really high speed the ship will appear at the right edge of the screen,
making it harder for the player to dodge the oncoming asteroids. All this depends on
the taste of the game designer.
As with increasing or decreasing the ship's speed, the ship is also allowed to
move vertically, and again by a delta. This delta value effectively controls how
maneuverable the ship is.
The updateSpeed method is listed next:
public function updateSpeed(update:Number):void {
if ( (update < 0 && m_speed > 0) ||
(update > 0 && m_speed < m_maxSpeed) )
m_speed += update;
// make sure speeds are within allowed values
if ( m_speed <= 0 )
m_speed = 0.1;
if ( m_speed > m_maxSpeed )
m_speed = m_maxSpeed;
}
The update parameter can either be positive or negative. We first check to make sure
that the current speed is between zero and the maximum speed of the ship. After
applying the speed update, we again make sure that the speed is within the range.
Skinning the ship
In order to create a wide variety of ships, we can do something similar to what we
did in the jigsaw sample. Instead of the jigsaw shape, we have a base image of the
ship and then we can apply various masks onto the ship. This will allow us to
create tons of different ships in no time.
 
Search WWH ::




Custom Search