Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/weapon/BulletManager.cc @ 872

Last change on this file since 872 was 871, checked in by landauf, 17 years ago

merged core branch to trunk

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 "OrxonoxStableHeaders.h"
29
30#include "BulletManager.h"
31#include "Bullet.h"
32#include "core/CoreIncludes.h"
33
34
35namespace orxonox {
36  CreateFactory(BulletManager);
37
38  BulletManager::BulletManager() : bulletsSize_(8), bulletsIndex_(0)
39  {
40    RegisterObject(BulletManager);
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  void BulletManager::tick(float dt)
77  {
78    // update the bullet positions
79    for (int i = 0; i < bulletsIndex_; i++)
80    {
81      bullets_[i]->getNode()->translate(bullets_[i]->getVelocity()*dt);
82      //bullets_[i]->getNode()->yaw(Degree(dt*100));
83      //bullets_[i]->getNode()->roll(Degree(dt*300));
84    }
85  }
86
87  int BulletManager::getAmmunitionID(const std::string &ammoName)
88  {
89    std::string ammoTypes[] = { "Energy Cell", "Barrel", "Lead Shot" };
90    int ammoTypesLength = 3;
91
92    for (int i = 0; i < ammoTypesLength; i++)
93    {
94      if (ammoTypes[i] == ammoName)
95        return i;
96    }
97    return -1;
98  }
99
100  int BulletManager::getNumberOfAmmos()
101  {
102    return 3;
103  }
104
105}
Note: See TracBrowser for help on using the repository browser.