Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12373 was 12371, checked in by pomselj, 6 years ago

BallProjectiles fly

File size: 4.6 KB
RevLine 
[12281]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
[12371]36
[12281]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
[12371]62        this->speed_ = 50;
63        this->delay_ = 100;
[12281]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        orxout() << "fire" << endl;
107        this->delayTimer_.startTimer();
108    }
109
110    /**
111    @brief
112        Fires the weapon. Creates a projectile and fires it.
113    */
114    void BallGun::shot()
115    {
116        assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() );
117        orxout() << "SHOT!" << endl;
118        // Create the projectile.
119        Projectile* projectile = new BallProjectile(this->getContext());
120        Model* model = new Model(projectile->getContext());
121        model->setMeshSource(mesh_);
122        model->setCastShadows(false);
123        projectile->attach(model);
124        model->setScale(5);
125
126        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
127        projectile->setOrientation(this->getMuzzleOrientation());
128        projectile->setPosition(this->getMuzzlePosition());
129        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
130
131        projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
132        projectile->setDamage(this->getDamage());
133        projectile->setShieldDamage(this->getShieldDamage());
134        projectile->setHealthDamage(this->getHealthDamage());
135
136        // Display the muzzle flash.
137        this->BallGun::muzzleflash();
138    }
139
140    /**
141    @brief
142        Displays the muzzle flash.
143    */
144    void BallGun::muzzleflash()
145    {
146        MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext());
147        this->getWeapon()->attach(muzzleFlash);
148        muzzleFlash->setPosition(this->getMuzzleOffset());
149        muzzleFlash->setMaterial(this->material_);
150    }
151}
Note: See TracBrowser for help on using the repository browser.