Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12305 was 12281, checked in by pomselj, 6 years ago

weapon stuff

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