| [668] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  * | 
|---|
 | 4 |  * | 
|---|
 | 5 |  *   License notice: | 
|---|
 | 6 |  * | 
|---|
 | 7 |  *   This program is free software; you can redistribute it and/or | 
|---|
 | 8 |  *   modify it under the terms of the GNU General Public License | 
|---|
 | 9 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
 | 10 |  *   of the License, or (at your option) any later version. | 
|---|
 | 11 |  * | 
|---|
 | 12 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 13 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 14 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 15 |  *   GNU General Public License for more details. | 
|---|
 | 16 |  * | 
|---|
 | 17 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 18 |  *   along with this program; if not, write to the Free Software | 
|---|
 | 19 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
 | 20 |  * | 
|---|
 | 21 |  *   Author: | 
|---|
 | 22 |  *      Reto Grieder | 
|---|
 | 23 |  *   Co-authors: | 
|---|
 | 24 |  *      ... | 
|---|
 | 25 |  * | 
|---|
 | 26 |  */ | 
|---|
 | 27 |  | 
|---|
| [786] | 28 | #include "OrxonoxStableHeaders.h" | 
|---|
| [784] | 29 |  | 
|---|
| [668] | 30 | #include "BulletManager.h" | 
|---|
 | 31 | #include "Bullet.h" | 
|---|
 | 32 |  | 
|---|
 | 33 |  | 
|---|
 | 34 | namespace orxonox { | 
|---|
 | 35 |   CreateFactory(BulletManager); | 
|---|
 | 36 |  | 
|---|
| [680] | 37 |   BulletManager::BulletManager() : bulletsSize_(8), bulletsIndex_(0) | 
|---|
| [668] | 38 |   { | 
|---|
 | 39 |     RegisterObject(BulletManager); | 
|---|
 | 40 |     bullets_ = new Bullet*[bulletsSize_]; | 
|---|
 | 41 |   } | 
|---|
 | 42 |  | 
|---|
 | 43 |  | 
|---|
 | 44 |   BulletManager::~BulletManager() | 
|---|
 | 45 |   { | 
|---|
 | 46 |     // clean up the bullet list | 
|---|
 | 47 |     if (bullets_) | 
|---|
 | 48 |     { | 
|---|
 | 49 |       for (int i = 0; i < bulletsIndex_; i++) | 
|---|
 | 50 |         delete bullets_[i]; | 
|---|
 | 51 |       delete bullets_; | 
|---|
 | 52 |     } | 
|---|
 | 53 |   } | 
|---|
 | 54 |  | 
|---|
 | 55 |  | 
|---|
 | 56 |   void BulletManager::addBullet(Bullet *bullet) | 
|---|
 | 57 |   { | 
|---|
 | 58 |     // resize array if neccessary (double the size then) | 
|---|
 | 59 |     if (bulletsIndex_ >= bulletsSize_) | 
|---|
 | 60 |     { | 
|---|
 | 61 |       // redimension the array | 
|---|
 | 62 |       Bullet **tempArray = new Bullet*[2*bulletsSize_]; | 
|---|
 | 63 |       for (int i = 0; i < bulletsSize_; i++) | 
|---|
 | 64 |         tempArray[i] = bullets_[i]; | 
|---|
 | 65 |       bulletsSize_ *= 2; | 
|---|
 | 66 |       delete bullets_; | 
|---|
 | 67 |       bullets_ = tempArray; | 
|---|
 | 68 |     } | 
|---|
 | 69 |  | 
|---|
 | 70 |     // add the bullet to the list | 
|---|
 | 71 |     bullets_[bulletsIndex_++] = bullet; | 
|---|
 | 72 |   } | 
|---|
 | 73 |  | 
|---|
 | 74 |  | 
|---|
 | 75 |   void BulletManager::tick(float dt) | 
|---|
 | 76 |   { | 
|---|
 | 77 |     // update the bullet positions | 
|---|
 | 78 |     for (int i = 0; i < bulletsIndex_; i++) | 
|---|
 | 79 |     { | 
|---|
 | 80 |       bullets_[i]->getNode()->translate(bullets_[i]->getVelocity()*dt); | 
|---|
 | 81 |       //bullets_[i]->getNode()->yaw(Degree(dt*100)); | 
|---|
 | 82 |       //bullets_[i]->getNode()->roll(Degree(dt*300)); | 
|---|
 | 83 |     } | 
|---|
 | 84 |   } | 
|---|
 | 85 |  | 
|---|
| [715] | 86 |   int BulletManager::getAmmunitionID(const std::string &ammoName) | 
|---|
| [668] | 87 |   { | 
|---|
| [715] | 88 |     std::string ammoTypes[] = { "Energy Cell", "Barrel", "Lead Shot" }; | 
|---|
| [668] | 89 |     int ammoTypesLength = 3; | 
|---|
 | 90 |  | 
|---|
 | 91 |     for (int i = 0; i < ammoTypesLength; i++) | 
|---|
 | 92 |     { | 
|---|
 | 93 |       if (ammoTypes[i] == ammoName) | 
|---|
 | 94 |         return i; | 
|---|
 | 95 |     } | 
|---|
 | 96 |     return -1; | 
|---|
 | 97 |   } | 
|---|
 | 98 |  | 
|---|
 | 99 |   int BulletManager::getNumberOfAmmos() | 
|---|
 | 100 |   { | 
|---|
 | 101 |     return 3; | 
|---|
 | 102 |   } | 
|---|
 | 103 |  | 
|---|
 | 104 | } | 
|---|