Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/objects/Projectile.cc @ 1454

Last change on this file since 1454 was 1454, checked in by landauf, 16 years ago

fixed tcl initialisation bug

File size: 3.4 KB
RevLine 
[670]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[670]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
[1454]29#include <OgreBillboard.h>
30
[786]31#include "OrxonoxStableHeaders.h"
[1039]32#include "Projectile.h"
[784]33
[1052]34#include "core/CoreIncludes.h"
35#include "core/Executor.h"
36#include "core/ConfigValueIncludes.h"
37
[708]38#include "SpaceShip.h"
[646]39#include "Explosion.h"
40#include "Model.h"
[643]41
42namespace orxonox
43{
44    CreateFactory(Projectile);
45
[1454]46    float Projectile::speed_ = 0;
47
[1293]48    Projectile::Projectile(SpaceShip* owner) :
49      owner_(owner)
[643]50    {
51        RegisterObject(Projectile);
52
[697]53        this->setConfigValues();
54
[643]55        this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
56        this->attachObject(this->billboard_.getBillboardSet());
57        this->scale(0.5);
58
59        if (this->owner_)
60        {
61            this->setStatic(false);
62            this->setOrientation(this->owner_->getOrientation());
63            this->setPosition(this->owner_->getPosition());
[644]64            this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
[643]65            this->setVelocity(Vector3(1, 0, 0) * this->speed_);
66        }
67
[1052]68        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
[1360]69//        COUT(3) << this->classID << std::endl;
[643]70    }
71
72    Projectile::~Projectile()
73    {
74    }
75
[697]76    void Projectile::setConfigValues()
77    {
[706]78        SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive");
79        SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second");
[1052]80
81        this->setVelocity(Vector3(1, 0, 0) * this->speed_);
[697]82    }
83
[646]84    void Projectile::tick(float dt)
85    {
86        WorldEntity::tick(dt);
87
88        float radius;
89        for (Iterator<Model> it = ObjectList<Model>::start(); it; ++it)
90        {
91            if ((*it) != this->owner_)
92            {
93                radius = it->getScale().x * 3.0;
94
95                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
96                {
[1425]97                    Explosion *exp = new Explosion(this);
98                    exp->create();
[646]99                    delete this;
100                    return;
101                }
102            }
103        }
104    }
105
[643]106    void Projectile::destroyObject()
107    {
108        delete this;
109    }
[1454]110
111    void Projectile::setColour(const ColourValue& colour)
112    {
113        this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
114    }
[643]115}
Note: See TracBrowser for help on using the repository browser.