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 | this->pointInFrontOfPlayer=Vector3(0,0,0); |
---|
20 | |
---|
21 | } |
---|
22 | |
---|
23 | /** |
---|
24 | @brief |
---|
25 | Method for creating a ghost through XML. |
---|
26 | */ |
---|
27 | void PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
28 | { |
---|
29 | SUPER(PacmanPink, XMLPort, xmlelement, mode); |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | void PacmanPink::tick(float dt) |
---|
34 | { |
---|
35 | SUPER(PacmanGhost, tick, dt); |
---|
36 | |
---|
37 | this->actuelposition = this->getPosition(); |
---|
38 | //std::cout<<this->actuelposition<<endl; |
---|
39 | |
---|
40 | |
---|
41 | for(int u=0; u < 67; u++){//always check if player passed a point |
---|
42 | if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ |
---|
43 | this->lastPlayerPassedPoint=possibleposition[u]; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | this->pointInFrontOfPlayer=frontPosition(); //getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
48 | |
---|
49 | Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); |
---|
50 | |
---|
51 | //Stop, if target arrived |
---|
52 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
53 | this->ismoving = false; |
---|
54 | } |
---|
55 | |
---|
56 | //Move, if ghost hasn't arrived yet |
---|
57 | if(this->ismoving){ |
---|
58 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
59 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
60 | move(dt, actuelposition, velocity); |
---|
61 | } |
---|
62 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
63 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
64 | move(dt, actuelposition, velocity); |
---|
65 | } |
---|
66 | } |
---|
67 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
68 | //as long as the player has not started the game, |
---|
69 | //i.e. lastPlayerPastPoint is (0,0,0), pink pacman |
---|
70 | //cannot possibly move, because it needs the position |
---|
71 | //of the player to move accordingly |
---|
72 | |
---|
73 | this->ismoving=false; |
---|
74 | } |
---|
75 | else if(this->pointInFrontOfPlayer==Vector3(0,0,0)){ |
---|
76 | std::cout<<"arheeuuuu"<<endl; |
---|
77 | |
---|
78 | Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); |
---|
79 | |
---|
80 | setNewTargetGhost(getShortestPath(pinkPos, this->lastPlayerPassedPoint)); |
---|
81 | |
---|
82 | |
---|
83 | } |
---|
84 | //Check on which position the ghost has arrived and set new target |
---|
85 | else{ |
---|
86 | while(lockmove){}; |
---|
87 | lockmove = true; |
---|
88 | |
---|
89 | //this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
90 | |
---|
91 | nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint); |
---|
92 | |
---|
93 | |
---|
94 | lockmove=false; |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){ |
---|
107 | |
---|
108 | Vector3 nextTarget; |
---|
109 | |
---|
110 | /*std::cout<<this->actuelposition<<endl; |
---|
111 | std::cout<<pinkPosP<<endl; |
---|
112 | std::cout<<playerPos<<endl; |
---|
113 | std::cout<<pointToAvoidP11<<endl; |
---|
114 | std::cout<<this->getPlayerPos()<<endl;*/ |
---|
115 | std::cout<<playerPos<<endl; |
---|
116 | std::cout<<"kok"<<endl; |
---|
117 | |
---|
118 | if(playerPos==pointToAvoidP11){ //SIGSEV if playerPos==pointToAvoidP11 otherwise |
---|
119 | nextTarget = getShortestPath(pinkPosP, playerPos); |
---|
120 | } |
---|
121 | /*else if(pinkPosP==pointToAvoidP11){ |
---|
122 | nextTarget=getShortestPath(pinkPosP, playerPos); |
---|
123 | }*/ |
---|
124 | else if((playerPos==Vector3(-70,10,-35))/*||(playerPos==Vector3(-20,10,-35))||(playerPos==Vector3(0,10,-35))*/){ |
---|
125 | //nextTarget=pinkPosP; |
---|
126 | nextTarget=getShortestPath(pinkPosP, Vector3(-70,10,-35)); |
---|
127 | std::cout<<"ChaillyVillage"<<endl; |
---|
128 | } |
---|
129 | /*else if((playerPos==Vector3(-70,10,-35))&&(pinkPosP==Vector3(-70,10,60))/*||(playerPos==Vector3(-20,10,-35))||(playerPos==Vector3(0,10,-35))){ |
---|
130 | //nextTarget=pinkPosP; |
---|
131 | nextTarget=getShortestPath(pinkPosP, Vector3(-70,10,-35)); |
---|
132 | std::cout<<"ChaillyVillage"<<endl; |
---|
133 | }*/ |
---|
134 | else{ |
---|
135 | //bugs here |
---|
136 | std::cout<<pinkPosP<<endl; |
---|
137 | nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); |
---|
138 | } |
---|
139 | std::cout<<nextTarget<<endl; |
---|
140 | setNewTargetGhost(nextTarget); |
---|
141 | } |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | |
---|