Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/weapons/weaponmodes/BallGun.cc @ 12378

Last change on this file since 12378 was 12378, checked in by pomselj, 5 years ago

Projectiles survive infinitely

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