Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/Projectile.cc @ 650

Last change on this file since 650 was 646, checked in by landauf, 17 years ago
  • added very bad collision detection (presentation hack :D)
  • added explosions
  • fixed bug in ParticleInterface (it tried to delete SceneManager)

AND:

  • fixed one of the most amazing bugs ever! (the game crashed when I deleted an object through a timer-function. because the timer-functions is called by an iterator, the iterator indirectly delted its object. by overloading the (it++) operator, i was able to solve this problem)
File size: 1.7 KB
Line 
1#include "Projectile.h"
2#include "../core/CoreIncludes.h"
3#include "Explosion.h"
4#include "Model.h"
5
6namespace orxonox
7{
8    CreateFactory(Projectile);
9
10    Projectile::Projectile(SpaceShip* owner)
11    {
12        RegisterObject(Projectile);
13
14        this->owner_ = owner;
15
16        SetConfigValue(lifetime_, 10.0);
17        SetConfigValue(speed_, 2000.0);
18
19        this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
20        this->attachObject(this->billboard_.getBillboardSet());
21        this->scale(0.5);
22
23        if (this->owner_)
24        {
25            this->setStatic(false);
26            this->setOrientation(this->owner_->getOrientation());
27            this->setPosition(this->owner_->getPosition());
28            this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
29            this->setVelocity(Vector3(1, 0, 0) * this->speed_);
30        }
31
32        this->destroyTimer_.setTimer(this->lifetime_, false, this, &Projectile::destroyObject);
33    }
34
35    Projectile::~Projectile()
36    {
37    }
38
39    void Projectile::tick(float dt)
40    {
41        WorldEntity::tick(dt);
42
43        float radius;
44        for (Iterator<Model> it = ObjectList<Model>::start(); it; ++it)
45        {
46            if ((*it) != this->owner_)
47            {
48                radius = it->getScale().x * 3.0;
49
50                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
51                {
52                    Explosion* eplosion = new Explosion(this);
53                    delete this;
54                    return;
55                }
56            }
57        }
58    }
59
60    void Projectile::destroyObject()
61    {
62        delete this;
63    }
64}
Note: See TracBrowser for help on using the repository browser.