X hits on this document

278 views

0 shares

0 downloads

0 comments

63 / 102

{

   set

   {

       Catapult.Enemy = value;

       Catapult.Self = this;

   }

}

public bool IsActive { get; set; }

136.

The last thing to do in the Player class is to override the Update method. This will in turn cause the player’s associated catapult to update:

C#

public override void Update(GameTime gameTime)

{

   // Update catapult related to the player

   Catapult.Update(gameTime);

   base.Update(gameTime);

}

137.

Open the AI.cs file and add a new field to the AI class:

C#

Random random;

138.

Revise the Initialize method. It should now look like this:

C#

public override void Initialize()

{

   //Initialize randomizer

   random = new Random();

   Catapult.Initialize();

   base.Initialize();

}

139.

Finally, we will override the Update method in the AI class. This will be used as an opportunity for the computer player to shoot at the human player:

C#

public override void Update(GameTime gameTime)

{

   // Check if it is time to take a shot

   if (Catapult.CurrentState == CatapultState.Aiming &&

       !Catapult.AnimationRunning)

   {

       // Fire at a random strength

       float shotVelocity =

Page | 63

Document info
Document views278
Page views278
Page last viewedFri Dec 09 08:32:58 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments