Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.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.6 KB
Line 
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);
15
16        this->target_x=0;
17        this->target_z=15;
18        this->lastPlayerPassedPoint=Vector3(70,10,-135);
19         
20    }
21
22    /**
23    @brief
24        Method for creating a ghost through XML.
25    */
26    void PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
27    {
28        SUPER(PacmanPink, XMLPort, xmlelement, mode);
29    }
30
31
32    void PacmanPink::tick(float dt)
33    {
34        SUPER(PacmanGhost, tick, dt);
35
36        this->actuelposition = this->getPosition();
37
38
39        for(int u=0; u < 67; u++){//always check if player passed a point
40            if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
41            this->lastPlayerPassedPoint=possibleposition[u];
42                    }
43            }
44
45       
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)){
48                 this->ismoving = false;
49        }
50
51        //Move, if ghost hasn't arrived yet
52        if(this->ismoving){
53            if(!(abs(this->actuelposition.z-target_z)<0.5)) {
54                velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
55                move(dt, actuelposition, velocity);
56            }   
57            if(!(abs(this->actuelposition.x-target_x)<0.5)){
58                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
59                move(dt, actuelposition, velocity);
60            }
61        }
62        //Check on which position the ghost has arrived and set new target
63         else{
64            while(lockmove){};
65            lockmove = true;
66
67            Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
68           
69            int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
70            this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
71
72
73            nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint);
74
75
76
77            /*if(findPos(player.getPos(), player.lastPassedPoint)){
78                // if player is on a point, for simplicity go to it
79            Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint);
80            setNewTargetPink(nextMove);
81            }
82
83            else{ //if player is not on a point either go to next neighboor, or if no
84            //neighboor in player direction available, go to last point passed by player.
85
86            int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos());
87            //not in other sense!
88
89            Vector3[] neighboors;
90            findNeighboor(player.lastPassedPoint, neighboors);
91            //we need to create function that finds neighboors of player last point
92            //We can use and even should use the part of the tick random function
93            // that determines the neighboors. But array neighboor should be in form
94            // south-west-north-east respectively to array index.
95
96            for(int s=0; s < 4; s++){
97                //find next neighboor between player and player.lastPassedPoint
98                if((neighboors[s]!=NULL)&&(s==dir)){
99                        if(dir==0){
100                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
101                                setNewTargetPink(nextMove);
102                        }
103                        else if(dir==1){
104                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
105                                setNewTargetPink(nextMove);
106                        }
107                        else if(dir==2){
108                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
109                                setNewTargetPink(nextMove);
110                        }
111                        else{//last is default
112                                Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
113                                setNewTargetPink(nextMove);
114                                        }
115                        }
116                else{//if no further point after last player point possible
117                        //then simply go to this last point.
118                Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint);
119                        setNewTargetPink(nextMove);
120                        }
121
122                }
123
124            }*/
125            lockmove=false;
126
127        }
128
129
130
131
132
133        }
134
135
136
137    void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){
138   
139        Vector3 nextTarget;
140
141       nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
142   
143       setNewTargetGhost(nextTarget);
144    }
145
146}
147
148       
149
150       
Note: See TracBrowser for help on using the repository browser.