[Orxonox-commit 7725] r12318 - code/branches/3DPacman_FS19/src/modules/pacman
peterf at orxonox.net
peterf at orxonox.net
Sun Apr 21 19:58:47 CEST 2019
Author: peterf
Date: 2019-04-21 19:58:47 +0200 (Sun, 21 Apr 2019)
New Revision: 12318
Modified:
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
Log:
improved red pacman behavior, but still segmentation fault sometimes
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-20 16:29:44 UTC (rev 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-21 17:58:47 UTC (rev 12318)
@@ -240,6 +240,7 @@
{
return player->getWorldPosition();
}
+ //std::cout<<"bug ??"<<endl;
return Vector3(0,0,0); //default, should not be used
}
@@ -744,12 +745,46 @@
return result;
}
+
+ bool PacmanGhost::playerFindPos(Vector3 one, Vector3 other){
+ if((abs(one.x - other.x)<15) && (abs(one.z - other.z)<15)) return true;
+ return false;
+ }
+
+
+
+
int PacmanGhost::findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){
//return 0 for south, 1 for west, 2 for north, 3 for east
- Vector3 difference = diffVector(playerPosBefore, playerPos);
+ if(playerFindPos(playerPosBefore, playerPos)){
+ //if player is still near last crossed point
+ return 4; //return the last crossed point for simplicity
+ }
+
+
+ if(abs(playerPos.x-playerPosBefore.x)<14){ //player is moving vertically
+ if((playerPos.z-playerPosBefore.z)<0){//move west
+ return 0;
+ }
+ if((playerPos.z-playerPosBefore.z)>0){//move east
+ return 2;
+ }
+ }
+
+ if(abs(playerPos.z-playerPosBefore.z)<14){ //player is moving horizontally
+ if((playerPos.x-playerPosBefore.x)<0){//move south
+ return 1;
+ }
+ if((playerPos.x-playerPosBefore.x)>0){//move north
+ return 3;
+ }
+ }
+
+
+ /*Vector3 difference = diffVector(playerPosBefore, playerPos);
if((difference.z < 0)&&(difference.z>difference.x)){ //move south
return 0;
@@ -771,7 +806,7 @@
else { //default move west Can still be changed
return 1;
- }
+ }*/
}
@@ -779,6 +814,11 @@
//return the Vector3 point that Pinky should target to
//be in front of pacman
+ if(indexForSWNE==4){
+ std::cout<<"Ryukyu"<<endl;
+ return pacLasVisPos;
+ }
+
Vector3 listOfNeighboors[4];
//first element is south, 2nd west, 3d north, 4th east
@@ -839,6 +879,11 @@
return listOfNeighboors[indexForSWNE];
}
else if(findpos(pacLasVisPos,possibleposition[10])){
+
+ if(indexForSWNE==3){ //nothing eastward
+ return pacLasVisPos;
+ }
+
listOfNeighboors[0]=possibleposition[9]; //south
listOfNeighboors[1]=possibleposition[45]; //west
listOfNeighboors[2]=possibleposition[11]; //north
@@ -1019,6 +1064,11 @@
return listOfNeighboors[indexForSWNE];
}
else if(findpos(pacLasVisPos,possibleposition[42])){
+
+ if(indexForSWNE==1){//nothing westward
+ return pacLasVisPos;
+ }
+
listOfNeighboors[0]=possibleposition[39]; //south
listOfNeighboors[2]=possibleposition[59]; //north
listOfNeighboors[3]=possibleposition[43]; //east
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h 2019-04-20 16:29:44 UTC (rev 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h 2019-04-21 17:58:47 UTC (rev 12318)
@@ -88,8 +88,12 @@
Vector3 playerPos;
- Vector3 lastPlayerPassedPoint;/*
+ Vector3 lastPlayerPassedPoint;
+ Vector3 pointInFrontOfPlayer;
+ /*
+
+
//Vector3 pathAlgorithm;
public: //HACK
@@ -119,7 +123,9 @@
int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos);
Vector3 diffVector (Vector3 start, Vector3 goal);
+ bool playerFindPos(Vector3 one, Vector3 other);
+
};
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc 2019-04-20 16:29:44 UTC (rev 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc 2019-04-21 17:58:47 UTC (rev 12318)
@@ -16,6 +16,7 @@
this->target_x=0;
this->target_z=15;
this->lastPlayerPassedPoint=Vector3(70,10,-135);
+ this->isNearPlayer=false;
}
@@ -41,6 +42,7 @@
void PacmanRed::tick(float dt)
{
+ std::cout<<"LemanExpress5"<<endl;
SUPER(PacmanGhost, tick, dt);
this->actuelposition = this->getPosition();
@@ -51,14 +53,28 @@
}
}
-
+
+ /*if((playerFindPos(this->actuelposition, this->getPlayerPos()))&&(isNearPlayer==false)){
+ isNearPlayer=true;
+ setNewTargetRed(this->getPlayerPos());
+ }
+ else if (!(playerFindPos(this->actuelposition, this->getPlayerPos())&&(isNearPlayer==true))){
+ isNearPlayer=false;
+ setNewTargetRed(this->pointInFrontOfPlayer);
+ }*/
+
+
+
+
//Stop, if target arrived
if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
+ std::cout<<"LemanExpress1"<<endl;
this->ismoving = false;
}
//Move, if ghost hasn't arrived yet
if(this->ismoving){
+ std::cout<<"LemanExpress2"<<endl;
if(!(abs(this->actuelposition.z-target_z)<0.5)) {
velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
move(dt, actuelposition, velocity);
@@ -67,10 +83,12 @@
velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
move(dt, actuelposition, velocity);
}
+ std::cout<<"LemanExpress4"<<endl;
}
-
+
//Check on which position the ghost has arrived and set new target
else{
+ std::cout<<"LemanExpress3"<<endl;
while(lockmove){};
lockmove = true;
@@ -82,24 +100,28 @@
//nextMove(this->getPlayerPos(), redPos);
int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+ this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
- if(this->actuelposition!=lastPlayerPassedPoint){
+ if(!findpos(this->actuelposition, lastPlayerPassedPoint)){
std::cout<<this->getPlayerPos()<<endl;
std::cout<<this->lastPlayerPassedPoint<<endl;
- std::cout<<getPointInFrontOfPacman(lastPlayerPassedPoint, directionV)<<endl;
+ std::cout<<this->pointInFrontOfPlayer<<endl;
+ std::cout<<this->actuelposition<<endl;
nextMove(redPos, lastPlayerPassedPoint);
+ std::cout<<"hiuddi"<<endl;
}
- else{// red pacman is at lastPlayerPassedPoint
+ else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint
- //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+ std::cout<<"dhdidjop"<<endl;
+ std::cout<<this->getPlayerPos()<<endl;
+ std::cout<<this->lastPlayerPassedPoint<<endl;
+ std::cout<<this->pointInFrontOfPlayer<<endl;
+ std::cout<<this->actuelposition<<endl;
- Vector3 pointInFrontOfPlayer = getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
-
- nextMove(redPos, pointInFrontOfPlayer);
-
- //nextMove(this->getPlayerPos(), redPos);
+ nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer);
+ std::cout<<"ogslodm"<<endl;
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h 2019-04-20 16:29:44 UTC (rev 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h 2019-04-21 17:58:47 UTC (rev 12318)
@@ -25,8 +25,10 @@
bool jeanfindpos(Vector3 one, Vector3 other);
+ bool isNearPlayer;
+
};
}
More information about the Orxonox-commit
mailing list