Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto_vs05/src/bullet_manager.cc @ 177

Last change on this file since 177 was 177, checked in by rgrieder, 16 years ago
File size: 2.2 KB
Line 
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
34namespace orxonox {
35  using namespace Ogre;
36
37  BulletManager::BulletManager(SceneManager *sceneMgr) : sceneMgr_(sceneMgr),
38        bulletsIndex_(0), bulletsSize_(10)
39  {
40    bullets_ = new Bullet*[10];
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  bool BulletManager::tick(unsigned long time, Real deltaTime)
76  {
77    // update the bullet positions
78    for (int i = 0; i < bulletsIndex_; i++)
79    {
80      bullets_[i]->node_->translate(bullets_[i]->speed_*deltaTime);
81      bullets_[i]->node_->yaw(Degree(deltaTime*100));
82      bullets_[i]->node_->roll(Degree(deltaTime*300));
83    }
84
85    return true;
86  }
87
88}
Note: See TracBrowser for help on using the repository browser.