Game Development Reference
In-Depth Information
some 3D content to be displayed. Stopping and restarting the calls to tick() would complicate the logic of
the menu system with no consequential performance gains.
The tick() function is where most of the real-time game play occurs. The following is an outline of the
major blocks of this function.
Frame rate mechanics : Calls requestAnimationFrame() to schedule the next frame and calculates
the time elapsed from the previous tick() call.
Keyboard input sampling: function sampleKeys() : Keyboard events onkeydown() and onkeyup()
are received from the document object in an asynchronous manner. The key codes from these
asynchronous events are pushed into a FIFO (First in First out) queue. This queue is then emptied
in the next tick() function after the presses are made. This method of user-input capture ensures
that even if the user made a quick succession of presses to two or more keys in between frames, no
key press will get lost. This is especially important in a game like CycleBlob, where quick and
precise keyboard action can save the player from crashing into a wall.
Artificial Intelligence decisions : The AI module of each computerized player is given a chance to
evaluate the state of the game and possibly make a decision to turn the bike either left or right, or
continue forward in the current direction.
Animation step: function animate() : Lets every animated object advance its animation state
according to the amount of elapsed time. First and foremost, the players' positions are updated.
After that, all animated special effects are updated. This includes the following:
Explosions quickly grow and fade away
The wall of a recently-crashed player changes color and drops down into nothing
Bonus objects that reside on the grid; there is animation for their appearance, disappearance,
and rotation
Number of live objects displayed on the top-left corner of the screen; these also have animations
for appearance, disappearance, and rotation
Notice that at this stage, nothing was yet displayed in this call to tick() . Only the state of the
animations was updated. For example, in the explosion animation, the state consists of the radius of
the rings and the scale factor of the spark model. For player bikes, the state consists of the A and B
vertices and the T parameter that tells how far between them the bike is.
Render 3D menu items : Some 3D items are not part of real-time game play and don't depend on the
state of the player. The rotating models of the lives-count in the top-left corner are such objects, as well as
the 3D objects on the instructions page (enemy and player bikes, an example rotation bonus object).
Render the main 3D scene of the game: function drawScene() : This function draws all of the elements
that take part in the game-play. It sets up the needed transformations and renders the following:
The pre-processed grid model
For every player, the bike and the wall behind it
Any explosions that may be occurring
Any bonus objects that reside on the grid
 
Search WWH ::




Custom Search