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 | int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); |
---|
48 | this->pointInFrontOfPlayer=frontPosition(); //getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
49 | //std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
50 | //std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
51 | |
---|
52 | Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); |
---|
53 | //std::cout<<pinkPos<<endl; |
---|
54 | |
---|
55 | //Stop, if target arrived |
---|
56 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
57 | this->ismoving = false; |
---|
58 | } |
---|
59 | |
---|
60 | //Move, if ghost hasn't arrived yet |
---|
61 | if(this->ismoving){ |
---|
62 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
63 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
64 | move(dt, actuelposition, velocity); |
---|
65 | } |
---|
66 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
67 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
68 | move(dt, actuelposition, velocity); |
---|
69 | } |
---|
70 | } |
---|
71 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
72 | //as long as the player has not started the game, |
---|
73 | //i.e. lastPlayerPastPoint is (0,0,0), pink pacman |
---|
74 | //cannot possibly move, because it needs the position |
---|
75 | //of the player to move accordingly |
---|
76 | |
---|
77 | this->ismoving=false; |
---|
78 | } |
---|
79 | else if(this->pointInFrontOfPlayer==Vector3(0,0,0)){ |
---|
80 | std::cout<<"arheeuuuu"<<endl; |
---|
81 | |
---|
82 | Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); |
---|
83 | |
---|
84 | setNewTargetGhost(getShortestPath(pinkPos, this->lastPlayerPassedPoint)); |
---|
85 | |
---|
86 | |
---|
87 | } |
---|
88 | //Check on which position the ghost has arrived and set new target |
---|
89 | else{ |
---|
90 | while(lockmove){}; |
---|
91 | lockmove = true; |
---|
92 | |
---|
93 | //Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); |
---|
94 | //std::cout<<pinkPos<<endl; |
---|
95 | |
---|
96 | //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); |
---|
97 | //this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
98 | |
---|
99 | //std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
100 | |
---|
101 | //std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
102 | nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint); |
---|
103 | |
---|
104 | |
---|
105 | lockmove=false; |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){ |
---|
118 | |
---|
119 | Vector3 nextTarget; |
---|
120 | |
---|
121 | std::cout<<this->actuelposition<<endl; |
---|
122 | std::cout<<pinkPosP<<endl; |
---|
123 | std::cout<<playerPos<<endl; |
---|
124 | std::cout<<pointToAvoidP11<<endl; |
---|
125 | std::cout<<this->getPlayerPos()<<endl; |
---|
126 | |
---|
127 | if(playerPos==pointToAvoidP11){ //SIGSEV if playerPos==pointToAvoidP11 otherwise |
---|
128 | nextTarget = getShortestPath(pinkPosP, playerPos); |
---|
129 | } |
---|
130 | /*else if(pinkPosP==pointToAvoidP11){ |
---|
131 | nextTarget=getShortestPath(pinkPosP, playerPos); |
---|
132 | }*/ |
---|
133 | else{ |
---|
134 | //bugs here |
---|
135 | std::cout<<"msjiowjqiq"<<endl; |
---|
136 | nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); |
---|
137 | } |
---|
138 | |
---|
139 | setNewTargetGhost(nextTarget); |
---|
140 | } |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | |
---|