Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups/src/orxonox/objects/pickup/DroppedItem.cc @ 2961

Last change on this file since 2961 was 2900, checked in by danielh, 16 years ago
  • some changes to the base framework
  • added DroppedItem
  • implemented usable items and a test UsableItem (Jump), console command to use an item is "useItem"
  • added ModifierType::Acceleration
File size: 2.9 KB
RevLine 
[2900]1#include "DroppedItem.h"
2
3#include "BaseItem.h"
4#include "objects/worldentities/pawns/Pawn.h"
5#include "objects/worldentities/Model.h"
6#include "objects/worldentities/Billboard.h"
7
8#include "core/CoreIncludes.h"
9#include "core/Core.h"
10
11namespace orxonox
12{
13    CreateFactory(DroppedItem);
14
15    DroppedItem::DroppedItem(BaseObject* creator) : StaticEntity(creator)
16    {
17        RegisterObject(DroppedItem);
18
19        this->triggerDistance_ = 20.0f;
20        this->timeToLive_ = 0;
21        this->item_ = 0;
22    }
23    DroppedItem::~DroppedItem()
24    {
25    }
26    void DroppedItem::tick(float dt)
27    {
28        if (this->item_)
29        {
30            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); it++)
31            {
32                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
33                if (distance.length() < this->triggerDistance_)
34                    this->trigger(*it);
35            }
36        }
37    }
38    void DroppedItem::trigger(Pawn* pawn)
39    {
40        if (this->item_->pickedUp(pawn))
41        {
42            COUT(3) << "DroppedItem '" << this->item_->getPickupIdentifier() << "' picked up." << std::endl;
43            delete this;
44        }
45    }
46    void DroppedItem::createTimer()
47    {
48        if (this->timeToLive_ > 0)
49        {
50            ExecutorMember<DroppedItem>* exec = createExecutor(createFunctor(&DroppedItem::timerCallback));
51            this->timer_.setTimer(this->timeToLive_, false, this, exec, false);
52        }
53    }
54    void DroppedItem::timerCallback()
55    {
56        if (this->item_)
57            delete this->item_;
58
59        delete this;
60    }
61
62    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
63    {
64        DroppedItem* drop = new DroppedItem(item);
65        Model* model = new Model(item);
66        Billboard* billboard = new Billboard(item);
67       
68        model->setMeshSource("sphere.mesh");
69        model->setScale(3.0f);
70
71        billboard->setMaterial("Examples/Flare");
72        billboard->setColour(flareColour);
73        billboard->setScale(0.5f);
74
75        drop->setPosition(position);
76        drop->attach(model);
77        drop->attach(billboard);
78
79        drop->setItem(item);
80
81        drop->setTimeToLive(timeToLive);
82        drop->createTimer();
83
84        COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl;
85
86        return drop;
87    }
88    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)
89    {
90        Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);
91        return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);
92    }
93}
Note: See TracBrowser for help on using the repository browser.