Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 19, 2008, 4:06:51 PM (16 years ago)
Author:
dsommer
Message:

Turbo funktioniert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc

    r2202 r2227  
    11#include "PickupSpawner.h"
     2#include "Item.h"
     3#include "objects/worldentities/pawns/Pawn.h"
     4#include "objects/worldentities/triggers/DistanceTrigger.h"
    25#include "core/CoreIncludes.h"
     6#include "core/XMLPort.h"
    37#include "core/Template.h"
    48
     
    1216
    1317        this->template_ = 0;
     18        this->distance_ = 50;
     19}
     20
     21PickupSpawner::~PickupSpawner()
     22{
     23}
     24
     25void PickupSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     26{
     27        SUPER(PickupSpawner, XMLPort, xmlelement, mode);
     28
     29        XMLPortParam(PickupSpawner, "item", setItemTemplate, getItemTemplate, xmlelement, mode);
     30        XMLPortParam(PickupSpawner, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(50.0f);
     31}
     32
     33void PickupSpawner::tick(float dt)
     34{
     35  if (this->isActive())
     36  {
     37    for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     38    {
     39      Vector3 distanceVec = it->getWorldPosition() - this->getWorldPosition();
     40      if (distanceVec.length() < this->distance_)
     41        this->triggering(*it);
     42    }
     43  }
    1444}
    1545
     
    2050}
    2151
    22     void PickupSpawner::processEvent(Event& event)
    23     {
    24         SUPER(PickupSpawner, processEvent, event);
    25 
    26         SetSubclassEvent(PickupSpawner, "pickup", triggering, event, DistanceTrigger);
    27     }
    28 
    29 void activateSpawner(bool active)
     52void PickupSpawner::triggering(Pawn* player)
     53{
     54        if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier())
    3055        {
    31         if active=true
    32         this->isActive =true;
    33         else
    34         this->isActive = false;
    35         }
    36 
    37 void triggering(bool active, DistanceTrigger* trigger)
    38 {
    39         if (active= true && this->template_ && this->template_->getBaseclassIdentifier())
    40         {
    41                 Pawn* player = trigger->getPlayer(); // getPlayer muss noch implementiert werden
    42                 if(player->isA(itemtemplate_->getPlayerBaseClass()))
     56                COUT(0) << "activated" << std::endl;
     57                //if(player->isA(itemtemplate_->getPlayerBaseClass()))
    4358                {
    44                 BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate();
     59                BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this);
    4560                Item* newitem = dynamic_cast<Item*>(newobject);
    4661                if (newitem)
    47                 newitem->addTemplate(this->itemtemplate_);
    48                 newitem->pickedUp(player);
     62                {
     63                        newitem->addTemplate(this->itemtemplate_);
     64                        if (newitem->pickedUp(player)== true)
     65                                this->setActive(false);
     66                        else
     67                                delete newobject;
    4968                }
    50                 else
    51                         delete newobject;
    52                 activateSpawner(false);
     69                }
     70                //else
     71                //      delete newobject;
    5372        }
    5473}
Note: See TracChangeset for help on using the changeset viewer.