Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapons/src/orxonox/objects/weaponsystem/weaponmodes/HsW01.cc @ 2979

Last change on this file since 2979 was 2979, checked in by Hagen, 15 years ago

working laser style weapon with muzzleflash

File size: 3.5 KB
RevLine 
[2912]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:
[2979]23 *      Hagen Seifert
[2912]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "HsW01.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
[2979]34#include "objects/weaponsystem/projectiles/ParticleProjectile.h"
35#include "objects/worldentities/Model.h"
36#include "objects/worldentities/MuzzleFlash.h"
[2912]37
[2979]38#include "objects/weaponsystem/Weapon.h"
39#include "objects/weaponsystem/WeaponPack.h"
40#include "objects/weaponsystem/WeaponSystem.h"
41
[2912]42namespace orxonox
43{
44    CreateFactory(HsW01);
45
[2979]46    HsW01::HsW01(BaseObject* creator) : WeaponMode(creator)
[2912]47    {
48        RegisterObject(HsW01);
49
[2979]50        this->reloadTime_ = 0.25;
51        this->damage_ = 15;
52        this->speed_ = 2500;
53        this->delay_ = 0;
54        this->setMunitionName("HsW01");
[2912]55
[2979]56        this->delayTimer_.setTimer(1.0f, false, this, createExecutor(createFunctor(&HsW01::shot)));
57        this->delayTimer_.stopTimer();
[2912]58    }
59
[2979]60    void HsW01::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[2912]61    {
[2979]62        SUPER(HsW01, XMLPort, xmlelement, mode);
63
64        XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode);
65        XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode);
66
[2912]67    }
68
[2979]69    void HsW01::setMaterial(const std::string& material)
[2912]70    {
[2979]71        this->material_ = material;
[2912]72    }
73
[2979]74    std::string& HsW01::getMaterial()
[2912]75    {
[2979]76        return this->material_;
[2912]77    }
78
[2979]79    void HsW01::setDelay(float d)
[2912]80    {
[2979]81        this->delay_ = d;
82        this->delayTimer_.setInterval(this->delay_);
[2912]83    }
84
[2979]85    float HsW01::getDelay() const
[2912]86    {
[2979]87        return this->delay_;
[2912]88    }
89
[2979]90    void HsW01::fire()
[2912]91    {
[2979]92        this->delayTimer_.startTimer();
[2912]93    }
[2979]94
95    void HsW01::muendungsfeuer()
96    {
97        MuzzleFlash *muzzleFlash = new MuzzleFlash(this);
98        this->getWeapon()->attach(muzzleFlash);
99        muzzleFlash->setPosition(this->getMuzzleOffset());
100        muzzleFlash->setMaterial(this->material_);
101    }
102
103    void HsW01::shot()
104    {
105        Projectile* projectile = new Projectile(this);
106        Model* model = new Model(projectile);
107        model->setMeshSource("laserbeam.mesh");
108        model->setCastShadows(false);
109        projectile->attach(model);
110        model->setScale(5);
111
112        projectile->setOrientation(this->getMuzzleOrientation());
113        projectile->setPosition(this->getMuzzlePosition());
114        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
115
116        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
117        projectile->setDamage(this->getDamage());
118
119        HsW01::muendungsfeuer();
120    }
[2912]121}
Note: See TracBrowser for help on using the repository browser.