X hits on this document

223 views

0 shares

0 downloads

0 comments

54 / 102

   // Set initial projectile velocity

   projectileVelocity.X = velocityX;

   projectileVelocity.Y = velocityY;

   projectileInitialVelocityY = projectileVelocity.Y;

   // Reset calculation variables

   flightTime = 0;

}

The above method initializes a projectile after it has been “fired” by one of the catapults.

The projectile class is ready and we can now set our sights on expanding the Catapult class.

126.

It is time to add some additional fields and constants to the Catapult class. To make things simple, replace all code between the two comments “// MARK: Fields start” and “// MARK: Fields end”:

C#

// MARK: Fields start

// Hold what the game to which the catapult belongs

CatapultGame curGame = null;

SpriteBatch spriteBatch;

Random random;

const int winScore = 5;

public bool AnimationRunning;

public string Name;

// In some cases the game need to start second animation while first

// animation is still running;

// this variable define at which frame the second animation should start

// UNCOMMENT: Dictionary<string, int> splitFrames;

Texture2D idleTexture;

// UNCOMMENT: Dictionary<string, Animation> animations;

SpriteEffects spriteEffects;

// Projectile

Projectile projectile;

string idleTextureName;

bool isAI;

// Game constants

const float gravity = 500f;

Page | 54

Document info
Document views223
Page views223
Page last viewedSun Dec 04 01:35:17 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments