Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/weapon_system/bullet_manager.cc @ 654

Last change on this file since 654 was 654, checked in by rgrieder, 16 years ago
  • removed barrel rotation
File size: 2.6 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
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
28#include "OgreSceneNode.h"
29
30#include "bullet_manager.h"
31#include "bullet.h"
32
33
34namespace orxonox {
35  using namespace Ogre;
36
37  CreateFactory(BulletManager);
38
39  BulletManager::BulletManager() : bulletsIndex_(0), bulletsSize_(8)
40  {
41    RegisterObject(BulletManager);
42    bullets_ = new Bullet*[bulletsSize_];
43  }
44
45
46  BulletManager::~BulletManager()
47  {
48    // clean up the bullet list
49    if (bullets_)
50    {
51      for (int i = 0; i < bulletsIndex_; i++)
52        delete bullets_[i];
53      delete bullets_;
54    }
55  }
56
57
58  void BulletManager::addBullet(Bullet *bullet)
59  {
60    // resize array if neccessary (double the size then)
61    if (bulletsIndex_ >= bulletsSize_)
62    {
63      // redimension the array
64      Bullet **tempArray = new Bullet*[2*bulletsSize_];
65      for (int i = 0; i < bulletsSize_; i++)
66        tempArray[i] = bullets_[i];
67      bulletsSize_ *= 2;
68      delete bullets_;
69      bullets_ = tempArray;
70    }
71
72    // add the bullet to the list
73    bullets_[bulletsIndex_++] = bullet;
74  }
75
76
77  void BulletManager::tick(float dt)
78  {
79    // update the bullet positions
80    for (int i = 0; i < bulletsIndex_; i++)
81    {
82      bullets_[i]->getNode()->translate(bullets_[i]->getVelocity()*dt);
83      //bullets_[i]->getNode()->yaw(Degree(dt*100));
84      //bullets_[i]->getNode()->roll(Degree(dt*300));
85    }
86  }
87
88  int BulletManager::getAmmunitionID(const Ogre::String &ammoName)
89  {
90    Ogre::String ammoTypes[] = { "Energy Cell", "Barrel", "Lead Shot" };
91    int ammoTypesLength = 3;
92
93    for (int i = 0; i < ammoTypesLength; i++)
94    {
95      if (ammoTypes[i] == ammoName)
96        return i;
97    }
98    return -1;
99  }
100
101  int BulletManager::getNumberOfAmmos()
102  {
103    return 3;
104  }
105
106}
Note: See TracBrowser for help on using the repository browser.