Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Red Pacman seems to work partially

File size: 3.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(70,10,-135);
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
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
42    void PacmanRed::tick(float dt)
43    {
44        SUPER(PacmanGhost, tick, dt);
45
46        this->actuelposition = this->getPosition();
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
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
79            //Use target_x and target_z for position of red pacman
80
81            Vector3 redPos=Vector3(this->target_x, 10, this->target_z);
82            //nextMove(this->getPlayerPos(), redPos);
83
84
85            if(this->actuelposition!=lastPlayerPassedPoint){
86                //std::cout<<this->target_x<<" "<<this->target_z<<endl;
87                std::cout<<redPos<<endl;
88                std::cout<<this->lastPlayerPassedPoint<<endl;
89                //getShortestPath(Vector3(-215,10,-195),Vector3(70,10,-135));
90                //getShortestPath(redPos, lastPlayerPassedPoint);
91            nextMove(redPos, lastPlayerPassedPoint);
92            }/*
93            else{// red pacman is at lastPlayerPassedPoint
94            nextMove(this->getPlayerPos(), redPos);
95            }*/
96
97            //setNewTargetRed(Vector3(70,10,-85));
98            //std::cout<<this->target_x<<" "<<target_z<<endl;
99            //std::cout<<"meuh"<<endl;
100            //std::cout<<this->actuelposition;
101
102            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
103        }
104       
105    }
106
107
108        void PacmanRed::setNewTargetRed(Vector3 goalToGo){
109
110                                        this->target_x = goalToGo.x;
111                    this->target_z = goalToGo.z; 
112                    this->ismoving = true;
113        }
114
115
116        void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
117       
118        Vector3 nextTarget;
119
120           nextTarget = getShortestPath(redPosP, playerPos);
121       
122           setNewTargetRed(nextTarget);
123        }
124
125
126
127    //save last checkpoint crossed by player
128    /*
129        void PacmanGelb::tick(float dt){ //last passed point of player
130            for(int u=0; u < 67; u++){
131            if(findpos(this->getPosition(), possibleposition[u])){
132            this->lastPassedPoint=possibleposition[u];
133                    }
134                }
135        }
136    */
137
138}
Note: See TracBrowser for help on using the repository browser.