X hits on this document

259 views

0 shares

0 downloads

0 comments

36 / 102

{

}

Note: Remember to change class’s namespace to CatapultGame.

DrawableGameComponent is game component that is notified when it needs to draw itself. For more information about this class please refer to MSDN documentation (http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.drawablegamecomponent.aspx)

79.

Add the following variable declarations to the Player class:

C#

protected CatapultGame curGame;

protected SpriteBatch spriteBatch;

// Constants used for calculating shot strength

public const float MinShotStrength = 150;

public const float MaxShotStrength = 400;

// Public variables used by Gameplay class

// TODO enable this: public Catapult Catapult;

public int Score;

public string Name;

These variables will give the Player class access to the game object and to a SpriteBatch that can be used for visual output, and will allow it to keep track of the player’s score and name. Notice the commented out Catapult member, which represents the catapult associated with the player. We will un-comment the Catapult member at a later point. Also notice the two constants defined, which will be used later to perform some calculations related to firing projectiles.

80.

Add a set of initialization methods for the Player class. Two of the methods are constructors and the third is an override of the DrawableGameComponent’s Initialize method, which is typically used for loading resources required by the component before displaying it:

C#

public Player(Game game)

   : base(game)

{

   curGame = (CatapultGame)game;

}

public Player(Game game, SpriteBatch screenSpriteBatch)

   : this(game)

{

   spriteBatch = screenSpriteBatch;

}

public override void Initialize()

{

   Score = 0;

Page | 36

Document info
Document views259
Page views259
Page last viewedWed Dec 07 15:17:17 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments