Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader/src/orxonox/objects/weapon/BarrelGun.cc @ 2274

Last change on this file since 2274 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "BarrelGun.h"
31
32#include <OgreStringConverter.h>
33#include <OgreSceneNode.h>
34#include <OgreEntity.h>
35#include <OgreSceneManager.h>
36
37#include "util/Math.h"
38#include "Bullet.h"
39#include "BulletManager.h"
40#include "AmmunitionDump.h"
41#include "BaseWeapon.h"
42#include "core/CoreIncludes.h"
43
44
45namespace orxonox {
46  CreateFactory(BarrelGun);
47
48  BarrelGun::BarrelGun()
49  {
50    RegisterObject(BarrelGun);
51
52    primaryFirePower_ = 100;
53    secondaryFirePower_ = 500;
54    primaryFiringRate_ = 1.0/7.0;
55    secondaryFiringRate_ = 1.0/2.0;
56    primaryBulletSpeed_ = 800;
57    secondaryBulletSpeed_ = 500;
58    magazineSize_ = 25;
59  }
60
61
62  BarrelGun::~BarrelGun()
63  {
64  }
65
66
67  void BarrelGun::primaryFire()
68  {
69    if (leftAmmo_ < 1)
70    {
71      currentState_ = IDLE;
72      return;
73    }
74
75    Ogre::SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
76          getNode()->getWorldPosition(),
77          getNode()->getWorldOrientation());
78
79    Ogre::Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
80      + Ogre::StringConverter::toString(bulletCounter_++), "Barrel.mesh");
81
82    Vector3 speed = (temp->getOrientation() * Vector3(1, 0, 0))
83          .normalisedCopy() * primaryBulletSpeed_;
84    speed += getVelocity();
85
86          temp->setScale(Vector3(1, 1, 1) * 1.5);
87    temp->roll(Degree(90));
88
89    Bullet* bullet = new Bullet();
90    bullet->setNode(temp);
91    bullet->attachObject(bulletEntity);
92    bullet->setVelocity(speed);
93          bulletManager_->addBullet(bullet);
94
95    --leftAmmo_;
96  }
97
98
99  void BarrelGun::primaryFiring(float time)
100  {
101    if (time > primaryFiringRate_)
102    {
103      currentState_ = IDLE;
104    }
105  }
106
107
108  void BarrelGun::secondaryFire()
109  {
110    if (leftAmmo_ < 5)
111    {
112      currentState_ = IDLE;
113      return;
114    }
115
116    Ogre::SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
117          getNode()->getWorldPosition(),
118          getNode()->getWorldOrientation());
119
120    Ogre::Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
121      + Ogre::StringConverter::toString(bulletCounter_++), "Barrel.mesh");
122
123    Vector3 speed = (temp->getOrientation() * Vector3(1, 0, 0))
124          .normalisedCopy() * secondaryBulletSpeed_*0.5;
125    speed += getVelocity();
126
127          temp->setScale(Vector3(1, 1, 1) * 3);
128          temp->roll(Degree(90));
129
130    Bullet* bullet = new Bullet();
131    bullet->setNode(temp);
132    bullet->attachObject(bulletEntity);
133    bullet->setVelocity(speed);
134          bulletManager_->addBullet(bullet);
135
136
137    leftAmmo_ -= 5;
138  }
139
140
141  void BarrelGun::secondaryFiring(float time)
142  {
143    if (time > secondaryFiringRate_)
144      currentState_ = IDLE;
145  }
146
147}
Note: See TracBrowser for help on using the repository browser.