Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/weapon_system/BarrelGun.cc @ 742

Last change on this file since 742 was 742, checked in by landauf, 16 years ago

moved all files from misc and the tinyxml folder into the new util folder

File size: 3.5 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 <OgreStringConverter.h>
29#include <OgreSceneNode.h>
30#include <OgreEntity.h>
31#include <OgreSceneManager.h>
32
33#include "util/Math.h"
34#include "Bullet.h"
35#include "BulletManager.h"
36#include "AmmunitionDump.h"
37#include "BaseWeapon.h"
38
39#include "BarrelGun.h"
40
41
42namespace orxonox {
43  CreateFactory(BarrelGun);
44
45  BarrelGun::BarrelGun()
46  {
47    RegisterObject(BarrelGun);
48
49    primaryFirePower_ = 100;
50    secondaryFirePower_ = 500;
51    primaryFiringRate_ = 1.0/7.0;
52    secondaryFiringRate_ = 1.0/2.0;
53    primaryBulletSpeed_ = 800;
54    secondaryBulletSpeed_ = 500;
55    magazineSize_ = 25;
56  }
57
58
59  BarrelGun::~BarrelGun()
60  {
61  }
62
63
64  void BarrelGun::primaryFire()
65  {
66    if (leftAmmo_ < 1)
67    {
68      currentState_ = IDLE;
69      return;
70    }
71
72    Ogre::SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
73          getNode()->getWorldPosition(),
74          getNode()->getWorldOrientation());
75
76    Ogre::Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
77      + Ogre::StringConverter::toString(bulletCounter_++), "Barrel.mesh");
78
79    Vector3 speed = (temp->getOrientation() * Vector3(1, 0, 0))
80          .normalisedCopy() * primaryBulletSpeed_;
81    speed += getVelocity();
82
83          temp->setScale(Vector3(1, 1, 1) * 1.5);
84    temp->roll(Degree(90));
85
86    Bullet* bullet = new Bullet();
87    bullet->setNode(temp);
88    bullet->attachObject(bulletEntity);
89    bullet->setVelocity(speed);
90          bulletManager_->addBullet(bullet);
91
92    --leftAmmo_;
93  }
94
95
96  void BarrelGun::primaryFiring(float time)
97  {
98    if (time > primaryFiringRate_)
99    {
100      currentState_ = IDLE;
101    }
102  }
103
104
105  void BarrelGun::secondaryFire()
106  {
107    if (leftAmmo_ < 5)
108    {
109      currentState_ = IDLE;
110      return;
111    }
112
113    Ogre::SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
114          getNode()->getWorldPosition(),
115          getNode()->getWorldOrientation());
116
117    Ogre::Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
118      + Ogre::StringConverter::toString(bulletCounter_++), "Barrel.mesh");
119
120    Vector3 speed = (temp->getOrientation() * Vector3(1, 0, 0))
121          .normalisedCopy() * secondaryBulletSpeed_*0.5;
122    speed += getVelocity();
123
124          temp->setScale(Vector3(1, 1, 1) * 3);
125          temp->roll(Degree(90));
126
127    Bullet* bullet = new Bullet();
128    bullet->setNode(temp);
129    bullet->attachObject(bulletEntity);
130    bullet->setVelocity(speed);
131          bulletManager_->addBullet(bullet);
132
133
134    leftAmmo_ -= 5;
135  }
136
137
138  void BarrelGun::secondaryFiring(float time)
139  {
140    if (time > secondaryFiringRate_)
141      currentState_ = IDLE;
142  }
143
144}
Note: See TracBrowser for help on using the repository browser.