Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Red Pacman seems to work even better

File size: 4.0 KB
RevLine 
[12304]1#include "PacmanRed.h"
2//#include "Pacman.h"
3
4#include "core/CoreIncludes.h"
5#include "BulletDynamics/Dynamics/btRigidBody.h"
6
[12316]7
8
[12304]9        namespace orxonox{
10
11                RegisterClass(PacmanRed);
12
13                PacmanRed::PacmanRed(Context* context) : PacmanGhost(context){
14
15        RegisterObject(PacmanRed);
[12316]16        this->target_x=0;
17        this->target_z=15;
18        this->lastPlayerPassedPoint=Vector3(70,10,-135);
[12304]19         
20    }
21
22
23    /**
24    @brief
25        Method for creating a ghost through XML.
26    */
27    void PacmanRed::XMLPort(Element& xmlelement, XMLPort::Mode mode)
28    {
29        SUPER(PacmanRed, XMLPort, xmlelement, mode);
30    }
31
[12316]32    /*void PacmanRed::setPlayerPos(Vector3 _playerPos)
33    {
34        this->playerPos = _playerPos;
35    }*/
36
37    bool PacmanRed::jeanfindpos(Vector3 one, Vector3 other){
38       if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true;
39        return false;
40        }
41
[12304]42    void PacmanRed::tick(float dt)
43    {
44        SUPER(PacmanGhost, tick, dt);
45
46        this->actuelposition = this->getPosition();
[12316]47
48        for(int u=0; u < 67; u++){//always check if player passed a point
49            if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
50            this->lastPlayerPassedPoint=possibleposition[u];
51                    }
52            }
53
[12304]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       
72        //Check on which position the ghost has arrived and set new target
73        else{
74
75            while(lockmove){};
76            lockmove = true;
77
78                //do red behavior
[12316]79            //Use target_x and target_z for position of red pacman
[12304]80
[12316]81            Vector3 redPos=Vector3(this->target_x, 10, this->target_z);
82            //nextMove(this->getPlayerPos(), redPos);
[12304]83
[12317]84            int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
[12304]85
[12317]86
[12316]87            if(this->actuelposition!=lastPlayerPassedPoint){
[12317]88               
89                std::cout<<this->getPlayerPos()<<endl;
[12316]90                std::cout<<this->lastPlayerPassedPoint<<endl;
[12317]91                std::cout<<getPointInFrontOfPacman(lastPlayerPassedPoint, directionV)<<endl;
[12316]92            nextMove(redPos, lastPlayerPassedPoint);
[12317]93            }
[12316]94            else{// red pacman is at lastPlayerPassedPoint
95
[12317]96            //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
[12316]97
[12317]98            Vector3 pointInFrontOfPlayer = getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
99
100            nextMove(redPos, pointInFrontOfPlayer);
101
102            //nextMove(this->getPlayerPos(), redPos);
103            }
104
105
[12316]106            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
[12304]107        }
108       
109    }
110
111
112        void PacmanRed::setNewTargetRed(Vector3 goalToGo){
113
114                                        this->target_x = goalToGo.x;
115                    this->target_z = goalToGo.z; 
116                    this->ismoving = true;
117        }
118
119
[12316]120        void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
121       
122        Vector3 nextTarget;
[12304]123
[12316]124           nextTarget = getShortestPath(redPosP, playerPos);
[12304]125       
[12316]126           setNewTargetRed(nextTarget);
[12304]127        }
128
129
130
131    //save last checkpoint crossed by player
132    /*
133        void PacmanGelb::tick(float dt){ //last passed point of player
134            for(int u=0; u < 67; u++){
135            if(findpos(this->getPosition(), possibleposition[u])){
136            this->lastPassedPoint=possibleposition[u];
137                    }
138                }
139        }
140    */
141
142}
Note: See TracBrowser for help on using the repository browser.