Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/PacmanCyan.cc @ 12321

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

continued Cyan implementation

File size: 3.5 KB
Line 
1#include "PacmanCyan.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(PacmanCyan);
12
13                PacmanCyan::PacmanCyan(Context* context) : PacmanGhost(context){
14
15        RegisterObject(PacmanCyan);
16        this->target_x=0;
17        this->target_z=15;
18        this->lastPlayerPassedPoint=Vector3(70,10,-135);
19
20        this->isPatrolling = false;
21         
22    }
23
24
25    /**
26    @brief
27        Method for creating a ghost through XML.
28    */
29    void PacmanCyan::XMLPort(Element& xmlelement, XMLPort::Mode mode)
30    {
31        SUPER(PacmanCyan, XMLPort, xmlelement, mode);
32    }
33
34
35
36    void PacmanCyan::tick(float dt)
37    {
38       
39        SUPER(PacmanGhost, tick, dt);
40
41        this->actuelposition = this->getPosition();
42
43
44
45        //Stop, if target arrived
46        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
47           
48                 this->ismoving = false;
49        }
50
51        //Move, if ghost hasn't arrived yet
52        if(this->ismoving){
53           
54            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
55                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
56                move(dt, actuelposition, velocity);
57            }   
58            if(!(abs(this->actuelposition.x-target_x)<0.5)){
59                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
60                move(dt, actuelposition, velocity);
61            }
62           
63        }
64
65        //Check on which position the ghost has arrived and set new target
66        else{
67
68            while(lockmove){};
69            lockmove = true;
70
71            Vector3 cyanPos=Vector3(this->target_x, 10, this->target_z);
72               
73            if(this->isPatrolling==false){
74                //we are not patrolling anymore, choose new patrol
75
76
77                this->nextPatrol();
78
79            }
80            else if((this->isPatrolling==true)&&(cyanPos!=this->goalPatrol)){
81
82
83
84            }
85            else if(cyanPos==this->goalPatrol){
86
87            }
88            else if(cyanPos==this->startPatrol){
89
90            }
91
92
93           
94
95
96            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
97        }
98       
99    }
100
101    void PacmanCyan::nextPatrol(){
102
103
104        int indexRand1=rand()%67;
105                while(indexRand1==44){
106                    //new try if index is that of the position in the middle
107                    indexRand1=rand()%67;
108                }
109
110                int indexRand2=rand()%67;
111                while((indexRand2==44)||(indexRand2==indexRand1)){
112                    //new try if 2nd index is same as first one or is index
113                    // of position in the middle
114
115                    indexRand2=rand()%67;
116                }
117
118
119
120
121              this->startPatrol =  possibleposition[indexRand1];
122              this->goalPatrol = possibleposition[indexRand2];
123
124              Vector3 nextMovement = getShortestPath(startPatrol, goalPatrol);
125
126    }
127
128
129
130
131        void PacmanCyan::nextMove( Vector3 cyanPosP, Vector3 playerPos){
132       
133        Vector3 nextTarget;
134
135           nextTarget = getShortestPath(cyanPosP, playerPos);
136       
137           setNewTargetGhost(nextTarget);
138        }
139
140    struct PacmanCyan::PatrolPosition{
141        //we need to check if PacmanCyan already passed the goal resp. start patrol point
142
143    public:
144
145        Vector3 position;
146        bool visitedPoint;
147
148        PatrolPosition(Vector3 positionP){
149            this->position=positionP;
150            visitedPoint=false;
151        }
152
153    };
154
155
156}
Note: See TracBrowser for help on using the repository browser.