- Timestamp:
- Nov 19, 2008, 4:06:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/objects/pickup/Turbo.cc
r2202 r2227 1 #include "Turbo.h" 2 3 #include "objects/worldentities/pawns/SpaceShip.h" 1 4 #include "core/Executor.h" 5 #include "core/CoreIncludes.h" 6 #include "core/XMLPort.h" 2 7 3 8 namespace orxonox 4 9 { 10 5 11 6 bool pickedUp(Pawn* player) 12 CreateFactory(Turbo); 13 14 Turbo::Turbo(BaseObject* creator) : Item(creator) 7 15 { 8 if(player-> isA(playerBaseClass)) 16 RegisterObject(Turbo); 17 18 this->boost_ = 0; 19 this->duration_ = 0; 20 this->accboost_ = 1; 21 } 22 23 Turbo::~Turbo() 24 { 25 } 26 27 void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode) 28 { 29 SUPER(Turbo, XMLPort, xmlelement, mode); 30 31 XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode); 32 XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode); 33 XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode); 34 } 35 36 bool Turbo::pickedUp(Pawn* player) 37 { 38 if(player-> isA(this->getPlayerBaseClass())) 9 39 { 10 Spaceship* ship = dynamic_cast <SpaceShip*>(player); 11 setSpeedBoost(this->boost, this->duration, Spaceship* ship) 40 SpaceShip* ship = dynamic_cast <SpaceShip*>(player); 41 this->setSpeedBoost(ship); 42 if(duration_==0) 43 addTo(player); 12 44 return true; 13 45 } … … 17 49 18 50 19 void unsetSpeedBoost(int boost, Spaceship* ship)51 void Turbo::unsetSpeedBoost(SpaceShip* ship) 20 52 { 21 ship->setMaxSpeed( ship->getMaxSpeed() - boost); 22 ship->setTransAcc( ship->getTransAcc()/ACCBOOST); 53 ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_); 54 ship->setTransAcc( ship->getTransAcc()/this->accboost_); 55 COUT(3)<<"PickUp Timer expired"<<std::endl; 23 56 } 24 57 25 void setSpeedBoost(float boost, float duration, Spaceship* ship)58 void Turbo::setSpeedBoost(SpaceShip* ship) 26 59 { 27 const float ACCBOOST =1.5 28 ship->setMaxSpeed( ship->getMaxSpeed() + boost); 29 ship->setTransAcc( ship->getTransAcc()*ACCBOOST); 30 31 turbotimer_.setTimer(duration, false, this, createExecutor(createFunctor(&Turbo::unsetSpeedBoost))) 60 ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_); 61 ship->setTransAcc( ship->getTransAcc()*this->accboost_); 62 if( this->duration_ != 0) 63 { 64 ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost)); 65 executor->setDefaultValues(ship); 66 turbotimer_.setTimer(this->duration_, false, this, executor); 67 } 32 68 33 69 } 34 70 bool Turbo::dropped(Pawn* player) 71 { 72 if (this->duration_ == 0) 73 { 74 //player->Equipment.erase ( std::pair<std::string, Item*>(this->itemname,this) ); 75 SpaceShip* ship = dynamic_cast <SpaceShip*>(player); 76 this->unsetSpeedBoost(ship); 77 } 78 return true; 79 } 35 80 36 81 } 82 /*<Template baseclass="Turbo" name=turboitem> 83 <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 /> 84 </Template> 85 86 <PickupSpawner item=turboitem> 87 <attached> 88 <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" /> 89 </attached> 90 </PickupSpawner>*/ 91 37 92 38 93 39 94 40 95 41
Note: See TracChangeset
for help on using the changeset viewer.