Changeset 232 for code/branches/main_reto_vs05/src/weapon/base_weapon.cpp
- Timestamp:
- Nov 21, 2007, 12:44:02 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/weapon/base_weapon.cpp
r198 r232 37 37 #include "inertial_node.h" 38 38 #include "ammunition_dump.h" 39 #include "run_manager.h" 39 40 40 41 #include "base_weapon.h" … … 45 46 using namespace Ogre; 46 47 47 BaseWeapon::BaseWeapon(SceneManager *sceneMgr, InertialNode *node, 48 BulletManager *bulletManager, AmmunitionDump *ammoDump) 49 : sceneMgr_(sceneMgr), node_(node), 50 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 51 secondaryFireRequest_(false), 52 bulletManager_(bulletManager), secondaryFired_(false), 53 timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING), 54 name_("Base Weapon"), primaryFirePower_(100), secondaryFirePower_(500), 55 primaryFiringRate_(10), secondaryFiringRate_(2), primaryBulletSpeed_(1000), 56 secondaryBulletSpeed_(500), magazineSize_(25), ammoDump_(ammoDump) 48 BaseWeapon::BaseWeapon(InertialNode *node, AmmunitionDump *ammoDump) 49 : sceneMgr_(RunManager::getSingletonPtr()->getSceneManagerPtr()), node_(node), 50 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 51 secondaryFireRequest_(false), 52 bulletManager_(RunManager::getSingletonPtr()->getBulletManagerPtr()), 53 secondaryFired_(false), 54 timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING), 55 ammoDump_(ammoDump) 57 56 { 58 leftAmmo_ = ammoDump_->getAmmunition(magazineSize_);57 leftAmmo_ = 0; 59 58 } 60 59 … … 84 83 85 84 86 void BaseWeapon::primaryFire()87 {88 if (leftAmmo_ < 1)89 {90 currentState_ = IDLE;91 return;92 }93 94 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(95 node_->getSceneNode()->getWorldPosition(),96 node_->getSceneNode()->getWorldOrientation());97 98 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"99 + StringConverter::toString(bulletCounter_++), "Barrel.mesh");100 101 Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))102 .normalisedCopy() * primaryBulletSpeed_;103 speed += node_->getWorldSpeed();104 105 temp->setScale(Vector3(1, 1, 1) * 4);106 temp->yaw(Degree(-90));107 108 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));109 110 --leftAmmo_;111 }112 113 114 void BaseWeapon::primaryFiring(unsigned int time)115 {116 if (time > 100)117 {118 currentState_ = IDLE;119 }120 }121 122 123 85 void BaseWeapon::secondaryFireRequest() 124 86 { 125 87 secondaryFireRequest_ = true; 126 }127 128 129 void BaseWeapon::secondaryFire()130 {131 if (leftAmmo_ < 5)132 {133 currentState_ = IDLE;134 return;135 }136 137 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(138 node_->getSceneNode()->getWorldPosition(),139 node_->getSceneNode()->getWorldOrientation());140 141 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"142 + StringConverter::toString(bulletCounter_++), "Barrel.mesh");143 144 Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1))145 .normalisedCopy() * secondaryBulletSpeed_*0.5;146 speed += node_->getWorldSpeed();147 148 temp->setScale(Vector3(1, 1, 1) * 10);149 temp->yaw(Degree(-90));150 151 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));152 153 leftAmmo_ -= 5;154 }155 156 157 void BaseWeapon::secondaryFiring(unsigned int time)158 {159 if (time > 250)160 currentState_ = IDLE;161 88 } 162 89 … … 181 108 { 182 109 case RELOAD: 183 leftAmmo_ += ammoDump_->getAmmunition( magazineSize_ - leftAmmo_);110 leftAmmo_ += ammoDump_->getAmmunition("Barrel", magazineSize_ - leftAmmo_); 184 111 break; 185 112
Note: See TracChangeset
for help on using the changeset viewer.