Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Boxhead_FS19/src/modules/weapons/weaponmodes/HoverGun.cc @ 12394

Last change on this file since 12394 was 12284, checked in by cwaupoti, 6 years ago

added working HoverGun

File size: 4.5 KB
RevLine 
[12262]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:
[12284]23 *      Hagen Seifert
[12262]24 *   Co-authors:
25 *      simonmie
26 *
27 */
28
29/**
[12273]30    @file HoverGun.h
31    @brief Implementation of the HoverGun class.
[12262]32*/
33
34#include "HoverGun.h"
35
36#include "core/CoreIncludes.h"
[12284]37#include "core/XMLPort.h"
38#include "core/command/Executor.h"
39
40#include "graphics/Model.h"
[12262]41#include "weaponsystem/Weapon.h"
42#include "weaponsystem/WeaponPack.h"
43#include "weaponsystem/WeaponSystem.h"
[12284]44#include "worldentities/WorldEntity.h"
[12262]45#include "worldentities/pawns/Pawn.h"
46
47#include "weapons/projectiles/HoverGunProjectile.h"
[12284]48#include "weapons/MuzzleFlash.h"
[12262]49
50namespace orxonox
51{
52    RegisterClass(HoverGun);
53
54    HoverGun::HoverGun(Context* context) : WeaponMode(context)
55    {
56        RegisterObject(HoverGun);
57
[12284]58        this->reloadTime_ = 0.25f;
59        this->damage_ = 0.0f; //default 15
[12262]60        this->speed_ = 750.0f;
[12284]61        this->delay_ = 0.0f;
62        this->setMunitionName("LaserMunition");
63        this->mesh_ = "laserbeam.mesh";
[12262]64
65
[12284]66        this->delayTimer_.setTimer(this->delay_, false, createExecutor(createFunctor(&HoverGun::shot, this)));
67        this->delayTimer_.stopTimer();
68
69        this->setFireSound("sounds/Weapon_HsW01.ogg");
70        this->setReloadSound("sounds/Reload_HsW01.ogg", 0.5);
71
72        hudImageString_ = "Orxonox/WSHUD_WM_HsW01";
[12262]73    }
74
75    HoverGun::~HoverGun()
76    {
77    }
78
[12284]79    void HoverGun::XMLPort(Element& xmlelement, XMLPort::Mode mode)
80    {
81        SUPER(HoverGun, XMLPort, xmlelement, mode);
82
83        XMLPortParam(HoverGun, "delay", setDelay, getDelay, xmlelement, mode);
84        XMLPortParam(HoverGun, "material", setMaterial, getMaterial, xmlelement, mode);
85        XMLPortParam(HoverGun, "projectileMesh", setMesh, getMesh, xmlelement, mode);
86        XMLPortParam(HoverGun, "sound", setSound, getSound, xmlelement, mode);
87    }
88
[12262]89    /**
90    @brief
[12284]91        Set the firing delay.
92    @param delay
93        The firing delay in seconds.
[12262]94    */
[12284]95    void HoverGun::setDelay(float delay)
96    {
97        this->delay_ = delay;
98        this->delayTimer_.setInterval(this->delay_);
99    }
100
[12262]101    void HoverGun::fire()
102    {
[12284]103        this->delayTimer_.startTimer();
104    }
105
106    /**
107    @brief
108        Fires the weapon. Creates a projectile and fires it.
109    */
110    void HoverGun::shot()
111    {
112        assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() );
113
114        // Create the projectile.
[12262]115        HoverGunProjectile* projectile = new HoverGunProjectile(this->getContext());
[12284]116        Model* model = new Model(projectile->getContext());
117        model->setMeshSource(mesh_);
118        model->setCastShadows(false);
119        projectile->attach(model);
120        model->setScale(5);
[12262]121
122        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
123        projectile->setOrientation(this->getMuzzleOrientation());
124        projectile->setPosition(this->getMuzzlePosition());
125        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
126
127        projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
128        projectile->setDamage(this->getDamage());
129        projectile->setShieldDamage(this->getShieldDamage());
130        projectile->setHealthDamage(this->getHealthDamage());
[12284]131
132        // Display the muzzle flash.
133        this->HoverGun::muzzleflash();
[12262]134    }
[12284]135
136    /**
137    @brief
138        Displays the muzzle flash.
139    */
140    void HoverGun::muzzleflash()
141    {
142        MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext());
143        this->getWeapon()->attach(muzzleFlash);
144        muzzleFlash->setPosition(this->getMuzzleOffset());
145        muzzleFlash->setMaterial(this->material_);
146    }
[12262]147}
Note: See TracBrowser for help on using the repository browser.