Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Improved formatting and added some comments to make the code more precise

File size: 3.1 KB
RevLine 
[12304]1#include "PacmanRed.h"
2
3#include "core/CoreIncludes.h"
4#include "BulletDynamics/Dynamics/btRigidBody.h"
5
[12316]6
7
[12304]8        namespace orxonox{
9
10                RegisterClass(PacmanRed);
11
12                PacmanRed::PacmanRed(Context* context) : PacmanGhost(context){
13
14        RegisterObject(PacmanRed);
[12316]15        this->target_x=0;
16        this->target_z=15;
[12357]17        this->lastPlayerPassedPoint=Vector3(0,0,0); 
[12318]18        this->isNearPlayer=false;
[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
32    void PacmanRed::tick(float dt)
33    {
34        SUPER(PacmanGhost, tick, dt);
35
36        this->actuelposition = this->getPosition();
[12316]37
38        for(int u=0; u < 67; u++){//always check if player passed a point
[12357]39           
[12323]40                if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
[12357]41                   
[12323]42                this->lastPlayerPassedPoint=possibleposition[u];
[12357]43                            }   
[12316]44            }
45
[12304]46        //Stop, if target arrived
47        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
[12357]48           
[12304]49                 this->ismoving = false;
50        }
51
52        //Move, if ghost hasn't arrived yet
53        if(this->ismoving){
[12357]54           
[12304]55            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
56                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
57                move(dt, actuelposition, velocity);
58            }   
59            if(!(abs(this->actuelposition.x-target_x)<0.5)){
60                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
61                move(dt, actuelposition, velocity);
62            }
[12357]63       
[12304]64        }
[12322]65        else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){
66            //as long as the player has not started the game,
67            //i.e. lastPlayerPastPoint is (0,0,0), red pacman
68            //cannot possibly move, because it needs the position
69            //of the player to move accordingly
[12318]70
[12322]71            this->ismoving=false;
72        }
73
[12304]74        //Check on which position the ghost has arrived and set new target
75        else{
76
77            while(lockmove){};
78            lockmove = true;
79
80                //do red behavior
[12316]81            //Use target_x and target_z for position of red pacman
[12304]82
[12316]83            Vector3 redPos=Vector3(this->target_x, 10, this->target_z);
[12357]84            this->pointInFrontOfPlayer=frontPosition(); 
[12304]85
[12318]86            if(!findpos(this->actuelposition, lastPlayerPassedPoint)){
[12317]87               
[12316]88            nextMove(redPos, lastPlayerPassedPoint);
[12317]89            }
[12318]90            else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint
[12316]91
[12357]92            nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer); 
[12317]93            }
94
[12316]95            lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
[12304]96        }
97       
98    }
99
100
[12316]101        void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
102       
103        Vector3 nextTarget;
[12304]104
[12325]105        if(redPosP!=playerPos){
[12316]106           nextTarget = getShortestPath(redPosP, playerPos);
[12325]107       setNewTargetGhost(nextTarget);
108        }
[12304]109        }
110
111}
Note: See TracBrowser for help on using the repository browser.