Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhostController.cc @ 11843

Last change on this file since 11843 was 11843, checked in by dreherm, 6 years ago

First try for moving ghosts

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oli Scheuss
24 *   Co-authors:
25 *      Damian 'Mozork' Frick
26 *
27 */
28
29#include "PacmanGhostController.h"
30
31#include "PacmanGhost.h"
32#include "util/Math.h"
33
34namespace orxonox
35{
36    // Create the factory for the drone controller.
37        RegisterClass(PacmanGhostController);
38
39    /**
40    @brief
41        Constructor.
42    @param context
43        The context of this object.
44    */
45    PacmanGhostController::PacmanGhostController(Context* context) : Controller(context)
46    {
47        RegisterObject(PacmanGhostController);
48
49        PacmanGhost* myGhost = nullptr;
50        this->actuelposition = myGhost.getPosition();
51
52        bool ismoving = false;
53        this->target_x = actuelposition.x;
54        this->target_z = actuelposition.z;     
55    }
56
57    void PacmanGhostController::setGhost(PacmanGhost ghost){
58        this->myGhost = ghost;
59    }
60
61    /**
62    @brief
63        Destructor.
64    */
65    PacmanGhostController::~PacmanGhostController()
66    {
67
68    }
69
70
71    static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)];
72    /**
73    @brief
74        The controlling happens here. This method defines what the controller has to do each tick.
75    @param dt
76        The duration of the tick.
77    */
78    void PacmanGhostController::tick(float dt)
79    {
80        /* NOTE: Ugly hack by Sandro to make the tutorial work for the moment.
81         * This will be reverted once the framework update is complete
82         */
83        //AutonomousDrone *myDrone = static_cast<AutonomousDrone*>(this->getControllableEntity());
84        ObjectList<PacmanGhost> objectList;
85        ObjectList<PacmanGhost>::iterator it = objectList.begin();
86        PacmanGhost* myDrone = *it;
87
88        if (this->myGhost != nullptr)
89        {
90
91            this->actuelposition = this->myGhost.getPosition();
92
93        if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){
94            this->ismoving = false;
95        }
96
97        if(this->ismoving){
98            if(!((this->actuelposition.z-target_z)<0.1))
99                moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100);
100            if(!((this->actuelposition.x-target_x)<0.1))
101              moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small
102        }
103       
104        else{ //Check on which position ghost is
105            if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){
106                this->target_x = possibleposition[1].x;
107                this->target_z = possibleposition[1].z; 
108                this->ismoving = true;
109            }
110            else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){
111                this->target_x = 0
112                this->target_z = 
113                this->ismoving = true;
114            }
115            else{
116            }     
117            } //End of Position table
118
119        }
120    }
121
122}
Note: See TracBrowser for help on using the repository browser.