Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/releases/0.1.0/src/orxonox/objects/weapon/BarrelGun.cc @ 2410

Last change on this file since 2410 was 790, checked in by nicolasc, 17 years ago

merged FICN back into trunk
awaiting release.

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