[190] | 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 modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | * (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, see <http://www.gnu.org/licenses/>. |
---|
| 19 | * |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Reto Grieder |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include "OgreSceneManager.h" |
---|
| 29 | |
---|
| 30 | #include "bullet_manager.h" |
---|
| 31 | #include "bullet.h" |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | namespace orxonox { |
---|
| 35 | namespace weapon { |
---|
| 36 | using namespace Ogre; |
---|
| 37 | |
---|
| 38 | BulletManager::BulletManager(SceneManager *sceneMgr) : sceneMgr_(sceneMgr), |
---|
| 39 | bulletsIndex_(0), bulletsSize_(8) |
---|
| 40 | { |
---|
| 41 | bullets_ = new Bullet*[bulletsSize_]; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | BulletManager::~BulletManager() |
---|
| 46 | { |
---|
| 47 | // clean up the bullet list |
---|
| 48 | if (bullets_) |
---|
| 49 | { |
---|
| 50 | for (int i = 0; i < bulletsIndex_; i++) |
---|
| 51 | delete bullets_[i]; |
---|
| 52 | delete bullets_; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | void BulletManager::addBullet(Bullet *bullet) |
---|
| 58 | { |
---|
| 59 | // resize array if neccessary (double the size then) |
---|
| 60 | if (bulletsIndex_ >= bulletsSize_) |
---|
| 61 | { |
---|
| 62 | // redimension the array |
---|
| 63 | Bullet **tempArray = new Bullet*[2*bulletsSize_]; |
---|
| 64 | for (int i = 0; i < bulletsSize_; i++) |
---|
| 65 | tempArray[i] = bullets_[i]; |
---|
| 66 | bulletsSize_ *= 2; |
---|
| 67 | delete bullets_; |
---|
| 68 | bullets_ = tempArray; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | // add the bullet to the list |
---|
| 72 | bullets_[bulletsIndex_++] = bullet; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | bool BulletManager::tick(unsigned long time, Real deltaTime) |
---|
| 77 | { |
---|
| 78 | // update the bullet positions |
---|
| 79 | for (int i = 0; i < bulletsIndex_; i++) |
---|
| 80 | { |
---|
| 81 | bullets_[i]->node_->translate(bullets_[i]->speed_*deltaTime); |
---|
| 82 | bullets_[i]->node_->yaw(Degree(deltaTime*100)); |
---|
| 83 | bullets_[i]->node_->roll(Degree(deltaTime*300)); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | return true; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | } |
---|
| 90 | } |
---|