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 | |
---|
34 | namespace 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 | PacmanGhostRed::PacmanGhostController(Context* context) : Controller(context) |
---|
46 | { |
---|
47 | RegisterObject(PacmanGhostController); |
---|
48 | bool ismoving = false; |
---|
49 | float reltarget_x; |
---|
50 | float reltarget_z; |
---|
51 | Vector3& actuelposition; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | @brief |
---|
56 | Destructor. |
---|
57 | */ |
---|
58 | PacmanGhostController::~PacmanGhostController() |
---|
59 | { |
---|
60 | |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | @brief |
---|
65 | The controlling happens here. This method defines what the controller has to do each tick. |
---|
66 | @param dt |
---|
67 | The duration of the tick. |
---|
68 | */ |
---|
69 | void PacmanGhostController::tick(float dt) |
---|
70 | { |
---|
71 | /* NOTE: Ugly hack by Sandro to make the tutorial work for the moment. |
---|
72 | * This will be reverted once the framework update is complete |
---|
73 | */ |
---|
74 | //AutonomousDrone *myDrone = static_cast<AutonomousDrone*>(this->getControllableEntity()); |
---|
75 | ObjectList<PacmanGhost> objectList; |
---|
76 | ObjectList<PacmanGhost>::iterator it = objectList.begin(); |
---|
77 | PacmanGhost* myDrone = *it; |
---|
78 | |
---|
79 | if (myGhost != nullptr) |
---|
80 | { |
---|
81 | |
---|
82 | actuelposition = myGhost.getPosition(); |
---|
83 | |
---|
84 | if(actuelposition.x = reltarget_x && actuelposition.z = reltarget_z){ |
---|
85 | ismoving = false; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | if(ismoving){ |
---|
91 | moveRightLeft(); |
---|
92 | moveFrontBack(); |
---|
93 | } |
---|
94 | |
---|
95 | else{ |
---|
96 | |
---|
97 | //hashtable |
---|
98 | |
---|
99 | int random = rand(); |
---|
100 | |
---|
101 | switch(actuelposition) { |
---|
102 | case 1: if(random % 4 == 0){ |
---|
103 | reltarget_x = 250; |
---|
104 | reltarget_z = 0; |
---|
105 | } |
---|
106 | else if(random % 4 == 1){ |
---|
107 | reltarget_x = 0; |
---|
108 | reltarget_z = 250; |
---|
109 | } |
---|
110 | else if(random % 4 == 2){ |
---|
111 | reltarget_x = 0; |
---|
112 | reltarget_z = -250; |
---|
113 | } |
---|
114 | else if(random % 4 == 3){ |
---|
115 | reltarget_x = -250; |
---|
116 | reltarget_z = 0; |
---|
117 | } |
---|
118 | moving = true; |
---|
119 | case 2: |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|