[Orxonox-commit 7727] r12320 - code/branches/3DPacman_FS19/src/modules/pacman

peterf at orxonox.net peterf at orxonox.net
Mon Apr 22 14:17:58 CEST 2019


Author: peterf
Date: 2019-04-22 14:17:58 +0200 (Mon, 22 Apr 2019)
New Revision: 12320

Added:
   code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.cc
   code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.h
Modified:
   code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
   code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.cc
   code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.h
   code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
Log:
began PacmanBrown and Cyan implementation

Modified: code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt	2019-04-21 21:30:41 UTC (rev 12319)
+++ code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt	2019-04-22 12:17:58 UTC (rev 12320)
@@ -8,6 +8,8 @@
   PacmanRandom.cc
   PacmanRed.cc
   PacmanPink.cc
+  PacmanBrown.cc
+  PacmanCyan.cc
 )
 
 ORXONOX_ADD_LIBRARY(pacman

Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.cc	2019-04-21 21:30:41 UTC (rev 12319)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.cc	2019-04-22 12:17:58 UTC (rev 12320)
@@ -25,7 +25,18 @@
     }
 
 
+int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){
 
+
+        Ogre::Vector3 diffVector;
+        diffVector.x=pos2.x-pos1.x;
+        diffVector.y=pos2.y-pos1.y; //should always be 0
+        diffVector.z=pos2.z-pos1.z;
+        int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z));
+        return result;
+    }
+
+
 	void PacmanBrown::tick(float dt)
     {
         SUPER(PacmanGhost, tick, dt);
@@ -58,7 +69,41 @@
         	//do brown behavior
         	//put everything needed here
 
-        	if((this->fleeing==true)&&(this->actuelposition!=(-215,10,-195))){
+            Vector3 brownPos=Vector3(this->target_x, 10, this->target_z);
+
+            if(absoluteDistance(this->lastPlayerPassedPoint, this->actuelposition)<50){
+                //no idea if 50 is large enough 
+
+                //if near player, flee
+
+                this->isFleeing=true;
+                Vector3 nextMove=getShortestPath( brownPos,Vector3(-215, 10, -195));
+                setNewTargetGhost(nextMove);
+
+            }
+
+            else if((this->isFleeing==true)&&(brownPos!=Vector3(-215,10,-195))){
+                //if fleeing, continue to flee
+             Vector3 nextMove = getShortestPath(brownPos, Vector3(-215, 10, -195));
+             setNewTargetGhost(nextMove);
+        }
+            else if ((this->isFleeing==true)&&(brownPos==Vector3(-215,10,-195))){
+                //if fleeing and reached flee point, go back near player
+            this->isFleeing=false;
+            Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint);
+            setNewTargetGhost(nextMove);
+        }
+            else{
+                //if not fleeing and not near player, go near player
+                Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint);
+            setNewTargetGhost(nextMove);
+            }
+        }
+
+
+
+
+        	/*if((this->fleeing==true)&&(this->actuelposition!=(-215,10,-195))){
             //if fleeing, then go to corner map if not already there
         		fleeMode();
         	}
@@ -81,14 +126,15 @@
         	setNewTargetBrown(nextMove);
         		}
 
-        	}
+        	}*/
+            lockmove=false; //NEVER FORGET THIS ONE !!!
    
         }
-        
     }
 
 
 
+    
 
 
 
@@ -96,23 +142,29 @@
 
 
 
-	int graphDistance(Vector3 start, Vector3 goal){
 
+
+
+
+
+
+	/*int graphDistance(Vector3 start, Vector3 goal){
+
         Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z));
 
         return differenceVector.x+differenceVector.z;
-    }
+    }*/
 
-	void setNewTargetBrown(Vector3 goalToGo){
+	/*void setNewTargetBrown(Vector3 goalToGo){
 
 					this->target_x = goalToGo.x;
                     this->target_z = goalToGo.z; 
                     this->ismoving = true;
-	}
+	}*/
 
 
 
-	int absoluteDistance(Vector3 pos1, Vector3 pos2){
+	/*int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){
 
 
 		Vector3 diffVector;
@@ -119,26 +171,26 @@
 		diffVector.x=pos2-pos1;
 		diffVector.y=pos2-pos1; //should always be 0
 		diffVector.z=pos2-pos1;
-		int result = sqrt(diffVector.x²+diffVector.z²);
+		int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z));
 		return result;
-	}
+	}*/
 
 
-	void fleeMode(){ //flees to corner of the map
+	/*void fleeMode(){ //flees to corner of the map
 
 		Vector3 cornerPos = Vector3(-215,10,-195); //let's take this. We can still change
 		Vector3 nextMove = getShortestPath(this->actuelposition, cornerPos);
-		setNewTargetBrown(nextMove);
+		setNewTargetGhost(nextMove);
 
-		/*//while(this->actuelposition!=cornerPos){
+		//while(this->actuelposition!=cornerPos){
 	
 		continue moving and each time find next point to go until
 		we reach the corner
-		}*/
-	}
+		}
+	}*/
 
 
-	Vector3 goAdjacentOfPlayer(Vector neighboorsOfPlayer[]){
+	/*Vector3 goAdjacentOfPlayer(Vector neighboorsOfPlayer[]){
 		//find ,nearest to brown, player neighboor 
 
 		int besTotDist=-1;
@@ -170,10 +222,10 @@
 		}
 		return chosenNeighbor;
 
-	}
+	}*/
 
 
-	Vector3 findPlayerNeighboorNearestToPacman(Vector3 neighboorArray[]){
+	/*Vector3 findPlayerNeighboorNearestToPacman(Vector3 neighboorArray[]){
 		//uh, i think it does the same think as the function above
 
         Vector3 nextMove;
@@ -202,10 +254,10 @@
         }
         return nextMove;
 
-    }
+    }*/
 
-}
 
 
 
 
+

Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.h	2019-04-21 21:30:41 UTC (rev 12319)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.h	2019-04-22 12:17:58 UTC (rev 12320)
@@ -28,11 +28,13 @@
   			void fleeMode();
 
 
-  			Vector3 goAdjacentOfPlayer(Vector neighboorsOfPlayer[]);
+  			Vector3 goAdjacentOfPlayer(Vector3 neighboorsOfPlayer[]);
   			//they both do the same -_-
   			Vector3 findPlayerNeighboorNearestToPacman(Vector3 neighboorArray);
 
+        bool isFleeing;
 
+
 	};
 
 }

