Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11859


Ignore:
Timestamp:
Apr 12, 2018, 4:12:25 PM (7 years ago)
Author:
dreherm
Message:

Moving ghosts

Location:
code/branches/3DPacman_FS18/src/modules/Pacman
Files:
2 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/3DPacman_FS18/src/modules/Pacman/3DPacman.cc

    r11844 r11859  
    3434#include "3DPacman.h"
    3535#include "core/CoreIncludes.h"
     36#include "PacmanGelb.h"
     37#include "PacmanGhost.h"
     38#include "PacmanPointSphere.h"
    3639
    3740namespace orxonox
     
    4346        RegisterObject(3DPacman);
    4447
    45         bEndGame = false;
    46         lives = 1;
     48        lives = 3;
     49        point = 0:
    4750        level = 1;
    48         point = 0;
    49         bShowLevel = false;
    50         multiplier = 1;
    51         b_combo = false;
    52         counter = 5000;
    53         pattern = 1;
    54         lastPosition = 0;
    55         // spawn enemy every 3.5 seconds
    56         //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this)));
    57         comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this)));
    58         this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
    59         this->center_ = nullptr;
    6051
    61         this->setHUDTemplate("DodgeRaceHUD");
    6252    }
    6353
    64     void DodgeRace::levelUp()
     54    void 3DPacman::levelUp()
    6555    {
    66         level++;
    67         if (getPlayer() != nullptr)
    68         {
    69             for (int i = 0; i < 7; i++)
    70             {
    71                 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
    72                 chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
    73                 chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
    74                 chunk5->setScale(10);
    75                 chunk5->setEffect1("Orxonox/explosion2b");
    76                 chunk5->setEffect2("Orxonox/smoke6");
    77                 chunk5->Explode();
    78 
    79             }
    80         }
    81         addPoints(multiplier * 42);
    82         multiplier *= 2;
    83         toggleShowLevel();
    84         showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this)));
     56        this->end();
    8557    }
    8658
    87     void DodgeRace::tick(float dt)
     59
     60    PacmanGhost[4] ghosts;
     61    PacmanPointSphere[1] spheres;
     62
     63
     64    void 3DPacman::tick(float dt)
    8865    {
    89         DodgeRaceShip* player = this->getPlayer();
     66        int i = 0;
     67        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
     68            ghosts[i] = nextghost;
     69            i++;
     70        }
     71
     72        i = 0:
     73        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
     74            spheres[i] = nextsphere;
     75            i++;
     76        }
     77
     78        player = this->getPlayer();
    9079        if (player != nullptr)
    9180        {
    92             currentPosition = player->getWorldPosition().x;
    93             counter = counter + (currentPosition - lastPosition);
    94             lastPosition = currentPosition;
    95             point = (int) currentPosition;
    96             player->speed = 830.0f - (point / 1000);
     81            currentPosition = player->getWorldPosition();
     82        }
    9783
    98             for(unsigned int i=0; i < cubeList.size();i++)
    99             {
    100                 if(cubeList.at(i)->getPosition().x < currentPosition-3000)
    101                 {
    102                     cubeList.at(i)->destroy();
    103                     cubeList.erase(cubeList.begin()+i);
    104                 }
    105             }
     84        bool bcolli = false;
     85        for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){
     86            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition)
     87        }
     88        if(collis){
     89            this->catched();
     90        }
    10691
    107             if(counter >= 3000)
    108             {
    109                 counter = 0;
    110                 for(int i = 0; i<6; i++)
    111                 {
    112                     DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext());
    113                     cubeList.push_back(cube);
    114                     switch(pattern)
    115                     {
    116                     case 1: cube->addTemplate("DodgeRaceCube01");
    117                     break;
    118                     case 2: cube->addTemplate("DodgeRaceCube02");
    119                     break;
     92        SUPER(3DPacman, tick, dt);
    12093
    121                     }
    122 
    123                     cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200)));
    124                     //stEntity->setScale3D(50,50,50);
    125                 }
     94    }
    12695
    12796
    128                 pattern %= 2;
    129                 pattern ++;
    13097
    131             }
    132 
    133         }
    134         SUPER(DodgeRace, tick, dt);
     98    bool 3DPacman::collis(Vector3 one, Vector3 other){
     99        if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1))
     100            return true;
     101        return false;
    135102    }
    136103
    137     DodgeRaceShip* DodgeRace::getPlayer()
     104    void 3DPacman::catched(){
     105        if(lives) this->end();
     106        --lives;
     107        this->posreset();
     108    }
     109
     110    void 3DPacman::posreset(){
     111        int i = 0;
     112        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
     113            ghosts[i] = nextghost;
     114            i++;
     115        }
     116       
     117    }
     118
     119
     120    PacmanGelb* 3DPacman::getPlayer()
    138121    {
    139         for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>())
     122        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
    140123        {
    141124            return ship;
     
    144127    }
    145128
    146     void DodgeRace::costLife()
    147     {
    148         //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this)));
    149         lives = 0;
    150     };
    151129
    152     void DodgeRace::comboControll()
    153     {
    154         if (b_combo)
    155             multiplier++;
    156         // if no combo was performed before, reset multiplier
    157         else
    158             multiplier = 1;
    159         b_combo = false;
    160     }
    161 
    162     void DodgeRace::start()
     130    void 3DPacman::start()
    163131    {
    164132        orxout() << "start" << endl;
    165         for(unsigned int i=0; i< cubeList.size();i++)
    166         {
    167             cubeList.at(i)->destroy();
    168             cubeList.erase(cubeList.begin()+i);
    169 
    170         }
    171         cubeList.clear();
    172         // Set variable to temporarily force the player to spawn.
    173         this->bForceSpawn_ = false;
    174 
    175         if (this->center_ == nullptr)  // abandon mission!
    176         {
    177             orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl;
    178             GSLevel::startMainMenu();
    179             return;
    180         }
    181         // Call start for the parent class.
     133       
    182134        Deathmatch::start();
    183135    }
    184136
    185     void DodgeRace::playerPreSpawn(PlayerInfo* player)
     137    void 3DPacman::playerPreSpawn(PlayerInfo* player)
    186138    {
    187139        this->playerInfo_ = player;
     
    190142            this->end();
    191143        }
    192 
    193         // Reset all the cubes
    194         /*
    195         orxout() << "prespawn" << endl;
    196         for(int i=0; i< cubeList.size();i++)
    197         {
    198             cubeList.at(i)->destroy();
    199             cubeList.erase(cubeList.begin()+i);
    200         }
    201         cubeList.clear();
    202         lives = 1;
    203         point = 0;
    204         lastPosition = 0;
    205         */
    206144    }
    207145
    208     void DodgeRace::addPoints(int numPoints)
    209     {
    210         if (!bEndGame)
    211         {
    212             point += numPoints * multiplier;
    213             b_combo = true;
    214         }
    215     }
    216146
    217     void DodgeRace::end()
     147    void 3DPacman::end()
    218148    {
    219149        // DON'T CALL THIS!
     
    224154        {
    225155            int score = this->getPoints();
    226             Highscore::getInstance().storeScore("Dodge Race", score, this->playerInfo_);
     156            Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
    227157        }
    228158        GSLevel::startMainMenu();
  • code/branches/3DPacman_FS18/src/modules/Pacman/3DPacman.h

    r11844 r11859  
    4242
    4343//#include "DodgeRaceHUDinfo.h"
     44#include "PacmanGelb.h"
    4445
    4546
     
    6364{
    6465
    65     class _DodgeRaceExport DodgeRace : public Deathmatch
     66    class _3DPacmanExport 3DPacman : public Deathmatch
    6667    {
    6768       public:
    68             DodgeRace(Context* context);
     69            3DPacman(Context* context);
    6970
    7071            virtual void start() override;
     
    100101
    101102       private:
     103            PacmanGelb* player;
     104            PacmanGhost[]
     105            Vector3 currentPosition;
     106
     107
     108
    102109            Timer endGameTimer;
    103110
  • code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhost.cc

    r11849 r11859  
    4646        RegisterObject(PacmanGhost);
    4747
    48         this->localLinearAcceleration_.setValue(1, 1, 1);
    49         this->localAngularAcceleration_.setValue(1, 1, 1);
    50 
    5148        this->velocity = Vector3(0, 0, 0);
    5249
     
    7976        SUPER(PacmanGhost, XMLPort, xmlelement, mode);
    8077
    81         XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
    82         XMLPortParam(PacmanGhost, "auxiliaryThrust", setAuxiliaryThrust, getAuxiliaryThrust, xmlelement, mode);
    83         XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
    8478        XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode);
    8579    }
     
    8781
    8882   
    89     Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,0,240)};
     83    Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,10,245),Vector3(215,10,220)};
    9084
    9185    /**
     
    9993        SUPER(PacmanGhost, tick, dt);
    10094
    101         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);
    102         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);
    103         if (this->localLinearAcceleration_.z() > 0)
    104             this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);
    105         else
    106             this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    107         this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    108         this->localLinearAcceleration_.setValue(0, 0, 0);
    109 
    110         this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    111         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    112         this->localAngularAcceleration_.setValue(0, 0, 0);
    113 
     95        //setorientation
    11496
    11597        this->actuelposition = this->getPosition();
    11698       
    11799        //Stop, if target arrived
    118         if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){
     100        if((abs(this->actuelposition.x - this->target_x)<0.1) && (abs(this->actuelposition.z - this->target_z)<0.1)){
    119101                 this->ismoving = false;
    120102        }
     
    122104        //Move, if ghost hasn't arrived yet
    123105        if(this->ismoving){
    124             if(!((this->actuelposition.z-target_z)<0.1)) {
    125                 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),-sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));
     106            if(!(abs(this->actuelposition.z-target_z)<0.1)) {
     107                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));
    126108                move(dt, actuelposition, velocity);
    127109            }   
    128             if(!((this->actuelposition.x-target_x)<0.1)){
    129                 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),-sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));
     110            if(!(abs(this->actuelposition.x-target_x)<0.1)){
     111                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));
    130112                move(dt, actuelposition, velocity);
    131113            }
     
    134116        //Check on which position ghost has arrived and set new target
    135117         else{
    136             if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[0].z)<0.1)){
    137                 this->target_x = possibleposition[1].x;
    138                 this->target_z = possibleposition[1].z;
    139                 this->ismoving = true;
     118            if((abs(this->actuelposition.x - possibleposition[0].x)<0.1) && (abs(this->actuelposition.z - possibleposition[0].z)<0.1)){
     119                decision = rand()%1;
     120            switch(decision){
     121                case 0:
     122                    this->target_x = possibleposition[1].x;
     123                    this->target_z = possibleposition[1].z;
     124                    this->ismoving = true;
    140125            }
    141             else if(((actuelposition.x - possibleposition[1].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){
    142                 this->target_x = possibleposition[0].x;
    143                 this->target_z = possibleposition[0].z;
    144                 this->ismoving = true;
     126           
    145127            }
     128            else if((abs(actuelposition.x - possibleposition[1].x)<0.1) && (abs(actuelposition.z - possibleposition[1].z)<0.1)){
     129                decision = rand()%2;
     130            switch(decision){
     131                case 0:
     132                    this->target_x = possibleposition[0].x;
     133                    this->target_z = possibleposition[0].z;
     134                    this->ismoving = true;
     135                    break;
     136                case 1:
     137                    this->target_x = possibleposition[2].x;
     138                    this->target_z = possibleposition[2].z;
     139                    this->ismoving = true;   
     140            }
     141
     142            }
     143            if((abs(this->actuelposition.x - possibleposition[2].x)<0.1) && (abs(this->actuelposition.z - possibleposition[2].z)<0.1)){
     144                decision = rand()%1;
     145            switch(decision){
     146                case 0:
     147                    this->target_x = possibleposition[1].x;
     148                    this->target_z = possibleposition[1].z;
     149                    this->ismoving = true;
     150            }
     151           
     152            }
     153
    146154            else{
    147155            } //End of Position table
     
    151159
    152160
    153 
    154161    void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){
    155 
    156         this->setPosition(Vector3(actuelposition.x+velocity.x*dt,actuelposition.y+velocity.y*dt ,actuelposition.z+velocity.z*dt));
     162        this->setPosition(Vector3(actuelposition.x+20*velocity.x*dt,10,actuelposition.z+20*velocity.z*dt));
    157163    }
    158164
    159 
    160     /**
    161     @brief
    162         Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
    163     @param value
    164         The vector determining the amount of the movement.
    165     */
    166     void PacmanGhost::moveFrontBack(const Vector2& value)
    167     {
    168         //this->setPosition(dt*(actuelposition + velocity_));
     165    void PacmanGhost::resetGhost(){
     166        this->setPosition(resetposition);
    169167    }
    170 
    171     /**
    172     @brief
    173         Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
    174     @param value
    175         The vector determining the amount of the movement.
    176     */
    177     void PacmanGhost::moveRightLeft(const Vector2& value)
    178     {
    179         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    180     }
    181 
    182     /**
    183     @brief
    184         Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
    185     @param value
    186         The vector determining the amount of the movement.
    187     */
    188     void PacmanGhost::moveUpDown(const Vector2& value)
    189     {
    190         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    191     }
    192 
    193     /**
    194     @brief
    195         Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.
    196     @param value
    197         The vector determining the amount of the angular movement.
    198     */
    199     void PacmanGhost::rotateYaw(const Vector2& value)
    200     {
    201         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
    202     }
    203 
    204     /**
    205     @brief
    206         Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.
    207     @param value
    208         The vector determining the amount of the angular movement.
    209     */
    210     void PacmanGhost::rotatePitch(const Vector2& value)
    211     {
    212         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
    213     }
    214 
    215     /**
    216     @brief
    217         Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.
    218     @param value
    219         The vector determining the amount of the angular movement.
    220     */
    221     void PacmanGhost::rotateRoll(const Vector2& value)
    222     {
    223         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
    224     }
    225 
    226168}
  • code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhost.h

    r11850 r11859  
    4747            virtual void tick(float dt); //!< Defines which actions the AutonomousDrone has to take in each tick.
    4848
    49             virtual void moveFrontBack(const Vector2& value);
    50             virtual void moveRightLeft(const Vector2& value);
    51             virtual void moveUpDown(const Vector2& value);
    52 
    53             virtual void rotateYaw(const Vector2& value);
    54             virtual void rotatePitch(const Vector2& value);
    55             virtual void rotateRoll(const Vector2& value);
    56 
    5749            void move(float dt, Vector3 actuelposition, Vector3 velocity);
    5850           
    59             //virtual void resetGhost();
    60             /**
    61             @brief Moves the Drone in the Front/Back-direction by the specifed amount.
    62             @param value  The amount by which the drone is to be moved.
    63             */
    64             inline void moveFrontBack(float value)
    65             { this->moveFrontBack(Vector2(value, 0)); }
    66             /**
    67             @brief Moves the Drone in the Right/Left-direction by the specifed amount.
    68             @param value  The amount by which the drone is to be moved.
    69             */
    70             inline void moveRightLeft(float value)
    71             { this->moveRightLeft(Vector2(value, 0)); }
    72             /**
    73             @brief Moves the Drone in the Up/Down-direction by the specifed amount.
    74             @param value  The amount by which the drone is to be moved.
    75             */
    76             inline void moveUpDown(float value)
    77             { this->moveUpDown(Vector2(value, 0)); }
    78 
    79             /**
    80             @brief Rotates the Drone around the y-axis by the specifed amount.
    81             @param value  The amount by which the drone is to be rotated.
    82             */
    83             inline void rotateYaw(float value)
    84             { this->rotateYaw(Vector2(value, 0)); }
    85             /**
    86             @brief Rotates the Drone around the x-axis by the specifed amount.
    87             @param value  The amount by which the drone is to be rotated.
    88             */
    89             inline void rotatePitch(float value)
    90             { this->rotatePitch(Vector2(value, 0)); }
    91             /**
    92             @brief Rotates the Drone around the z-axis by the specifed amount.
    93             @param value  The amount by which the drone is to be rotated.
    94             */
    95             inline void rotateRoll(float value)
    96             { this->rotateRoll(Vector2(value, 0)); }
    97 
    98             /**
    99             @brief Sets the primary thrust to the input amount.
    100             @param thrust The amount of thrust.
    101             */
    102             inline void setPrimaryThrust( float thrust )
    103                 { this->primaryThrust_ = thrust; }
    104             inline void setAuxiliaryThrust( float thrust )
    105                 { this->auxiliaryThrust_ = thrust; }
    106             inline void setRotationThrust( float thrust )
    107                 { this->rotationThrust_ = thrust; }
     51            void resetGhost();
    10852
    10953            inline void setResetPosition(Vector3 rpos)
    11054                { this->resetposition = rpos; }   
    111      
    112             /**
    113             @brief Gets the primary thrust to the input amount.
    114             @return The amount of thrust.
    115             */
    116             inline float getPrimaryThrust()
    117                 { return this->primaryThrust_; }
    118             inline float getAuxiliaryThrust()
    119                 { return this->auxiliaryThrust_; }
    120             inline float getRotationThrust()
    121                 { return this->rotationThrust_; }
    12255           
    12356            inline Vector3 getResetPosition()
     
    12760
    12861        private:
    129            
    130             btVector3 localLinearAcceleration_; //!< The linear acceleration that is used to move the AutonomousDrone the next tick.
    131             btVector3 localAngularAcceleration_; //!< The linear angular acceleration that is used to move the AutonomousDrone the next tick.
    132             float primaryThrust_=100; //!< The amount of primary thrust. This is just used, when moving forward.
    133             float auxiliaryThrust_=100; //!< The amount of auxilliary thrust. Used for all other movements (except for rotations).
    134             float rotationThrust_=100; //!< The amount of rotation thrust. Used for rotations only.s
    135             //Vector3 resetposition; //Start position for Ghost
    136        
    137             PacmanGhost* myGhost = nullptr;
    138 
    13962            bool ismoving = false;
     63            int decision = 0; //Gives the random which way information to the ghost.
    14064            int target_x = 0;
    14165            int target_z = 0;
  • code/branches/3DPacman_FS18/src/modules/Pacman/PacmanPointSphere.cc

    r11844 r11859  
    2727 */
    2828
    29 #include "PacmanGhost.h"
     29#include "PacmanPointSphere.h"
    3030
    3131#include "core/CoreIncludes.h"
     
    3434namespace orxonox
    3535{
    36     RegisterClass(PacmanGhost);
     36    RegisterClass(PacmanPointSphere);
    3737
    3838    /**
     
    4242        The creator of this object.
    4343    */
    44     PacmanGhost::PacmanGhost(Context* context) : ControllableEntity(context)
     44    PacmanPointSphere::PacmanPointSphere(Context* context) : ControllableEntity(context)
    4545    {
    46         RegisterObject(PacmanGhost);
    47 
    48         this->myController_ = NULL;
    49 
    50         this->localLinearAcceleration_.setValue(0, 0, 0);
    51         this->localAngularAcceleration_.setValue(0, 0, 0);
    52         this->primaryThrust_  = 100;
    53         this->auxiliaryThrust_ = 100;
    54         this->rotationThrust_ = 10;
    55 
    56         this->setCollisionType(CollisionType::Dynamic);
     46        RegisterObject(PacmanPointSphere);
     47        this->setCollisionType(CollisionType::none);
    5748    }
    5849
     
    6152        Destructor. Destroys controller, if present.
    6253    */
    63     PacmanGhost::~PacmanGhost()
     54    PacmanPointSphere::~PacmanPointSphere()
    6455    {
    6556        // Deletes the controller if the object was initialized and the pointer to the controller is not NULL.
    66         if( this->isInitialized() && this->myController_ != NULL )
    67             delete this->myController_;
    6857    }
    6958
     
    7261        Method for creating a AutonomousDrone through XML.
    7362    */
    74     void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     63    void PacmanPointSphere::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7564    {
    76         // This calls the XMLPort function of the parent class
    77         SUPER(PacmanGhost, XMLPort, xmlelement, mode);
     65        SUPER(PacmanPointSphere, XMLPort, xmlelement, mode);
    7866
    79         XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
    80         // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort.
    81         // Variables can be added by the following command
    82         // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode);
    83         // Also make sure that you also create the get- and set-functions in AutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there.
     67        XMLPortParam(PacmanPointSphere, "resetposition", setResetPosition, getResetPosition, xmlelement, mode);
    8468    }
    8569
    86     /**
    87     @brief
    88         Defines which actions the AutonomousDrone has to take in each tick.
    89     @param dt
    90         The length of the tick.
    91     */
    92     void PacmanGhost::tick(float dt)
     70
     71    void PacmanPointSphere::tick(float dt)
    9372    {
    9473        SUPER(PacmanGhost, tick, dt);
    95 
    96         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);
    97         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);
    98         if (this->localLinearAcceleration_.z() > 0)
    99             this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);
    100         else
    101             this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    102         this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    103         this->localLinearAcceleration_.setValue(0, 0, 0);
    104 
    105         this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    106         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    107         this->localAngularAcceleration_.setValue(0, 0, 0);
    108 
    10974    }
    11075
    111     /**
    112     @brief
    113         Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
    114     @param value
    115         The vector determining the amount of the movement.
    116     */
    117     void PacmanGhost::moveFrontBack(const Vector2& value)
     76    bool PacmanPointSphere::taken(Vector3 playerpos)
    11877    {
    119         this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
     78      if((abs(this->resetposition.x - playerpos.x)<0.1) && (abs(this->resetposition.z - playerpos.z)<0.1)){
     79        this->setPosition(Vector3(resetposition.x, -50, resetposition.z));
     80        return true;
     81      }
     82
     83      return false;
    12084    }
    12185
    122     /**
    123     @brief
    124         Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
    125     @param value
    126         The vector determining the amount of the movement.
    127     */
    128     void PacmanGhost::moveRightLeft(const Vector2& value)
    129     {
    130         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
     86
     87    void PacmanPointSphere::resetPacmanPointSphere(){
     88        this->setPosition(resetposition);
    13189    }
    132 
    133     /**
    134     @brief
    135         Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
    136     @param value
    137         The vector determining the amount of the movement.
    138     */
    139     void PacmanGhost::moveUpDown(const Vector2& value)
    140     {
    141         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    142     }
    143 
    144     /**
    145     @brief
    146         Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.
    147     @param value
    148         The vector determining the amount of the angular movement.
    149     */
    150     void PacmanGhost::rotateYaw(const Vector2& value)
    151     {
    152         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
    153     }
    154 
    155     /**
    156     @brief
    157         Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.
    158     @param value
    159         The vector determining the amount of the angular movement.
    160     */
    161     void PacmanGhost::rotatePitch(const Vector2& value)
    162     {
    163         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
    164     }
    165 
    166     /**
    167     @brief
    168         Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.
    169     @param value
    170         The vector determining the amount of the angular movement.
    171     */
    172     void PacmanGhost::rotateRoll(const Vector2& value)
    173     {
    174         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
    175     }
    176 
    17790}
  • code/branches/3DPacman_FS18/src/modules/Pacman/PacmanPointSphere.h

    r11844 r11859  
    2727 */
    2828
    29 #ifndef _PacmanGhost_H__
    30 #define _PacmanGhost_H__
     29#ifndef _PacmanPointSphere_H__
     30#define _PacmanPointSphere_H__
    3131
    3232#include "OrxonoxPrereqs.h"
    3333
    3434#include "core/XMLPort.h"
    35 #include "controllers/PacmanGhostController.h"
    3635
    37 #include "ControllableEntity.h"
     36#include "worldentities/ControllableEntity.h"
    3837
    3938namespace orxonox {
    4039
    41     class _OrxonoxExport PacmanGhost : public ControllableEntity
     40    class _OrxonoxExport PacmanPointSphere : public ControllableEntity
    4241    {
    4342        public:
    44             PacmanGhost(Context* context);
    45             virtual ~PacmanGhost();
     43            PacmanPointSphere(Context* context);
     44            virtual ~PacmanPointSphere();
    4645
    4746            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating an AutonomousDrone through XML.
    4847            virtual void tick(float dt); //!< Defines which actions the AutonomousDrone has to take in each tick.
    4948
    50             virtual void moveFrontBack(const Vector2& value);
    51             virtual void moveRightLeft(const Vector2& value);
    52             virtual void moveUpDown(const Vector2& value);
     49            bool taken(Vector3 playerpos);
     50            void resetPacmanPointSphere();
    5351
    54             virtual void rotateYaw(const Vector2& value);
    55             virtual void rotatePitch(const Vector2& value);
    56             virtual void rotateRoll(const Vector2& value);
    57 
    58             /**
    59             @brief Moves the Drone in the Front/Back-direction by the specifed amount.
    60             @param value  The amount by which the drone is to be moved.
    61             */
    62             inline void moveFrontBack(float value)
    63             { this->moveFrontBack(Vector2(value, 0)); }
    64             /**
    65             @brief Moves the Drone in the Right/Left-direction by the specifed amount.
    66             @param value  The amount by which the drone is to be moved.
    67             */
    68             inline void moveRightLeft(float value)
    69             { this->moveRightLeft(Vector2(value, 0)); }
    70             /**
    71             @brief Moves the Drone in the Up/Down-direction by the specifed amount.
    72             @param value  The amount by which the drone is to be moved.
    73             */
    74             inline void moveUpDown(float value)
    75             { this->moveUpDown(Vector2(value, 0)); }
    76 
    77             /**
    78             @brief Rotates the Drone around the y-axis by the specifed amount.
    79             @param value  The amount by which the drone is to be rotated.
    80             */
    81             inline void rotateYaw(float value)
    82             { this->rotateYaw(Vector2(value, 0)); }
    83             /**
    84             @brief Rotates the Drone around the x-axis by the specifed amount.
    85             @param value  The amount by which the drone is to be rotated.
    86             */
    87             inline void rotatePitch(float value)
    88             { this->rotatePitch(Vector2(value, 0)); }
    89             /**
    90             @brief Rotates the Drone around the z-axis by the specifed amount.
    91             @param value  The amount by which the drone is to be rotated.
    92             */
    93             inline void rotateRoll(float value)
    94             { this->rotateRoll(Vector2(value, 0)); }
    95 
    96             /**
    97             @brief Sets the primary thrust to the input amount.
    98             @param thrust The amount of thrust.
    99             */
    100             inline void setPrimaryThrust( float thrust )
    101                 { this->primaryThrust_ = thrust; }
    102             //TODO: Place your set-functions here.
    103             // Hint: auxiliary thrust, rotation thrust.
     52            inline void setResetPosition(Vector3 rpos)
     53                { this->resetposition = rpos; }   
    10454           
    105             /**
    106             @brief Gets the primary thrust to the input amount.
    107             @return The amount of thrust.
    108             */
    109             inline float getPrimaryThrust()
    110                 { return this->primaryThrust_; }
    111             //TODO: Place your get-functions here.
     55            inline Vector3 getResetPosition()
     56               { return this->resetposition; }       
    11257
    11358        private:
    114             PacmanGhostController *myController_; //!< The controller of the AutonomousDrone.
    115 
    116             btVector3 localLinearAcceleration_; //!< The linear acceleration that is used to move the AutonomousDrone the next tick.
    117             btVector3 localAngularAcceleration_; //!< The linear angular acceleration that is used to move the AutonomousDrone the next tick.
    118             float primaryThrust_; //!< The amount of primary thrust. This is just used, when moving forward.
    119             float auxiliaryThrust_; //!< The amount of auxiliary thrust. Used for all other movements (except for rotations).
    120             float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.s
    121        
     59           
     60            Vector3 resetposition;
    12261    };
    12362
Note: See TracChangeset for help on using the changeset viewer.