Time for action – catching the cube
1. Add the following declaration to the
Fields
region of theCube
class:private const float collisionRadius = 0.25f;
2. Add a
Properties
region of theCube
class:#region Properties public BoundingSphere Bounds { get { return new BoundingSphere(location, collisionRadius); } } #endregion
3. In the
CubeChaserGame
class, add the following to the class declarations area to hold the player's current score:float lastScoreTime = 0f; int score = 0;
4. In the
Update()
method of theCubeChaserGame
class, add the following code right before the call tocube.Update()
:if (cube.Bounds.Contains(camera.Position) == ContainmentType.Contains) { cube.PositionCube(camera.Position, 5f); float thisTime = (float)gameTime.TotalGameTime.TotalSeconds; float scoreTime = thisTime - lastScoreTime; score += 1000; if (scoreTime < 120) { score += (120 - (int)scoreTime) * 100; } lastScoreTime = thisTime; }
5. In the
Draw...