Added: code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.cc	                        (rev 0)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.cc	2019-04-22 12:17:58 UTC (rev 12320)
@@ -0,0 +1,91 @@
+#include "PacmanCyan.h"
+//#include "Pacman.h"
+
+#include "core/CoreIncludes.h"
+#include "BulletDynamics/Dynamics/btRigidBody.h"
+
+
+
+	namespace orxonox{
+
+		RegisterClass(PacmanCyan);
+
+		PacmanCyan::PacmanCyan(Context* context) : PacmanGhost(context){
+
+        RegisterObject(PacmanCyan);
+        this->target_x=0;
+        this->target_z=15;
+        this->lastPlayerPassedPoint=Vector3(70,10,-135);
+          
+    }
+
+
+    /**
+    @brief
+        Method for creating a ghost through XML.
+    */
+    void PacmanCyan::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(PacmanCyan, XMLPort, xmlelement, mode);
+    }
+
+
+
+    void PacmanCyan::tick(float dt)
+    {
+        
+        SUPER(PacmanGhost, tick, dt);
+
+        this->actuelposition = this->getPosition();
+
+
+
+        //Stop, if target arrived
+        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
+            
+                 this->ismoving = false;
+        }
+
+        //Move, if ghost hasn't arrived yet
+        if(this->ismoving){
+            
+            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
+                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
+                move(dt, actuelposition, velocity);
+            }    
+            if(!(abs(this->actuelposition.x-target_x)<0.5)){
+                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
+                move(dt, actuelposition, velocity);
+            }
+            
+        }
+
+        //Check on which position the ghost has arrived and set new target
+        else{
+
+            while(lockmove){};
+            lockmove = true;
+
+        	
+
+            Vector3 cyanPos=Vector3(this->target_x, 10, this->target_z);
+            
+
+
+            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
+        }
+        
+    }
+
+
+	void PacmanCyan::nextMove( Vector3 cyanPosP, Vector3 playerPos){
+	
+        Vector3 nextTarget;
+
+	   nextTarget = getShortestPath(cyanPosP, playerPos);
+	
+	   setNewTargetGhost(nextTarget);
+	}
+
+
+}
\ No newline at end of file

Added: code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.h	                        (rev 0)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.h	2019-04-22 12:17:58 UTC (rev 12320)
@@ -0,0 +1,28 @@
+#ifndef _PacmanCyan_H__
+#define _PacmanCyan_H__
+
+
+#include "PacmanGhost.h"
+//#include "getShortestPath.h"
+
+
+namespace orxonox {
+
+	class _OrxonoxExport PacmanCyan : public PacmanGhost{
+
+		public :
+			PacmanCyan(Context* context);
+
+			virtual void tick(float dt) override; //!< Defines which actions the AutonomousDrone has to take in each tick.
+
+  			virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
+
+  			void nextMove( Vector3 cyanPosP, Vector3 playerPos);
+
+
+
+	};
+
+}
+
+#endif 
\ No newline at end of file

Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h	2019-04-21 21:30:41 UTC (rev 12319)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h	2019-04-22 12:17:58 UTC (rev 12320)
@@ -36,7 +36,7 @@
 #include "worldentities/ControllableEntity.h"
 
 #include "Pacman.h"
-#include "GetShortestPathAlgorithm.h"
+//#include "GetShortestPathAlgorithm.h"
 
 namespace orxonox {
 



More information about the Orxonox-commit mailing list