X hits on this document

351 views

0 shares

0 downloads

0 comments

45 / 102

102.

We will eventually want a way to keep track of a catapult’s state. Add the following enum declaration above the class (still inside the same file):

C#

[Flags]

public enum CatapultState

{

   Idle = 0x0,

   Aiming = 0x1,

   Firing = 0x2,

   ProjectileFlying = 0x4,

   ProjectileHit = 0x8,

   Hit = 0x10,

   Reset = 0x20,

   Stalling = 0x40

}

The above enum will make it possible for a catapult to have several states at any given time.

103.

Add the following variable declarations to the Catapult class:

C#

// MARK: Fields start

CatapultGame curGame = null;

SpriteBatch spriteBatch;

Texture2D idleTexture;

string idleTextureName;

bool isAI;

SpriteEffects spriteEffects;

// MARK: Fields end

Now the class can store its associated game, a SpriteBatch with which to display assets, and a texture which shows the catapult in its idle state. We also added a variable to represent whether the catapult is AI controlled or human controlled and an additional rendering variable we will not immediately use.

104.

Add the following properties and backing fields to the class. One will be used to represent the catapult’s position, and another to represent the catapult’s state:

C#

Vector2 catapultPosition;

public Vector2 Position

{

   get

   {

       return catapultPosition;

   }

}

Page | 45

Document info
Document views351
Page views351
Page last viewedThu Jan 19 21:48:56 UTC 2017
Pages102
Paragraphs3115
Words17333

Comments