Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_FS19/src/modules/pacman/PacmanPink.cc @ 12408

Last change on this file since 12408 was 12408, checked in by wiesep, 5 years ago

Merged 3DPacman_FS19

File size: 3.3 KB
RevLine 
[12304]1       
2#include "PacmanPink.h"
3
4#include "core/CoreIncludes.h"
5#include "BulletDynamics/Dynamics/btRigidBody.h"
6
7       
8namespace orxonox{
9
10        RegisterClass(PacmanPink);
11
12                PacmanPink::PacmanPink(Context* context) : PacmanGhost(context){
13
14        RegisterObject(PacmanPink);
[12319]15
16        this->target_x=0;
17        this->target_z=15;
[12357]18        this->lastPlayerPassedPoint=Vector3(0,0,0); 
[12324]19        this->pointInFrontOfPlayer=Vector3(0,0,0);
[12304]20         
21    }
22
23    /**
24    @brief
25        Method for creating a ghost through XML.
26    */
27    void PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
28    {
29        SUPER(PacmanPink, XMLPort, xmlelement, mode);
30    }
31
32
33    void PacmanPink::tick(float dt)
34    {
35        SUPER(PacmanGhost, tick, dt);
36        this->actuelposition = this->getPosition();
[12319]37
38        for(int u=0; u < 67; u++){//always check if player passed a point
[12324]39            if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ 
40                    this->lastPlayerPassedPoint=possibleposition[u];       
41                }
[12319]42            }
43
[12357]44        this->pointInFrontOfPlayer=frontPosition(); 
[12326]45        Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
[12304]46       
47        //Stop, if target arrived
48        if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
49                 this->ismoving = false;
50        }
51
52        //Move, if ghost hasn't arrived yet
53        if(this->ismoving){
54            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
55                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
56                move(dt, actuelposition, velocity);
57            }   
58            if(!(abs(this->actuelposition.x-target_x)<0.5)){
59                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
60                move(dt, actuelposition, velocity);
61            }
62        }
[12322]63        else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){
64            //as long as the player has not started the game,
65            //i.e. lastPlayerPastPoint is (0,0,0), pink pacman
66            //cannot possibly move, because it needs the position
67            //of the player to move accordingly
68
69            this->ismoving=false;
70        }
[12324]71        else if(this->pointInFrontOfPlayer==Vector3(0,0,0)){
72
73            Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
74            setNewTargetGhost(getShortestPath(pinkPos, this->lastPlayerPassedPoint));
75
76        }
[12304]77        //Check on which position the ghost has arrived and set new target
78         else{
79            while(lockmove){};
80            lockmove = true;
[12319]81            nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint);
82            lockmove=false;
[12304]83        }
84        }
85
86
87
[12319]88    void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){
89   
90        Vector3 nextTarget;
[12304]91
[12325]92        if(playerPos==pointToAvoidP11){ //SIGSEV if playerPos==pointToAvoidP11 otherwise
[12324]93            nextTarget = getShortestPath(pinkPosP, playerPos);
94        }
[12357]95        else if(playerPos==Vector3(-70,10,-35)){
96           
[12338]97        nextTarget=getShortestPath(pinkPosP, Vector3(-70,10,-35));
[12357]98       
[12338]99        }
[12357]100        else{   
101       
[12324]102        nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
103        }
[12357]104       
[12319]105       setNewTargetGhost(nextTarget);
106    }
[12304]107
[12319]108}
[12304]109
110       
111
112       
Note: See TracBrowser for help on using the repository browser.