Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 29, 2018, 12:15:19 PM (6 years ago)
Author:
dreherm
Message:

Update for ghost controller and ghost class

File:
1 edited

Legend:

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

    r11832 r11834  
    4343        The context of this object.
    4444    */
    45     PacmanGhostRed::PacmanGhostController(Context* context) : Controller(context)
     45    PacmanGhostController::PacmanGhostController(Context* context) : Controller(context)
    4646    {
    4747        RegisterObject(PacmanGhostController);
     48
     49        PacmanGhost* myGhost = nullptr;
     50        this->actuelposition = myGhost.getPosition();
     51
    4852        bool ismoving = false;
    49         float reltarget_x;
    50         float reltarget_z; 
    51         Vector3& actuelposition;     
     53        this->target_x = actuelposition.x;
     54        this->target_z = actuelposition.z;     
     55    }
     56
     57    void PacmanGhostController::setGhost(PacmanGhost ghost){
     58        this->myGhost = ghost;
    5259    }
    5360
     
    6168    }
    6269
     70
     71    static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)];
    6372    /**
    6473    @brief
     
    7786        PacmanGhost* myDrone = *it;
    7887
    79         if (myGhost != nullptr)
     88        if (this->myGhost != nullptr)
    8089        {
    8190
    82             actuelposition = myGhost.getPosition();
     91            this->actuelposition = this->myGhost.getPosition();
    8392
    84             if(actuelposition.x = reltarget_x && actuelposition.z = reltarget_z){
    85                     ismoving = false;
     93            if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){
     94                    this->ismoving = false;
    8695            }
    8796
    88 
    89 
    90             if(ismoving){
    91                 moveRightLeft();
    92                 moveFrontBack();
     97        if(this->ismoving){
     98            if(!((this->actuelposition.z-target_z)<0.1))
     99                moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100);
     100            if(!((this->actuelposition.x-target_x)<0.1))
     101              moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small
     102        }
     103       
     104        else{ //Check on which position ghost is
     105            if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){
     106                this->target_x = possibleposition[1].x;
     107                this->target_z = possibleposition[1].z;
     108                this->ismoving = true;
    93109            }
    94        
     110            else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){
     111                this->target_x = 0
     112                this->target_z = 
     113                this->ismoving = true;
     114            }
    95115            else{
    96 
    97                 //hashtable
    98 
    99                 int random = rand();
    100 
    101                 switch(actuelposition) {
    102                     case 1: if(random % 4 == 0){
    103                             reltarget_x = 250;
    104                             reltarget_z = 0;
    105                             }
    106                             else if(random % 4 == 1){
    107                             reltarget_x = 0;
    108                             reltarget_z = 250;
    109                             }
    110                             else if(random % 4 == 2){
    111                             reltarget_x = 0;
    112                             reltarget_z = -250;
    113                             }
    114                             else if(random % 4 == 3){
    115                             reltarget_x = -250;
    116                             reltarget_z = 0;
    117                             }
    118                             moving = true;
    119                     case 2:
    120                 }
    121             }
    122 
     116            }     
     117            } //End of Position table
    123118
    124119        }
    125120    }
     121
    126122}
Note: See TracChangeset for help on using the changeset viewer.