Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

PacmanPink implementation, but lots of SIGSEGV

File size: 4.5 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(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
85        //Check on which position the ghost has arrived and set new target
86        else{
87            std::cout<<"LemanExpress3"<<endl;
88
89            while(lockmove){};
90            lockmove = true;
91
92                //do red behavior
93            //Use target_x and target_z for position of red pacman
94
95            Vector3 redPos=Vector3(this->target_x, 10, this->target_z);
96            //nextMove(this->getPlayerPos(), redPos);
97
98            int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
99            this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
100
101
102            if(!findpos(this->actuelposition, lastPlayerPassedPoint)){
103               
104                /*std::cout<<this->getPlayerPos()<<endl;
105                std::cout<<this->lastPlayerPassedPoint<<endl;
106                std::cout<<this->pointInFrontOfPlayer<<endl;
107                std::cout<<this->actuelposition<<endl;*/
108            nextMove(redPos, lastPlayerPassedPoint);
109            std::cout<<"hiuddi"<<endl;
110            }
111            else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint
112
113                /*std::cout<<"dhdidjop"<<endl;
114                std::cout<<this->getPlayerPos()<<endl;
115                std::cout<<this->lastPlayerPassedPoint<<endl;
116                std::cout<<this->pointInFrontOfPlayer<<endl;
117                std::cout<<this->actuelposition<<endl;*/
118
119                nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer);
120                std::cout<<"ogslodm"<<endl;
121            }
122
123
124            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
125        }
126       
127    }
128
129
130        void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
131       
132        Vector3 nextTarget;
133
134           nextTarget = getShortestPath(redPosP, playerPos);
135       
136           setNewTargetGhost(nextTarget);
137        }
138
139
140
141    //save last checkpoint crossed by player
142    /*
143        void PacmanGelb::tick(float dt){ //last passed point of player
144            for(int u=0; u < 67; u++){
145            if(findpos(this->getPosition(), possibleposition[u])){
146            this->lastPassedPoint=possibleposition[u];
147                    }
148                }
149        }
150    */
151
152}
Note: See TracBrowser for help on using the repository browser.