- Timestamp:
- Apr 18, 2019, 1:26:10 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
r12303 r12304 34 34 namespace orxonox 35 35 { 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 36 59 RegisterClass(PacmanGhost); 37 60 … … 47 70 48 71 this->velocity = Vector3(0, 0, 0); 72 49 73 this->setCollisionType(CollisionType::Dynamic); 50 74 … … 72 96 Method for creating a ghost through XML. 73 97 */ 74 void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)98 void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode) 75 99 { 76 100 SUPER(PacmanGhost, XMLPort, xmlelement, mode); 77 78 }79 80 81 /* //All positions in the map, see documentation82 Vector3 possibleposition[] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-483 Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-984 Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-1485 Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-1986 Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-2487 Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-2988 Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-3489 Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-3990 Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-4491 Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-4992 Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-5493 Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-5994 Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-6495 Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66*/96 97 /**98 @brief99 Defines which actions the ghost has to take in each tick.100 @param dt101 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 arrived110 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 yet115 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 }140 101 } 141 102 … … 164 125 165 126 //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)){ 167 128 if(velocity.x<0){ 168 129 this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0))); … … 171 132 this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0))); 172 133 } 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)){ 174 136 if(velocity.z<0){ 175 137 this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0))); … … 178 140 this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0))); 179 141 } 142 } 180 143 181 144 } 182 }183 184 //Check if there is a collision185 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;188 145 } 189 146 … … 213 170 speed ++; 214 171 } 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 215 185 }
Note: See TracChangeset
for help on using the changeset viewer.