Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Turbo funktioniert

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"
    14#include "core/Executor.h"
     5#include "core/CoreIncludes.h"
     6#include "core/XMLPort.h"
    27
    38namespace orxonox
    49{
     10       
    511
    6         bool pickedUp(Pawn* player)
     12        CreateFactory(Turbo);
     13
     14        Turbo::Turbo(BaseObject* creator) : Item(creator)
    715        {
    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()))
    939                        {
    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);
    1244                        return true;
    1345                        }
     
    1749       
    1850       
    19         void unsetSpeedBoost(int boost, Spaceship* ship)
     51        void Turbo::unsetSpeedBoost(SpaceShip* ship)
    2052        {
    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;
    2356        }
    2457
    25         void setSpeedBoost(float boost, float duration, Spaceship* ship)
     58        void Turbo::setSpeedBoost(SpaceShip* ship)
    2659        {
    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        }
    3268       
    3369        }
    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        }
    3580       
    3681}
     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
    3792       
    3893       
    3994       
    4095       
    41        
Note: See TracChangeset for help on using the changeset viewer.