Game Development Reference
In-Depth Information
Since we tend to think about the y axis being the height above the ground, the y
component was used for height in the game too. However, since the skier and trees are
stuck to the floor, this means the y component of all position vectors is always zero.
The game therefore scrolls the trees along the z axis and the camera is placed high
in the air and orientated to look at the skier. This still provides the effect of the trees
moving up the screen.
The second step was to get rid of all the old 2D textures and replace them with 3D
models. Since the GameObject class dealt with all the rendering, all that had to be
done was to change this class to use CIwModel instances instead of CIwMaterial
instances. The child classes then just provided a pointer to a model instead of a
pointer to the material.
The GameObject class also had a y axis rotation added to it. This is used to rotate the
skier model, which leads to a far smoother motion than we had previously.
The trees also use the rotation feature. The game features only one tree model, but
by rotating it at random angles it makes the game look far more interesting without
having to add more game resources.
Addition of a collision detection system
The code now features a very simple collision detection system. The GameObject
class now allows a collision radius to be set, which is then used to perform sphere
intersection tests.
The ModeGame::Update method now steps through every game object (currently just
trees, of course) in the game world and finds out how far away it is from the skier. If
the distance is less than the combined collision radius of the skier and the other game
object, a collision has occurred.
So, to act on these collisions, a virtual method called OnCollide has been added to
the GameObject class. Child objects can override this class and then react accordingly
whenever they collide with another object. The Skier class implements this method
so that whenever the skier collides with a tree, the game is over.
 
Search WWH ::




Custom Search