1 | #include "PacmanRed.h" |
---|
2 | //#include "Pacman.h" |
---|
3 | |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | namespace orxonox{ |
---|
10 | |
---|
11 | RegisterClass(PacmanRed); |
---|
12 | |
---|
13 | PacmanRed::PacmanRed(Context* context) : PacmanGhost(context){ |
---|
14 | |
---|
15 | RegisterObject(PacmanRed); |
---|
16 | this->target_x=0; |
---|
17 | this->target_z=15; |
---|
18 | this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135); |
---|
19 | this->isNearPlayer=false; |
---|
20 | |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | /** |
---|
25 | @brief |
---|
26 | Method for creating a ghost through XML. |
---|
27 | */ |
---|
28 | void PacmanRed::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
29 | { |
---|
30 | SUPER(PacmanRed, XMLPort, xmlelement, mode); |
---|
31 | } |
---|
32 | |
---|
33 | /*void PacmanRed::setPlayerPos(Vector3 _playerPos) |
---|
34 | { |
---|
35 | this->playerPos = _playerPos; |
---|
36 | }*/ |
---|
37 | |
---|
38 | |
---|
39 | void PacmanRed::tick(float dt) |
---|
40 | { |
---|
41 | //std::cout<<"LemanExpress5"<<endl; |
---|
42 | SUPER(PacmanGhost, tick, dt); |
---|
43 | |
---|
44 | this->actuelposition = this->getPosition(); |
---|
45 | |
---|
46 | for(int u=0; u < 67; u++){//always check if player passed a point |
---|
47 | //if(possibleposition[u]!=Vector3(0,10,15)){ |
---|
48 | if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ |
---|
49 | //if(!findpos(possibleposition[u],Vector3(0,10,15))){ |
---|
50 | this->lastPlayerPassedPoint=possibleposition[u]; |
---|
51 | } |
---|
52 | //} |
---|
53 | //} |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | /*if((playerFindPos(this->actuelposition, this->getPlayerPos()))&&(isNearPlayer==false)){ |
---|
58 | isNearPlayer=true; |
---|
59 | setNewTargetRed(this->getPlayerPos()); |
---|
60 | } |
---|
61 | else if (!(playerFindPos(this->actuelposition, this->getPlayerPos())&&(isNearPlayer==true))){ |
---|
62 | isNearPlayer=false; |
---|
63 | setNewTargetRed(this->pointInFrontOfPlayer); |
---|
64 | }*/ |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | //Stop, if target arrived |
---|
70 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
71 | //std::cout<<"LemanExpress1"<<endl; |
---|
72 | this->ismoving = false; |
---|
73 | } |
---|
74 | |
---|
75 | //Move, if ghost hasn't arrived yet |
---|
76 | if(this->ismoving){ |
---|
77 | //std::cout<<"LemanExpress2"<<endl; |
---|
78 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
79 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
80 | move(dt, actuelposition, velocity); |
---|
81 | } |
---|
82 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
83 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
84 | move(dt, actuelposition, velocity); |
---|
85 | } |
---|
86 | //std::cout<<"LemanExpress4"<<endl; |
---|
87 | } |
---|
88 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
89 | //as long as the player has not started the game, |
---|
90 | //i.e. lastPlayerPastPoint is (0,0,0), red pacman |
---|
91 | //cannot possibly move, because it needs the position |
---|
92 | //of the player to move accordingly |
---|
93 | |
---|
94 | this->ismoving=false; |
---|
95 | } |
---|
96 | |
---|
97 | //Check on which position the ghost has arrived and set new target |
---|
98 | else{ |
---|
99 | std::cout<<"LemanExpress3"<<endl; |
---|
100 | |
---|
101 | while(lockmove){}; |
---|
102 | lockmove = true; |
---|
103 | |
---|
104 | //do red behavior |
---|
105 | //Use target_x and target_z for position of red pacman |
---|
106 | |
---|
107 | Vector3 redPos=Vector3(this->target_x, 10, this->target_z); |
---|
108 | //nextMove(this->getPlayerPos(), redPos); |
---|
109 | |
---|
110 | int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); |
---|
111 | this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
112 | |
---|
113 | |
---|
114 | if(!findpos(this->actuelposition, lastPlayerPassedPoint)){ |
---|
115 | |
---|
116 | /*std::cout<<this->getPlayerPos()<<endl; |
---|
117 | std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
118 | std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
119 | std::cout<<this->actuelposition<<endl;*/ |
---|
120 | nextMove(redPos, lastPlayerPassedPoint); |
---|
121 | std::cout<<"hiuddi"<<endl; |
---|
122 | } |
---|
123 | else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint |
---|
124 | |
---|
125 | /*std::cout<<"dhdidjop"<<endl; |
---|
126 | std::cout<<this->getPlayerPos()<<endl; |
---|
127 | std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
128 | std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
129 | std::cout<<this->actuelposition<<endl;*/ |
---|
130 | |
---|
131 | //if(!findpos(pointInFrontOfPlayer, Vector3(0,10,15))){ |
---|
132 | nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer); |
---|
133 | //} |
---|
134 | std::cout<<"ogslodm"<<endl; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | lockmove=false; //NEVER FORGET THIS ONE !!!!!!! |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){ |
---|
145 | |
---|
146 | Vector3 nextTarget; |
---|
147 | |
---|
148 | nextTarget = getShortestPath(redPosP, playerPos); |
---|
149 | |
---|
150 | setNewTargetGhost(nextTarget); |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | //save last checkpoint crossed by player |
---|
156 | /* |
---|
157 | void PacmanGelb::tick(float dt){ //last passed point of player |
---|
158 | for(int u=0; u < 67; u++){ |
---|
159 | if(findpos(this->getPosition(), possibleposition[u])){ |
---|
160 | this->lastPassedPoint=possibleposition[u]; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | */ |
---|
165 | |
---|
166 | } |
---|