X hits on this document

265 views

0 shares

0 downloads

0 comments

56 / 102

// Used to determine whether or not the game is over

public bool GameOver { get; set; }

These properties will allow a catapult to keep track of the wind, its associated player and the enemy player, the current shot being fired, and the state of the current game.

128.

Now alter the Catapult class’s “Initialize” method by adding some code just before the call to base.Initialize. This code will initialize the new fields we have added:

C#

...

   // Load the textures

idleTexture = curGame.Content.Load<Texture2D>(idleTextureName);

   // Initialize the projectile

   Vector2 projectileStartPosition;

   if (isAI)

       projectileStartPosition = new Vector2(630, 340);

   else

       projectileStartPosition = new Vector2(175, 340);

   // TODO: Update hit offset

   projectile = new Projectile(curGame, spriteBatch,

       "Textures/Ammo/rock_ammo", projectileStartPosition,

       60, isAI, gravity);

   projectile.Initialize();

   AnimationRunning = false;

   stallUpdateCycles = 0;

   // Initialize randomizer

   random = new Random();

   base.Initialize();

}

While we have set the projectile’s hit offset to 60 in the above code, we will later change this so that the size is relative to the catapult asset.

129.

Override the Update method in the Catapult class, giving it an opportunity to update its own state and keep track of fired projectiles:

C#

public override void Update(GameTime gameTime)

{

   bool isGroundHit;

   bool startStall;

   CatapultState postUpdateStateChange = 0;

Page | 56

Document info
Document views265
Page views265
Page last viewedThu Dec 08 01:00:54 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments