Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/shader/src/orxonox/objects/Projectile.cc @ 11975

Last change on this file since 11975 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 3.2 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
38#include "SpaceShip.h"
39#include "Explosion.h"
40#include "Model.h"
41
42namespace orxonox
43{
44    CreateFactory(Projectile);
45
46    float Projectile::speed_ = 0;
47
48    Projectile::Projectile(SpaceShip* owner) :
49      owner_(owner)
50    {
51        RegisterObject(Projectile);
52
53        this->setConfigValues();
54
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());
64            this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
65            this->setVelocity(Vector3(1, 0, 0) * this->speed_);
66        }
67
68        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
69//        COUT(3) << this->classID << std::endl;
70    }
71
72    Projectile::~Projectile()
73    {
74    }
75
76    void Projectile::setConfigValues()
77    {
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");
80
81        this->setVelocity(Vector3(1, 0, 0) * this->speed_);
82    }
83
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                {
97                    Explosion *exp = new Explosion(this);
98                    exp->create();
99                    delete this;
100                    return;
101                }
102            }
103        }
104    }
105
106    void Projectile::destroyObject()
107    {
108        delete this;
109    }
110
111    void Projectile::setColour(const ColourValue& colour)
112    {
113        this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
114    }
115}
Note: See TracBrowser for help on using the repository browser.