Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc @ 12322

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

continued brown and cyan pacman. Pink pacman still causes SIGSEV

File size: 4.9 KB
Line 
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(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
48            this->lastPlayerPassedPoint=possibleposition[u];
49                    }
50            }
51
52
53        /*if((playerFindPos(this->actuelposition, this->getPlayerPos()))&&(isNearPlayer==false)){
54            isNearPlayer=true;
55            setNewTargetRed(this->getPlayerPos());
56        }
57        else if (!(playerFindPos(this->actuelposition, this->getPlayerPos())&&(isNearPlayer==true))){
58            isNearPlayer=false;
59            setNewTargetRed(this->pointInFrontOfPlayer);
60        }*/
61
62
63
64
65        //Stop, if target arrived
66        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
67            //std::cout<<"LemanExpress1"<<endl;
68                 this->ismoving = false;
69        }
70
71        //Move, if ghost hasn't arrived yet
72        if(this->ismoving){
73            //std::cout<<"LemanExpress2"<<endl;
74            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
75                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
76                move(dt, actuelposition, velocity);
77            }   
78            if(!(abs(this->actuelposition.x-target_x)<0.5)){
79                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
80                move(dt, actuelposition, velocity);
81            }
82            //std::cout<<"LemanExpress4"<<endl;
83        }
84        else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){
85            //as long as the player has not started the game,
86            //i.e. lastPlayerPastPoint is (0,0,0), red pacman
87            //cannot possibly move, because it needs the position
88            //of the player to move accordingly
89
90            this->ismoving=false;
91        }
92
93        //Check on which position the ghost has arrived and set new target
94        else{
95            std::cout<<"LemanExpress3"<<endl;
96
97            while(lockmove){};
98            lockmove = true;
99
100                //do red behavior
101            //Use target_x and target_z for position of red pacman
102
103            Vector3 redPos=Vector3(this->target_x, 10, this->target_z);
104            //nextMove(this->getPlayerPos(), redPos);
105
106            int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
107            this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
108
109
110            if(!findpos(this->actuelposition, lastPlayerPassedPoint)){
111               
112                /*std::cout<<this->getPlayerPos()<<endl;
113                std::cout<<this->lastPlayerPassedPoint<<endl;
114                std::cout<<this->pointInFrontOfPlayer<<endl;
115                std::cout<<this->actuelposition<<endl;*/
116            nextMove(redPos, lastPlayerPassedPoint);
117            std::cout<<"hiuddi"<<endl;
118            }
119            else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint
120
121                /*std::cout<<"dhdidjop"<<endl;
122                std::cout<<this->getPlayerPos()<<endl;
123                std::cout<<this->lastPlayerPassedPoint<<endl;
124                std::cout<<this->pointInFrontOfPlayer<<endl;
125                std::cout<<this->actuelposition<<endl;*/
126
127                nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer);
128                std::cout<<"ogslodm"<<endl;
129            }
130
131
132            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
133        }
134       
135    }
136
137
138        void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
139       
140        Vector3 nextTarget;
141
142           nextTarget = getShortestPath(redPosP, playerPos);
143       
144           setNewTargetGhost(nextTarget);
145        }
146
147
148
149    //save last checkpoint crossed by player
150    /*
151        void PacmanGelb::tick(float dt){ //last passed point of player
152            for(int u=0; u < 67; u++){
153            if(findpos(this->getPosition(), possibleposition[u])){
154            this->lastPassedPoint=possibleposition[u];
155                    }
156                }
157        }
158    */
159
160}
Note: See TracBrowser for help on using the repository browser.