1 | |
---|
2 | #include "PacmanPink.h" |
---|
3 | |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
6 | |
---|
7 | |
---|
8 | namespace orxonox{ |
---|
9 | |
---|
10 | RegisterClass(PacmanPink); |
---|
11 | |
---|
12 | PacmanPink::PacmanPink(Context* context) : PacmanGhost(context){ |
---|
13 | |
---|
14 | RegisterObject(PacmanPink); |
---|
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 PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
27 | { |
---|
28 | SUPER(PacmanPink, XMLPort, xmlelement, mode); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | void PacmanPink::tick(float dt) |
---|
33 | { |
---|
34 | SUPER(PacmanGhost, tick, dt); |
---|
35 | |
---|
36 | this->actuelposition = this->getPosition(); |
---|
37 | |
---|
38 | |
---|
39 | for(int u=0; u < 67; u++){//always check if player passed a point |
---|
40 | if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ |
---|
41 | this->lastPlayerPassedPoint=possibleposition[u]; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | //Stop, if target arrived |
---|
47 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
48 | this->ismoving = false; |
---|
49 | } |
---|
50 | |
---|
51 | //Move, if ghost hasn't arrived yet |
---|
52 | if(this->ismoving){ |
---|
53 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
54 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
55 | move(dt, actuelposition, velocity); |
---|
56 | } |
---|
57 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
58 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
59 | move(dt, actuelposition, velocity); |
---|
60 | } |
---|
61 | } |
---|
62 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
63 | //as long as the player has not started the game, |
---|
64 | //i.e. lastPlayerPastPoint is (0,0,0), pink pacman |
---|
65 | //cannot possibly move, because it needs the position |
---|
66 | //of the player to move accordingly |
---|
67 | |
---|
68 | this->ismoving=false; |
---|
69 | } |
---|
70 | //Check on which position the ghost has arrived and set new target |
---|
71 | else{ |
---|
72 | while(lockmove){}; |
---|
73 | lockmove = true; |
---|
74 | |
---|
75 | Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); |
---|
76 | |
---|
77 | std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
78 | |
---|
79 | int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); |
---|
80 | this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
81 | |
---|
82 | std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
83 | nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint); |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | /*if(findPos(player.getPos(), player.lastPassedPoint)){ |
---|
88 | // if player is on a point, for simplicity go to it |
---|
89 | Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint); |
---|
90 | setNewTargetPink(nextMove); |
---|
91 | } |
---|
92 | |
---|
93 | else{ //if player is not on a point either go to next neighboor, or if no |
---|
94 | //neighboor in player direction available, go to last point passed by player. |
---|
95 | |
---|
96 | int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos()); |
---|
97 | //not in other sense! |
---|
98 | |
---|
99 | Vector3[] neighboors; |
---|
100 | findNeighboor(player.lastPassedPoint, neighboors); |
---|
101 | //we need to create function that finds neighboors of player last point |
---|
102 | //We can use and even should use the part of the tick random function |
---|
103 | // that determines the neighboors. But array neighboor should be in form |
---|
104 | // south-west-north-east respectively to array index. |
---|
105 | |
---|
106 | for(int s=0; s < 4; s++){ |
---|
107 | //find next neighboor between player and player.lastPassedPoint |
---|
108 | if((neighboors[s]!=NULL)&&(s==dir)){ |
---|
109 | if(dir==0){ |
---|
110 | Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); |
---|
111 | setNewTargetPink(nextMove); |
---|
112 | } |
---|
113 | else if(dir==1){ |
---|
114 | Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); |
---|
115 | setNewTargetPink(nextMove); |
---|
116 | } |
---|
117 | else if(dir==2){ |
---|
118 | Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); |
---|
119 | setNewTargetPink(nextMove); |
---|
120 | } |
---|
121 | else{//last is default |
---|
122 | Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); |
---|
123 | setNewTargetPink(nextMove); |
---|
124 | } |
---|
125 | } |
---|
126 | else{//if no further point after last player point possible |
---|
127 | //then simply go to this last point. |
---|
128 | Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint); |
---|
129 | setNewTargetPink(nextMove); |
---|
130 | } |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | }*/ |
---|
135 | lockmove=false; |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){ |
---|
148 | |
---|
149 | Vector3 nextTarget; |
---|
150 | |
---|
151 | nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); |
---|
152 | |
---|
153 | setNewTargetGhost(nextTarget); |
---|
154 | } |
---|
155 | |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | |
---|