Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/weaponmodes/EnergyDrink.cc @ 12226

Last change on this file since 12226 was 11108, checked in by fvultier, 9 years ago

A few modifications in the weapon system: WeaponModes may play a reload sound now. Fireing Sounds of WeaponModes may overlap now. New weapon: FlameGun, a flame thrower for close combat (e.g. for the FPS player)

  • Property svn:eol-style set to native
File size: 4.4 KB
RevLine 
[3053]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:
[8706]25 *      simonmie
[3053]26 *
27 */
28
[8855]29/**
30    @file EnergyDrink.h
31    @brief Implementation of the EnergyDrink class.
32*/
33
[3053]34#include "EnergyDrink.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
[7284]38#include "core/command/Executor.h"
[8855]39
[5737]40#include "graphics/Model.h"
[5735]41#include "weaponsystem/Weapon.h"
42#include "weaponsystem/WeaponPack.h"
43#include "weaponsystem/WeaponSystem.h"
[6732]44#include "worldentities/pawns/Pawn.h"
[3053]45
[8855]46#include "weapons/projectiles/Projectile.h"
47#include "weapons/MuzzleFlash.h"
48
[3053]49namespace orxonox
50{
[9667]51    RegisterClass(EnergyDrink);
[3053]52
[9667]53    EnergyDrink::EnergyDrink(Context* context) : WeaponMode(context)
[3053]54    {
55        RegisterObject(EnergyDrink);
56
[8855]57        this->reloadTime_ = 0.25f;
58        this->damage_ = 0.0f;
[10294]59        this->speed_ = 750.0f;
[8855]60        this->delay_ = 0.0f;
[11108]61        this->timerStarted_ = false;
[3053]62        this->setMunitionName("FusionMunition");
[11108]63        this->setFireSound("sounds/Weapon_EnergyDrink.ogg");
[3053]64
[5929]65        this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&EnergyDrink::shot, this)));
[3053]66        this->delayTimer_.stopTimer();
[11052]67
68        hudImageString_ = "Orxonox/WSHUD_WM_EnergyDrink";
[3053]69    }
70
71    void EnergyDrink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
72    {
73        SUPER(EnergyDrink, XMLPort, xmlelement, mode);
74
75        XMLPortParam(EnergyDrink, "delay", setDelay, getDelay, xmlelement, mode);
76        XMLPortParam(EnergyDrink, "material", setMaterial, getMaterial, xmlelement, mode);
77    }
78
[8855]79    /**
80    @brief
81        Sets the delay with which is fired.
82    @param delay
83        The delay in seconds.
84    */
85    void EnergyDrink::setDelay(float delay)
[3053]86    {
[8855]87        this->delay_ = delay;
[3053]88        this->delayTimer_.setInterval(this->delay_);
89    }
90
[8855]91    /**
92    @brief
93        Fires the weapon.
94    */
[3053]95    void EnergyDrink::fire()
96    {
[11108]97        if (!timerStarted_)
98        {
99            this->delayTimer_.startTimer();
100            this->timerStarted_ = true;
101        }
[3053]102    }
103
[11108]104    bool EnergyDrink::fire(float* reloadTime)
105    {
106        if (!timerStarted_)
107        {
108            return WeaponMode::fire(reloadTime);
109        }
110
111        return false;
112    }
113
[8855]114    /**
115    @brief
116        Executes the shot, be creating the projectile and sending it on its way.
117    */
[3053]118    void EnergyDrink::shot()
119    {
[11108]120        this->timerStarted_ = false;
121
[8855]122        // Create the projectile
[9667]123        Projectile* projectile = new Projectile(this->getContext());
124        Model* model = new Model(projectile->getContext());
[3053]125        model->setMeshSource("can.mesh");
126        model->setCastShadows(false);
127        projectile->attach(model);
128        model->setScale(5);
129
[10622]130        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
[3053]131        projectile->setOrientation(this->getMuzzleOrientation());
132        projectile->setPosition(this->getMuzzlePosition());
[10296]133        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
[3053]134
[8855]135        projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
[3053]136        projectile->setDamage(this->getDamage());
[8706]137        projectile->setShieldDamage(this->getShieldDamage());
138        projectile->setHealthDamage(this->getHealthDamage());
[3053]139
[8855]140        // Display a muzzle flash.
141        this->muzzleflash();
[3053]142    }
[8855]143
144    /**
145    @brief
146        Displays a muzzle flash.
147    */
148    void EnergyDrink::muzzleflash()
149    {
[9667]150        MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext());
[8855]151        this->getWeapon()->attach(muzzleFlash);
152        muzzleFlash->setPosition(this->getMuzzleOffset());
153        muzzleFlash->setMaterial(this->material_);
154    }
[3053]155}
Note: See TracBrowser for help on using the repository browser.