Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/weapon/BulletManager.cc @ 782

Last change on this file since 782 was 768, checked in by nicolasc, 17 years ago

merged FICN_test back to FICN

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