Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/Turbo.cc @ 2389

Last change on this file since 2389 was 2389, checked in by dsommer, 15 years ago

funktioniert :)

File size: 2.8 KB
Line 
1#include "Turbo.h"
2
3#include "objects/worldentities/pawns/SpaceShip.h"
4#include "core/Executor.h"
5#include "core/CoreIncludes.h"
6#include "core/XMLPort.h"
7
8namespace orxonox
9{
10       
11
12        CreateFactory(Turbo);
13
14        Turbo::Turbo(BaseObject* creator) : Item(creator)
15        {
16                RegisterObject(Turbo);
17
18                this->boost_ = 0;
19                this->duration_ = 0;
20                this->accboost_ = 1;
21                this->rotacc_= 0;
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);
35        XMLPortParam(Turbo, "rotacc", setRotAcc, getRotAcc, xmlelement, mode);
36       
37    }
38
39        bool Turbo::pickedUp(Pawn* player)
40        {
41               
42                if(player-> isA(this->getPlayerBaseClass()))
43                        {
44                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
45                        COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
46                        if(duration_==0 )
47                        {       if(addTo(player))
48                                        {       
49                                                COUT(3)<<"ITEM EQUIPPED"<<std::endl;
50                                                this->setSpeedBoost(ship);
51                                                COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
52                                                return true;
53                                        }
54                        }
55                        else
56                        {
57                                this->setSpeedBoost(ship);
58                                COUT(3)<<"Speed:"<< ship->getMaxSpeed()<<std::endl;
59                                return true;
60                        }
61                        return false;
62                        }
63                return false;
64
65        }
66       
67       
68        void Turbo::unsetSpeedBoost(SpaceShip* ship)
69        {
70        ship->setMaxSpeed( ship->getMaxSpeed() - this->boost_);
71        ship->setTransAcc( ship->getTransAcc()/this->accboost_);
72        ship->setMaxRotation( ship->getMaxRotation()-this->rotacc_);
73        ship->setRotAcc( ship->getRotAcc()-this->rotacc_);
74        COUT(3)<<"BOOST UNSET"<<std::endl;
75        }
76
77        void Turbo::setSpeedBoost(SpaceShip* ship)
78        {
79        ship->setMaxSpeed( ship->getMaxSpeed() + this->boost_);
80        ship->setTransAcc( ship->getTransAcc()*this->accboost_);
81        ship->setMaxRotation( ship->getMaxRotation()+this->rotacc_);
82        ship->setRotAcc( ship->getRotAcc()+this->rotacc_);
83        if( this->duration_ != 0)
84        {
85                ExecutorMember<Turbo>* executor = createExecutor(createFunctor(&Turbo::unsetSpeedBoost));
86                executor->setDefaultValues(ship);
87                turbotimer_.setTimer(this->duration_, false, this, executor);
88        }
89       
90        }
91        bool Turbo::dropped(Pawn* player)
92        {
93                if (this->duration_ == 0)
94                {
95                        COUT(0) << "ITEM DROPPED" << std::endl;
96                        if(remove(player)==true);
97                        {
98                        SpaceShip* ship = dynamic_cast <SpaceShip*>(player);
99                        this->unsetSpeedBoost(ship);
100                        }       
101                }
102                return true;
103        }
104       
105}
106/*<Template baseclass="Turbo" name=turboitem>
107      <Turbo playerclass="SpaceShip" boost=150 duration=10 accboost=10 />
108    </Template>
109
110    <PickupSpawner item=turboitem>
111      <attached>
112        <Billboard material="Examples/Flare" scale=0.2 colour="0.0, 0.0, 1.0, 1.0" />
113      </attached>
114    </PickupSpawner>*/
115
116       
117       
118       
119       
Note: See TracBrowser for help on using the repository browser.