Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2019, 1:26:10 PM (6 years ago)
Author:
peterf
Message:

added several pacmans

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc

    r12303 r12304  
    3434namespace orxonox
    3535{
     36
     37    //Check if there is a collision
     38        bool findpos(Vector3 one, Vector3 other){
     39       if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true;
     40        return false;
     41        }
     42
     43    //All positions in the map, see documentation
     44     Vector3 possibleposition[67] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4
     45        Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9
     46        Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14
     47        Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19
     48        Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24
     49        Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29
     50        Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34
     51        Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39
     52        Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44
     53        Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49
     54        Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54
     55        Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59
     56        Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64
     57        Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66
     58
    3659    RegisterClass(PacmanGhost);
    3760
     
    4770
    4871        this->velocity = Vector3(0, 0, 0);
     72
    4973        this->setCollisionType(CollisionType::Dynamic);
    5074       
     
    7296        Method for creating a ghost through XML.
    7397    */
    74     void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     98     void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7599    {
    76100        SUPER(PacmanGhost, XMLPort, xmlelement, mode);
    77 
    78     }
    79 
    80 
    81    /* //All positions in the map, see documentation
    82     Vector3 possibleposition[] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4
    83         Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9
    84         Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14
    85         Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19
    86         Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24
    87         Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29
    88         Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34
    89         Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39
    90         Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44
    91         Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49
    92         Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54
    93         Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59
    94         Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64
    95         Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66*/
    96 
    97     /**
    98     @brief
    99         Defines which actions the ghost has to take in each tick.
    100     @param dt
    101         The length of the tick.
    102     */
    103     void PacmanGhost::tick(float dt)
    104     {
    105         SUPER(PacmanGhost, tick, dt);
    106 
    107         this->actuelposition = this->getPosition();
    108        
    109         //Stop, if target arrived
    110         if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
    111                  this->ismoving = false;
    112         }
    113 
    114         //Move, if ghost hasn't arrived yet
    115         if(this->ismoving){
    116             if(!(abs(this->actuelposition.z-target_z)<0.5)) {
    117                 velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
    118                 move(dt, actuelposition, velocity);
    119             }   
    120             if(!(abs(this->actuelposition.x-target_x)<0.5)){
    121                 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
    122                 move(dt, actuelposition, velocity);
    123             }
    124         }
    125 
    126     }
    127 
    128 
    129     //Random choice of new target (not used in game, but useful)
    130     void PacmanGhost::setnewTarget(int firstdec){
    131        
    132           decision = rand()%1;
    133             switch(decision){
    134                 case 0:
    135                     this->target_x = possibleposition[firstdec].x;
    136                     this->target_z = possibleposition[firstdec].z;
    137                     this->ismoving = true;
    138                     break;
    139                 }
    140101    }
    141102
     
    164125       
    165126        //Rotate ghost in the direction of movement
    166         if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1))
     127        if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1)){
    167128            if(velocity.x<0){
    168129                 this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0))); 
     
    171132                 this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0))); 
    172133            }
    173         if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1))
     134        }
     135        if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1)){
    174136            if(velocity.z<0){
    175137                 this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0))); 
     
    178140                 this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0))); 
    179141            }
     142        }
    180143                     
    181144     }
    182     }
    183 
    184     //Check if there is a collision
    185     bool PacmanGhost::findpos(Vector3 one, Vector3 other){
    186        if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true;
    187         return false;
    188145    }
    189146
     
    213170        speed ++;
    214171    }
     172
     173    Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){
     174        //given that the position of a pacman is generally not "neat",
     175        //we need to set it to the nearest point on the map
     176        // if the pacman is not moving anymore, i.e. has reached a point
     177        int i=0;
     178        while(!(findpos(possibleposition[i], posToSet))){
     179            i++;
     180        }
     181        return possibleposition[i];
     182    }
     183
     184
    215185}
Note: See TracChangeset for help on using the changeset viewer.