X hits on this document

281 views

0 shares

0 downloads

0 comments

47 / 102

107.

Finally, we will override the Draw method so that the Catapult could be drawn to the screen:

C#

public override void Draw(GameTime gameTime)

{

   spriteBatch.Draw(idleTexture, catapultPosition, null, Color.White,

       0.0f, Vector2.Zero, 1.0f,

       spriteEffects, 0);

   base.Draw(gameTime);

}

The catapults can now be drawn, but in order for that to actually happen, we need to revisit the player classes.

108.

Open the Player.cs file and uncomment the field definition for the “Catapult” field. The relevant portion of the file should now look like this:

C#

...

protected CatapultGame curGame;

protected SpriteBatch spriteBatch;

// Public variables used by Gameplay class

public Catapult Catapult;

public int Score;

public string Name;

...

109.

Override the Draw method in the Player class:

C#

public override void Draw(GameTime gameTime)

{

   // Draw related catapults

   Catapult.Draw(gameTime);

   base.Draw(gameTime);

}

110.

Open the Human.cs file and locate the TODO marker we have left in the Human class’s constructor. Change it so that the constructor would look like the following:

C#

public Human(Game game, SpriteBatch screenSpriteBatch)

   : base(game, screenSpriteBatch)

{

   Catapult = new Catapult(game, screenSpriteBatch,

                           "Textures/Catapults/Blue/blueIdle/blueIdle",

new Vector2(140, 332), SpriteEffects.None, false);

}

Page | 47

Document info
Document views281
Page views281
Page last viewedFri Dec 09 10:09:06 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments