Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/script/src/orxonox/objects/weapon/BarrelGun.cc @ 906

Last change on this file since 906 was 906, checked in by bknecht, 16 years ago

created lua branch w/o Media

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#include "core/CoreIncludes.h"
41
42#include "BarrelGun.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.