- Timestamp:
- Nov 19, 2008, 4:06:51 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc
r2202 r2227 1 1 #include "PickupSpawner.h" 2 #include "Item.h" 3 #include "objects/worldentities/pawns/Pawn.h" 4 #include "objects/worldentities/triggers/DistanceTrigger.h" 2 5 #include "core/CoreIncludes.h" 6 #include "core/XMLPort.h" 3 7 #include "core/Template.h" 4 8 … … 12 16 13 17 this->template_ = 0; 18 this->distance_ = 50; 19 } 20 21 PickupSpawner::~PickupSpawner() 22 { 23 } 24 25 void 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 33 void 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 } 14 44 } 15 45 … … 20 50 } 21 51 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) 52 void PickupSpawner::triggering(Pawn* player) 53 { 54 if (this->isActive() && this->template_ && this->template_->getBaseclassIdentifier()) 30 55 { 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())) 43 58 { 44 BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate( );59 BaseObject* newobject = this->template_->getBaseclassIdentifier()->fabricate(this); 45 60 Item* newitem = dynamic_cast<Item*>(newobject); 46 61 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; 49 68 } 50 else51 delete newobject;52 activateSpawner(false);69 } 70 //else 71 // delete newobject; 53 72 } 54 73 }
Note: See TracChangeset
for help on using the changeset viewer.