#include <Projectile.h>
Collaboration diagram for ASR::Projectile:
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 | |
Unit * | mSource |
Unit * | mTarget |
float | mSpeed |
float | mDamage |
Entity * | mEntity |
Static Private Attributes | |
static int | mNumBullets = 0 |
TODO Implement support for being fired from/to buildings.
Definition at line 21 of file Projectile.h.
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 }
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] |
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 }
float ASR::Projectile::mDamage [private] |
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] |
Unit* ASR::Projectile::mSource [private] |
float ASR::Projectile::mSpeed [private] |
Unit* ASR::Projectile::mTarget [private] |