Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc @ 2494

Last change on this file since 2494 was 2494, checked in by landauf, 15 years ago

shooting, hitting and killing works

  • Property svn:eol-style set to native
File size: 3.8 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Projectile.h"
31
32#include <OgreBillboard.h>
33
34#include "core/CoreIncludes.h"
35#include "core/Executor.h"
36#include "core/ConfigValueIncludes.h"
37#include "core/Iterator.h"
38#include "tools/ParticleInterface.h"
39
40#include "objects/worldentities/Model.h"
41#include "objects/worldentities/ParticleSpawner.h"
42#include "objects/worldentities/pawns/Pawn.h"
43#include "objects/collisionshapes/SphereCollisionShape.h"
44#include "core/Core.h"
45
46namespace orxonox
47{
48    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator)
49    {
50        RegisterObject(Projectile);
51
52        this->setConfigValues();
53        this->bDestroy_ = false;
54        this->owner_ = 0;
55
56        // Get notification about collisions
57        this->enableCollisionCallback();
58
59        this->setCollisionType(Kinematic);
60
61        SphereCollisionShape* shape = new SphereCollisionShape(this);
62        shape->setRadius(10);
63        this->attachCollisionShape(shape);
64
65        if(!Core::isClient()) //only if not on client
66          this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
67    }
68
69    Projectile::~Projectile()
70    {
71    }
72
73    void Projectile::setConfigValues()
74    {
75        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
76        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
77    }
78
79
80    void Projectile::tick(float dt)
81    {
82        SUPER(Projectile, tick, dt);
83
84        if (!this->isActive())
85            return;
86
87        if (this->bDestroy_)
88            delete this;
89    }
90
91    void Projectile::destroyObject()
92    {
93        delete this;
94    }
95
96    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
97    {
98        if (!this->bDestroy_)
99        {
100            this->bDestroy_ = true;
101            Pawn* victim = dynamic_cast<Pawn*>(otherObject);
102            if (victim)
103                victim->damage(this->damage_, this->owner_);
104
105
106            if (this->owner_)
107            {
108                {
109                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
110                    effect->setPosition(this->getPosition());
111                    effect->setOrientation(this->getOrientation());
112                    effect->setDestroyAfterLife(true);
113                    effect->setSource("Orxonox/explosion3");
114                    effect->setLifetime(2.0f);
115                }
116                {
117                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
118                    effect->setPosition(this->getPosition());
119                    effect->setOrientation(this->getOrientation());
120                    effect->setDestroyAfterLife(true);
121                    effect->setSource("Orxonox/smoke4");
122                    effect->setLifetime(3.0f);
123                }
124            }
125        }
126        return false;
127    }
128}
Note: See TracBrowser for help on using the repository browser.