X hits on this document

229 views

0 shares

0 downloads

0 comments

50 / 102

117.

We will start by creating a class to represent the catapult projectiles. Both players fire projectiles and they need to behave in accordance to the laws of physics, taking the wind into account as well. Add a new class under the “Catapult” folder and name it Projectile.

118.

Add the following using statements to the top of the newly created file:

C#

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Graphics;

119.

As the projectile represents an entity that will be drawn on screen, change the Projectile class to inherit from the DrawableGameComponent class.

C#

class Projectile : DrawableGameComponent

{

}

Note: Do not forget to alter the new class’s namespace as we have done previously.

120.

Add the following field and property definitions to the Projectile class:

C#

SpriteBatch spriteBatch;

Game curGame;

Random random;

// Textures for projectile

string textureName;

// Position and speed of projectile

Vector2 projectileVelocity = Vector2.Zero;

float projectileInitialVelocityY;

Vector2 projectileRotationPosition = Vector2.Zero;

float projectileRotation;

float flightTime;

bool isAI;

float hitOffset;

float gravity;

Vector2 projectileStartPosition;

public Vector2 ProjectileStartPosition

{

   get

   {

       return projectileStartPosition;

   }

   set

   {

       projectileStartPosition = value;

   }

Page | 50

Document info
Document views229
Page views229
Page last viewedSun Dec 04 16:53:34 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments