Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/weapon_system/barrel_gun.cc @ 645

Last change on this file since 645 was 645, checked in by rgrieder, 16 years ago
  • weapon system up and running
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 "OgreMath.h"
29#include "OgreVector3.h"
30#include "OgreStringConverter.h"
31#include "OgreSceneNode.h"
32#include "OgreEntity.h"
33#include "OgreSceneManager.h"
34
35#include "bullet.h"
36#include "bullet_manager.h"
37#include "ammunition_dump.h"
38#include "base_weapon.h"
39
40#include "barrel_gun.h"
41
42
43namespace orxonox {
44  using namespace Ogre;
45
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_ = 300;
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          + 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) * 2);
87          temp->yaw(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
109  void BarrelGun::secondaryFire()
110  {
111    if (leftAmmo_ < 5)
112    {
113      currentState_ = IDLE;
114      return;
115    }
116
117    Ogre::SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
118          getNode()->getWorldPosition(),
119          getNode()->getWorldOrientation());
120
121    Ogre::Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
122          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
123
124    Vector3 speed = (temp->getOrientation() * Vector3(1, 0, 0))
125          .normalisedCopy() * secondaryBulletSpeed_*0.5;
126    speed += getVelocity();
127
128          temp->setScale(Vector3(1, 1, 1) * 4);
129          temp->yaw(Degree(-90));
130
131    Bullet* bullet = new Bullet();
132    bullet->setNode(temp);
133    bullet->attachObject(bulletEntity);
134    bullet->setVelocity(speed);
135          bulletManager_->addBullet(bullet);
136
137
138    leftAmmo_ -= 5;
139  }
140
141
142  void BarrelGun::secondaryFiring(float time)
143  {
144    if (time > secondaryFiringRate_)
145      currentState_ = IDLE;
146  }
147
148}
Note: See TracBrowser for help on using the repository browser.