ASR::Projectile Class Reference

A Projectile is any ranged "bullet" that is fired from one Unit/Building to another Unit/Building. More...

#include <Projectile.h>

Collaboration diagram for ASR::Projectile:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Projectile (Unit *source, Unit *target)
 ~Projectile ()
void setDamage (float damage)
void setSpeed (float speed)
float getDamage () const
float getSpeed () const
bool update ()
 Updates the projectiles position.

Private Member Functions

void _generateEntity ()
void _destroyEntity ()
Vector3 getPosition () const

Private Attributes

UnitmSource
UnitmTarget
float mSpeed
float mDamage
Entity * mEntity

Static Private Attributes

static int mNumBullets = 0

Detailed Description

A Projectile is any ranged "bullet" that is fired from one Unit/Building to another Unit/Building.

TODO Implement support for being fired from/to buildings.

Definition at line 21 of file Projectile.h.


Constructor & Destructor Documentation

ASR::Projectile::Projectile ( Unit source,
Unit target 
)

Definition at line 21 of file Projectile.cpp.

References _generateEntity(), and mSpeed.

00022                 : mSource ( source ), mTarget ( destination )
00023         {
00024                 _generateEntity ();
00025 
00026                 mSpeed = 0.0f;
00027         }

ASR::Projectile::~Projectile (  ) 

Definition at line 31 of file Projectile.cpp.

References _destroyEntity().

00032         {
00033                 _destroyEntity ();
00034         }


Member Function Documentation

void ASR::Projectile::_destroyEntity (  )  [private]

Definition at line 113 of file Projectile.cpp.

References ASR::Game::getSceneManager(), ASR::Game::getSingleton(), and mEntity.

Referenced by ~Projectile().

00114         {
00115                 SceneNode* node = mEntity->getParentSceneNode ();
00116 
00117                 node->detachAllObjects ();
00118 
00119                 Game::getSingleton ().getSceneManager()->destroyEntity ( mEntity );
00120                 Game::getSingleton ().getSceneManager()->destroySceneNode ( node->getName() );
00121         }

void ASR::Projectile::_generateEntity (  )  [private]

Definition at line 52 of file Projectile.cpp.

References ASR::Game::getSceneManager(), ASR::Game::getSingleton(), mEntity, mNumBullets, and mSource.

Referenced by Projectile().

00053         {
00054                 mNumBullets++;
00055                 String bulletName = mSource->getUnitName() + "_bullet_" + StringConverter::toString ( mNumBullets );
00056 
00057 
00058                 // Create a new cube projectile and add it to the list
00059                 mEntity = Game::getSingleton ().getSceneManager()->createEntity ( bulletName, "cube.mesh" );
00060 
00061                 SceneNode* bulletParent = Game::getSingleton ().getSceneManager()->getRootSceneNode()->createChildSceneNode ();
00062                 bulletParent->attachObject ( mEntity );
00063                 bulletParent->setPosition ( mSource->getPosition() );
00064                 bulletParent->setScale ( 0.1, 0.1, 0.1 );
00065 
00066                 mEntity->setMaterialName ( "ASR/Bullet" );
00067         }

float ASR::Projectile::getDamage (  )  const

Definition at line 99 of file Projectile.cpp.

References mDamage.

Referenced by update().

00100         {
00101                 return mDamage;
00102         }

Vector3 ASR::Projectile::getPosition (  )  const [private]

Definition at line 71 of file Projectile.cpp.

References mEntity.

Referenced by update().

00072         {
00073                 OgreAssert ( mEntity, "Projectile has no entity" );
00074                 return mEntity->getParentSceneNode ()->getWorldPosition();
00075         }

float ASR::Projectile::getSpeed (  )  const

Definition at line 106 of file Projectile.cpp.

References mSpeed.

Referenced by update().

00107         {
00108                 return mSpeed;
00109         }

void ASR::Projectile::setDamage ( float  damage  ) 

Definition at line 45 of file Projectile.cpp.

References mDamage.

00046         {
00047                 mDamage = damage;
00048         }

void ASR::Projectile::setSpeed ( float  speed  ) 

Definition at line 38 of file Projectile.cpp.

References mSpeed.

00039         {
00040                 mSpeed = speed;
00041         }

bool ASR::Projectile::update (  ) 

Updates the projectiles position.

If the projectile hits the target then it assigns some damage to it.

Returns true if the projectile has hit the target. False otherwise

Definition at line 79 of file Projectile.cpp.

References getDamage(), getPosition(), getSpeed(), mEntity, and mTarget.

00080         {
00081                 Vector3 direction = mTarget->getPosition () - getPosition ();
00082                 Vector3 trans = direction.normalisedCopy();
00083                 trans = trans * Timer::getSingleton ().getTimeSinceLastFrame () * getSpeed();
00084 
00085                 // Assign damage if we are close enough
00086                 if ( trans.length() > direction.length() || direction.isZeroLength () )
00087                 {
00088                         mTarget->assignDamage ( getDamage() );
00089                         return true;
00090                 }
00091 
00092                 mEntity->getParentSceneNode()->translate ( trans );
00093 
00094                 return false;
00095         }


Member Data Documentation

float ASR::Projectile::mDamage [private]

Definition at line 30 of file Projectile.h.

Referenced by getDamage(), and setDamage().

Entity* ASR::Projectile::mEntity [private]

Definition at line 32 of file Projectile.h.

Referenced by _destroyEntity(), _generateEntity(), getPosition(), and update().

int ASR::Projectile::mNumBullets = 0 [static, private]

Definition at line 36 of file Projectile.h.

Referenced by _generateEntity().

Unit* ASR::Projectile::mSource [private]

Definition at line 26 of file Projectile.h.

Referenced by _generateEntity().

float ASR::Projectile::mSpeed [private]

Definition at line 29 of file Projectile.h.

Referenced by getSpeed(), Projectile(), and setSpeed().

Unit* ASR::Projectile::mTarget [private]

Definition at line 27 of file Projectile.h.

Referenced by update().


The documentation for this class was generated from the following files:
Generated on Sun Jun 25 19:23:44 2006 for Valors End by  doxygen 1.4.7