Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/modules/weapons/weaponmodes/FlameGun.cc @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 4.4 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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file FlameGun.cc
31    @brief Implementation of the FlameGun class.
32*/
33
34#include "FlameGun.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "weaponsystem/Weapon.h"
39#include "weaponsystem/WeaponPack.h"
40#include "weaponsystem/WeaponSystem.h"
41#include "worldentities/pawns/Pawn.h"
42
43#include "weapons/projectiles/FlameGunProjectile.h"
44
45namespace orxonox
46{
47    RegisterClass(FlameGun);
48
49    const int FlameGun::PROJECTILES_PER_FIRE = 3;
50
51    FlameGun::FlameGun(Context* context) : WeaponMode(context)
52    {
53        RegisterObject(FlameGun);
54
55        this->reloadTime_ = 0.1f;
56        this->damage_ = 0.0f;
57        this->speed_ = 550.0f;
58        this->lifetime_ = 1.0;
59        this->sideAcceleration_ = 2000.0;
60
61        this->setMunitionName("FlameMunition");
62        this->setFireSound("sounds/Weapon_FlameGun.ogg");
63
64        hudImageString_ = "Orxonox/WSHUD_WM_FlameGun";
65    }
66
67    FlameGun::~FlameGun()
68    {
69    }
70
71    /**
72    @brief
73        XMLPort for the FlameGun. You can define how often the projectiles Flame, how many childs should be created per Flame, the spread and the time between two Flames.
74    */
75    void FlameGun::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        SUPER(FlameGun, XMLPort, xmlelement, mode);
78
79        XMLPortParam(FlameGun, "Lifetime", setLifetime, getLifetime, xmlelement, mode);
80    }
81
82    /**
83    @brief
84        Fires the weapon. Creates a projectile and fires it.
85    */
86    void FlameGun::fire()
87    {
88        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
89
90        Vector3 muzzleDirection = this->getMuzzleDirection();
91        Vector3 directionOffset = muzzleDirection.perpendicular();
92        directionOffset.normalise();
93        Degree angle = Degree(rnd(0,360));
94        directionOffset = Quaternion(angle, muzzleDirection.normalisedCopy()) * directionOffset;
95        directionOffset.normalise();
96
97        FlameGunProjectile* projectile = new FlameGunProjectile(this->getContext());
98
99        projectile->setOrientation(this->getMuzzleOrientation());
100        projectile->setPosition(this->getMuzzlePosition());
101        projectile->setVelocity(muzzleDirection * this->speed_);
102
103        projectile->setLifetime(getLifetime());
104
105        projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
106        projectile->setDamage(this->getDamage());
107        projectile->setShieldDamage(this->getShieldDamage());
108        projectile->setHealthDamage(this->getHealthDamage());
109
110        angle = Degree(360.0/PROJECTILES_PER_FIRE);
111
112        for (int i = 0; i < PROJECTILES_PER_FIRE; ++i)
113        {
114            FlameGunProjectile* projectile = new FlameGunProjectile(this->getContext());
115
116            projectile->setOrientation(this->getMuzzleOrientation());
117            projectile->setPosition(this->getMuzzlePosition());
118            projectile->setVelocity(muzzleDirection * this->speed_);
119            projectile->setAcceleration(directionOffset*sideAcceleration_);
120
121            projectile->setLifetime(getLifetime());
122
123            projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
124            projectile->setDamage(this->getDamage());
125            projectile->setShieldDamage(this->getShieldDamage());
126            projectile->setHealthDamage(this->getHealthDamage());
127
128            directionOffset = Quaternion(angle, muzzleDirection.normalisedCopy()) * directionOffset;
129            directionOffset.normalise();
130        }
131
132
133
134       
135    }
136}
Note: See TracBrowser for help on using the repository browser.