Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/PacmanBrown.cc @ 12338

Last change on this file since 12338 was 12338, checked in by peterf, 5 years ago

Pink Bug Workaround

File size: 4.8 KB
Line 
1       
2#include "PacmanBrown.h"
3
4#include "core/CoreIncludes.h"
5#include "BulletDynamics/Dynamics/btRigidBody.h"
6
7       
8        namespace orxonox{
9
10                RegisterClass(PacmanBrown);
11
12                PacmanBrown::PacmanBrown(Context* context) : PacmanGhost(context){
13
14        RegisterObject(PacmanBrown);
15
16        this->target_x=0;
17        this->target_z=15;
18        this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135);
19         
20    }
21
22    /**
23    @brief
24        Method for creating a ghost through XML.
25    */
26    void PacmanBrown::XMLPort(Element& xmlelement, XMLPort::Mode mode)
27    {
28        SUPER(PacmanBrown, XMLPort, xmlelement, mode);
29    }
30
31
32int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){
33
34
35        Vector3 diffVector;
36        diffVector.x=pos2.x-pos1.x;
37        diffVector.y=pos2.y-pos1.y; //should always be 0
38        diffVector.z=pos2.z-pos1.z;
39        int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z));
40        return result;
41    }
42
43
44        void PacmanBrown::tick(float dt)
45    {
46        SUPER(PacmanGhost, tick, dt);
47
48        this->actuelposition = this->getPosition();
49
50
51        for(int u=0; u < 67; u++){//always check if player passed a point
52            if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
53            this->lastPlayerPassedPoint=possibleposition[u];
54                    }
55            }
56
57       
58        //Stop, if target arrived
59        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
60                 this->ismoving = false;
61        }
62
63        //Move, if ghost hasn't arrived yet
64        if(this->ismoving){
65            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
66                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
67                move(dt, actuelposition, velocity);
68            }   
69            if(!(abs(this->actuelposition.x-target_x)<0.5)){
70                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
71                move(dt, actuelposition, velocity);
72            }
73        }
74        else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){
75            //as long as the player has not started the game,
76            //i.e. lastPlayerPastPoint is (0,0,0), brown pacman
77            //cannot possibly move, because it needs the position
78            //of the player to move accordingly
79
80            this->ismoving=false;
81            std::cout<<"weie"<<endl;
82        }
83       
84        //Check on which position the ghost has arrived and set new target
85        else{
86            std::cout<<"naye"<<endl;
87                while(lockmove){};
88            lockmove = true;
89
90                //do brown behavior
91                //put everything needed here
92
93            Vector3 brownPos=Vector3(this->target_x, 10, this->target_z);
94            std::cout<<brownPos<<endl;
95
96           
97            if(this->isFleeing==true){
98                if(findpos(brownPos, Vector3(-215,10,-195))){
99                    this->isFleeing=false;
100                    //Vector3 nextMoveP = getShortestPath(brownPos, this->lastPlayerPassedPoint);
101                    //this->setNewTargetGhost(nextMoveP);
102                }
103                else{
104                    if(findpos(this->lastPlayerPassedPoint, Vector3(-215,10,-195))){
105                    Vector3 nextMoveP = getShortestPath(brownPos, Vector3(-215,10,-195));
106                    this->setNewTargetGhost(nextMoveP);
107                    }
108                    else{
109                    Vector3 nextMoveP = getShortestPath(brownPos, Vector3(-215,10,-195), this->lastPlayerPassedPoint);
110                    this->setNewTargetGhost(nextMoveP);
111                    }
112                }
113
114            }
115            else {
116                    Vector3 arrayPlaNeig[4];
117
118                    findNeighboorPositions(this->lastPlayerPassedPoint, arrayPlaNeig, possibleposition);
119                    if(isAdjacentToPlayerLastPastPoint(brownPos, arrayPlaNeig)){
120                        this->isFleeing=true;
121                    }
122                    else{
123                        Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint);       
124                        setNewTargetGhost(nextMove);
125                    }
126
127            }
128            std::cout<<this->isFleeing<<endl;
129
130
131            lockmove=false; //NEVER FORGET THIS ONE !!!
132   
133        }
134}
135
136
137    bool PacmanBrown::isAdjacentToPlayerLastPastPoint(Vector3 pacmanBrownPos, Vector3 arrayForNeighborPositions[]){
138            //return true if brownPacman is on an adjacent position to the last
139            //point visited by the player. return false otherwise.
140
141            for(int i =0; i < 4; i++){
142                if(arrayForNeighborPositions[i]!=Vector3(0,0,0)){
143                    if(findpos(pacmanBrownPos, arrayForNeighborPositions[i])){
144                        return true;
145                    }
146                }
147            }
148            return false;
149        }
150
151
152
153}
154
Note: See TracBrowser for help on using the repository browser.