Game Development Reference
In-Depth Information
player.visible = false;
drawCamera(); // draw the level so it will roll in from the side
}
Here is a detailed description of the main points of this function:
1.
First, we attempt to execute code as described previously: we orient the camera so the
player is in the center of the screen.
2.
If the player cannot be centered in either the x or y direction (or both), the camera is
set to start at 0 on that axis, and the player position is set accordingly. If the player is
not near an edge on an axis, it is centered on that axis.
3.
You will start to notice the use of the nextX and nextX variables for the player.x ,
player.y , player.worldX , and player.worldY . We will always update these first and
then do collision detection and set the player.x and player.y values to the nextX and
nextY only if the car is allowed to move in that direction.
4.
Next, we set all of the default values for car attributes. Here is a brief description of
each:
player.dx = 0 : The dx is the vector value for movement along the x axis.
player.dy = 0 : The dy is the vector value for movement along the y axis.
player.nextRotation=levelPlayerStartFacing : This will be set when the
player attempts to turn the car.
player.turnSpeed=.3 : The turn speed will adjust based on the velocity of the
car. This is the number of degrees the rotation of the car is changed then a left
or right arrow is pressed.
player.maxTurnSpeed=.6 : This is the maximum value for turn speed. This value
is linear and related to velocity directly.
player.minTurnSpeed=.3 : This is the minimum speed the car will turn while
moving (the car cannot turn when velocity equals 0).
player.maxVelocity=8 : This is the maximum number to multiply the sine and
cosine of the radians of the current player rotation to obtain the dx and dy values.
player.acceleration=.05 : The acceleration of the car is added every frame as
long as the up key is pressed and held.
player.deceleration=.03 : The deceleration is subtracted from the velocity
then the up key is not pressed.
player.reverseVelocityModifier = .3 : This is the percentage of the
maximum velocity that applies to the reverse velocity; the car cannot go as fast
in reverse as it can going forward unless you set this to 1.
player.radius = .5 * player.width : We use the radius to find the positions of
the side LookAheadPoint instances.
Search WWH ::




Custom Search