Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/modules/weapons/weaponmodes/HsW01.cc @ 6227

Last change on this file since 6227 was 6227, checked in by youngk, 14 years ago

Inserted a firing sound into HsW01. BUG Sound plays only once on first fire.

  • Property svn:eol-style set to native
File size: 4.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 *      Hagen Seifert
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "HsW01.h"
30
31#include "core/CoreIncludes.h"
32#include "core/Executor.h"
33#include "core/XMLPort.h"
34#include "graphics/Model.h"
35
36#include "weapons/projectiles/Projectile.h"
37#include "weapons/MuzzleFlash.h"
38#include "weaponsystem/Weapon.h"
39#include "weaponsystem/WeaponPack.h"
40#include "weaponsystem/WeaponSystem.h"
41#include "worldentities/WorldEntity.h"
42#include "worldentities/pawns/Pawn.h"
43
44#include "sound/WorldSound.h"
45
46namespace orxonox
47{
48    CreateFactory(HsW01);
49
50    HsW01::HsW01(BaseObject* creator) : WeaponMode(creator)
51    {
52        RegisterObject(HsW01);
53
54        this->reloadTime_ = 0.5;
55        this->damage_ = 15;
56        this->speed_ = 2500;
57        this->delay_ = 0;
58        this->setMunitionName("LaserMunition");
59
60        this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&HsW01::shot, this)));
61        this->delayTimer_.stopTimer();
62
63        this->defSndWpnFire_ = new WorldSound(this);
64        this->defSndWpnFire_->setLooping(false);
65        this->setDefaultSound("sounds/Weapon_Laser_shrt.ogg");
66    }
67
68    HsW01::~HsW01()
69    {
70        if(this->isInitialized())
71        {
72            delete this->defSndWpnFire_;
73        }
74    }
75
76    void HsW01::XMLPort(Element& xmlelement, XMLPort::Mode mode)
77    {
78        SUPER(HsW01, XMLPort, xmlelement, mode);
79
80        XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode);
81        XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode);
82
83    }
84
85    void HsW01::setMaterial(const std::string& material)
86    {
87        this->material_ = material;
88    }
89
90    std::string& HsW01::getMaterial()
91    {
92        return this->material_;
93    }
94
95    void HsW01::setDelay(float d)
96    {
97        this->delay_ = d;
98        this->delayTimer_.setInterval(this->delay_);
99    }
100
101    float HsW01::getDelay() const
102    {
103        return this->delay_;
104    }
105
106    void HsW01::fire()
107    {
108        this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->attach(this->defSndWpnFire_);
109        this->defSndWpnFire_->play();
110
111        this->delayTimer_.startTimer();
112
113        //this->defSndWpnFire_->stop();
114    }
115
116    void HsW01::muendungsfeuer()
117    {
118        MuzzleFlash *muzzleFlash = new MuzzleFlash(this);
119        this->getWeapon()->attach(muzzleFlash);
120        muzzleFlash->setPosition(this->getMuzzleOffset());
121        muzzleFlash->setMaterial(this->material_);
122    }
123
124    void HsW01::shot()
125    {
126        assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() );
127        Projectile* projectile = new Projectile(this);
128        Model* model = new Model(projectile);
129        model->setMeshSource("laserbeam.mesh");
130        model->setCastShadows(false);
131        projectile->attach(model);
132        model->setScale(5);
133
134        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
135        projectile->setOrientation(this->getMuzzleOrientation());
136        projectile->setPosition(this->getMuzzlePosition());
137        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
138
139        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
140        projectile->setDamage(this->getDamage());
141
142        HsW01::muendungsfeuer();
143    }
144
145    void HsW01::setDefaultSound(const std::string& soundPath)
146    {
147        this->defSndWpnFire_->setSource(soundPath);
148    }
149
150    const std::string& HsW01::getDefaultSound()
151    {
152        return this->defSndWpnFire_->getSource();
153    }
154}
Note: See TracBrowser for help on using the repository browser.