[Orxonox-commit 7283] r11900 - in code/branches/3DPacman_FS18: data/levels/templates src/modules/pacman
dreherm at orxonox.net
dreherm at orxonox.net
Tue Apr 24 13:10:36 CEST 2018
Author: dreherm
Date: 2018-04-24 13:10:36 +0200 (Tue, 24 Apr 2018)
New Revision: 11900
Modified:
code/branches/3DPacman_FS18/data/levels/templates/PacmanGelb.oxt
code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.cc
code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.h
Log:
Add Ghost movements
Modified: code/branches/3DPacman_FS18/data/levels/templates/PacmanGelb.oxt
===================================================================
--- code/branches/3DPacman_FS18/data/levels/templates/PacmanGelb.oxt 2018-04-24 08:32:56 UTC (rev 11899)
+++ code/branches/3DPacman_FS18/data/levels/templates/PacmanGelb.oxt 2018-04-24 11:10:36 UTC (rev 11900)
@@ -34,7 +34,7 @@
collisionType = "dynamic"
mass = 80
- linearDamping = 0.7
+ linearDamping = 0.9
angularDamping = 0.9999999
>
<engines>
Modified: code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.cc 2018-04-24 08:32:56 UTC (rev 11899)
+++ code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.cc 2018-04-24 11:10:36 UTC (rev 11900)
@@ -80,7 +80,8 @@
- Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,10,245),Vector3(215,10,210)};
+ Vector3 possibleposition[] = {Vector3(175,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195),
+ Vector3(185,10,150),Vector3(135,10,145),Vector3(215,10,150)};
/**
@brief
@@ -104,11 +105,11 @@
//Move, if ghost hasn't arrived yet
if(this->ismoving){
if(!(abs(this->actuelposition.z-target_z)<0.1)) {
- velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));
+ velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
move(dt, actuelposition, velocity);
}
if(!(abs(this->actuelposition.x-target_x)<0.1)){
- velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));
+ velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
move(dt, actuelposition, velocity);
}
}
@@ -115,7 +116,7 @@
//Check on which position ghost has arrived and set new target
else{
- if((abs(this->actuelposition.x - possibleposition[0].x)<0.1) && (abs(this->actuelposition.z - possibleposition[0].z)<0.1)){
+ if(findpos(actuelposition,possibleposition[0])){
decision = rand()%1;
switch(decision){
case 0:
@@ -122,10 +123,11 @@
this->target_x = possibleposition[1].x;
this->target_z = possibleposition[1].z;
this->ismoving = true;
+ break;
}
}
- else if((abs(actuelposition.x - possibleposition[1].x)<0.1) && (abs(actuelposition.z - possibleposition[1].z)<0.1)){
+ else if(findpos(actuelposition,possibleposition[1])){
decision = rand()%2;
switch(decision){
case 0:
@@ -136,21 +138,104 @@
case 1:
this->target_x = possibleposition[2].x;
this->target_z = possibleposition[2].z;
- this->ismoving = true;
+ this->ismoving = true;
+ break;
}
}
- if((abs(this->actuelposition.x - possibleposition[2].x)<0.1) && (abs(this->actuelposition.z - possibleposition[2].z)<0.1)){
- decision = rand()%1;
+ else if(findpos(actuelposition,possibleposition[2])){
+ decision = rand()%2;
switch(decision){
case 0:
this->target_x = possibleposition[1].x;
this->target_z = possibleposition[1].z;
this->ismoving = true;
+ break;
+ case 1:
+ this->target_x = possibleposition[3].x;
+ this->target_z = possibleposition[3].z;
+ this->ismoving = true;
+ break;
}
}
+ else if(findpos(actuelposition,possibleposition[3])){
+ decision = rand()%3;
+ switch(decision){
+ case 0:
+ this->target_x = possibleposition[2].x;
+ this->target_z = possibleposition[2].z;
+ this->ismoving = true;
+ break;
+ case 1:
+ this->target_x = possibleposition[4].x;
+ this->target_z = possibleposition[4].z;
+ this->ismoving = true;
+ break;
+ case 2:
+ this->target_x = possibleposition[5].x;
+ this->target_z = possibleposition[5].z;
+ this->ismoving = true;
+ break;
+ }
+ }
+
+ else if(findpos(actuelposition,possibleposition[4])){
+ decision = rand()%2;
+ switch(decision){
+ case 0:
+ this->target_x = possibleposition[3].x;
+ this->target_z = possibleposition[3].z;
+ this->ismoving = true;
+ break;
+ case 1:
+ this->target_x = possibleposition[6].x;
+ this->target_z = possibleposition[6].z;
+ this->ismoving = true;
+ break;
+ }
+ }
+
+ else if(findpos(actuelposition,possibleposition[5])){
+ decision = rand()%2;
+ switch(decision){
+ case 0:
+ this->target_x = possibleposition[3].x;
+ this->target_z = possibleposition[3].z;
+ this->ismoving = true;
+ break;
+ case 1:
+ this->target_x = possibleposition[7].x;
+ this->target_z = possibleposition[7].z;
+ this->ismoving = true;
+ break;
+ }
+ }
+
+ else if(findpos(actuelposition,possibleposition[6])){
+ decision = rand()%1;
+ switch(decision){
+ case 0:
+ this->target_x = possibleposition[4].x;
+ this->target_z = possibleposition[4].z;
+ this->ismoving = true;
+ break;
+ }
+ }
+
+ else if(findpos(actuelposition,possibleposition[7])){
+ decision = rand()%1;
+ switch(decision){
+ case 0:
+ this->target_x = possibleposition[5].x;
+ this->target_z = possibleposition[5].z;
+ this->ismoving = true;
+ break;
+ }
+ }
+
+
else{
} //End of Position table
}
@@ -162,6 +247,11 @@
this->setPosition(Vector3(actuelposition.x+20*velocity.x*dt,10,actuelposition.z+20*velocity.z*dt));
}
+ bool PacmanGhost::findpos(Vector3 one, Vector3 other){
+ if((abs(one.x - other.x)<0.1) && (abs(one.z - other.z)<0.1)) return true;
+ return false;
+ }
+
void PacmanGhost::resetGhost(){
this->setPosition(resetposition);
}
Modified: code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.h 2018-04-24 08:32:56 UTC (rev 11899)
+++ code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.h 2018-04-24 11:10:36 UTC (rev 11900)
@@ -50,6 +50,8 @@
void resetGhost();
+ bool findpos(Vector3 one, Vector3 other);
+
inline void setResetPosition(Vector3 rpos)
{ this->resetposition = rpos; }
More information about the Orxonox-commit
mailing list