Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/objects/pickup/Turbo.cc @ 2501

Last change on this file since 2501 was 2500, checked in by landauf, 17 years ago

merged pickups2 to presentation

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[2227]1#include "Turbo.h"
2
3#include "objects/worldentities/pawns/SpaceShip.h"
[2202]4#include "core/Executor.h"
[2227]5#include "core/CoreIncludes.h"
6#include "core/XMLPort.h"
[2202]7
8namespace orxonox
9{
10
[2500]11
[2227]12        CreateFactory(Turbo);
13
[2500]14        Turbo::Turbo(BaseObject* creator) : BaseItem(creator)
[2202]15        {
[2227]16                RegisterObject(Turbo);
17
18                this->boost_ = 0;
19                this->duration_ = 0;
20                this->accboost_ = 1;
[2289]21                this->rotacc_= 0;
[2227]22        }
23
24        Turbo::~Turbo()
25        {
26        }
27
28    void Turbo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
29    {
30        SUPER(Turbo, XMLPort, xmlelement, mode);
31
32        XMLPortParam(Turbo, "boost", setBoost, getBoost, xmlelement, mode);
33        XMLPortParam(Turbo, "duration", setDuration, getDuration, xmlelement, mode);
34        XMLPortParam(Turbo, "accboost", setAccBoost, getAccBoost, xmlelement, mode);
[2500]35        XMLPortParam(Turbo, "rotacc", setRotAcc, getRotAcc, xmlelement, mode);
[2227]36    }
37
38        bool Turbo::pickedUp(Pawn* player)
39        {
[2500]40
[2227]41                if(player-> isA(this->getPlayerBaseClass()))
[2202]42                        {
[2227]43                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
[2324]44                        if(duration_==0 )
[2500]45                        {
[2397]46                                if(addTo(player))
[2500]47                                {
[2389]48                                                COUT(3)<<"ITEM EQUIPPED"<<std::endl;
[2324]49                                                this->setSpeedBoost(ship);
50                                                return true;
[2397]51                                }
52                                return false;
[2202]53                        }
[2324]54                        else
55                        {
56                                this->setSpeedBoost(ship);
57                                return true;
58                        }
59                        return false;
60                        }
[2202]61                return false;
62
63        }
[2500]64
65
[2227]66        void Turbo::unsetSpeedBoost(SpaceShip* ship)
[2202]67        {
[2500]68/*
[2227]69        ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_);
70        ship->setTransAcc( ship->getTransAcc()/this->accboost_);
[2289]71        ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_);
72        ship->setRotAcc( ship->getRotAcc()-this->rotacc_);
[2389]73        COUT(3)<<"BOOST UNSET"<<std::endl;
[2397]74        COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
[2500]75*/
76        ship->setPermanentBoost(false);
[2202]77        }
78
[2227]79        void Turbo::setSpeedBoost(SpaceShip* ship)
[2202]80        {
[2500]81/*
[2397]82        COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
[2227]83        ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_);
84        ship->setTransAcc( ship->getTransAcc()*this->accboost_);
[2289]85        ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_);
86        ship->setRotAcc( ship->getRotAcc()+this->rotacc_);
[2500]87*/
88    ship->setPermanentBoost(true);
89    ship->setBoost(true);
90
[2227]91        if( this->duration_ != 0)
92        {
93                ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost));
94                executor->setDefaultValues(ship);
95                turbotimer_.setTimer(this->duration_, false, this, executor);
96        }
[2500]97//      COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
[2202]98        }
[2227]99        bool Turbo::dropped(Pawn* player)
100        {
101                if (this->duration_ == 0)
102                {
[2389]103                        COUT(0) << "ITEM DROPPED" << std::endl;
[2289]104                        if(remove(player)==true);
105                        {
[2227]106                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
107                        this->unsetSpeedBoost(ship);
[2500]108                        }
[2227]109                }
110                return true;
111        }
[2500]112
[2202]113}
[2227]114/*<Template baseclass="Turbo" name=turboitem>
115      <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 />
116    </Template>
117
118    <PickupSpawner item=turboitem>
119      <attached>
120        <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" />
121      </attached>
122    </PickupSpawner>*/
123
[2500]124
125
126
127
Note: See TracBrowser for help on using the repository browser.