Changeset 10835
- Timestamp:
- Nov 23, 2015, 3:32:48 PM (9 years ago)
- Location:
- code/branches/hoverHS15
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hoverHS15/cmake/CompilerConfigGCC.cmake
r9686 r10835 72 72 ADD_COMPILER_FLAGS("-fno-omit-frame-pointer" CACHE) 73 73 74 74 75 # Enable non standard floating point optimisations 75 76 ADD_COMPILER_FLAGS("-ffast-math" CACHE) -
code/branches/hoverHS15/src/modules/hover/Hover.cc
r10787 r10835 38 38 #include "core/CoreIncludes.h" 39 39 40 #include <iostream> 41 #include <string> 42 #include <time.h> 43 #include <stdlib.h> 44 #include <memory.h> 45 #include <stdint.h> 46 #include <fstream> 47 48 40 49 namespace orxonox 41 50 { … … 43 52 int levelcode[10][10] = 44 53 { 45 { 0,0,0,0,0,0,0,0,0,0 }, // row 046 { 1,0,0,0,0,0,0,0,0,0 }, // row 047 { 1,0,0,0,0,0,0,0,0,0 }, // row 048 { 1,1,3,0,1,3,0,0,0,0 }, // row 049 { 1,0,3,2,3,2,0,0,0,0 }, // row 050 { 1,0,1,0,1,0,0,0,0,0 }, // row 051 { 1,2,2,0,0,0,0,0,0,0 }, // row 052 { 1,0,0,0,0,0,0,0,0,0 }, // row 053 { 1,0,0,0,0,0,0,0,1,0 },// row 154 { 1,0,0,0,0,0,0,1,2,0 } // row 254 { 0,0,0,0,0,0,0,0,0,0 }, 55 { 0,0,0,0,0,0,0,0,0,0 }, 56 { 0,0,0,0,0,0,0,0,0,0 }, 57 { 0,0,0,0,0,0,0,0,0,0 }, 58 { 0,0,0,0,0,0,0,0,0,0 }, 59 { 0,0,0,0,0,0,0,0,0,0 }, 60 { 0,0,0,0,0,0,0,0,0,0 }, 61 { 0,0,0,0,0,0,0,0,0,0 }, 62 { 0,0,0,0,0,0,0,0,0,0 }, 63 { 0,0,0,0,0,0,0,0,0,0 } 55 64 }; 56 65 66 const int NumCells = 10; 67 unsigned char* g_Maze = new unsigned char[ NumCells* NumCells ]; 68 69 // current traversing position 70 int g_PtX; 71 int g_PtY; 72 73 // return the current index in g_Maze 74 int Hover::CellIdx() 75 { 76 return g_PtX + NumCells * g_PtY; 77 } 78 79 80 int Hover::RandomInt() 81 { 82 return (rand() % NumCells); 83 } 84 85 int Hover::RandomInt4() 86 { 87 return (rand() % 4); 88 } 89 57 90 58 91 RegisterUnloadableClass(Hover); 92 93 94 95 96 97 59 98 60 99 Hover::Hover(Context* context) : Gametype(context) … … 76 115 if(firstTick) 77 116 { 117 std::fill( g_Maze, g_Maze + NumCells * NumCells, 0 ); 118 g_PtX=0; 119 g_PtY=0; 120 GenerateMaze(); 121 MazeOut(); 122 RenderMaze(); 123 LevelOut(); 78 124 firstTick = false; 79 125 80 126 for(int y=0; y<10; y++){ 81 127 for(int x=0; x<10; x++){ 82 83 128 switch(levelcode[y][x]){ 84 129 case 1: new HoverWall(origin_->getContext(), x+1, 10-y, 1); … … 96 141 97 142 98 //new HoverWall(origin_->getContext(), 1, 1, 1); 99 //new HoverWall(origin_->getContext(), 1, 1, 0); 143 //new HoverWall(origin_->getContext(), 1, 1, 1); //Rechts in Y Richtung 144 //new HoverWall(origin_->getContext(), 5, 6, 0); //Ueber in x richtung 145 //new HoverWall(origin_->getContext(), 5, 5, 0); //Ueber in x richtung 100 146 } 101 147 … … 122 168 GSLevel::startMainMenu(); 123 169 } 170 171 172 173 174 //////////////////////////////////////////////////////////////////////////// 175 176 177 // 0 1 2 3 4 5 6 7 8 178 // U R D L 179 int Heading_X[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 }; 180 int Heading_Y[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 }; 181 int Mask[9] = { 182 0, 183 eDirection_Down | eDirection_Down << 4, 184 eDirection_Left | eDirection_Left << 4, 185 0, 186 eDirection_Up | eDirection_Up << 4, 187 0, 188 0, 189 0, 190 eDirection_Right | eDirection_Right << 4 191 }; 192 193 194 //////////////////////////////////////////////////////////////////////////// 195 196 bool Hover::IsDirValid( eDirection Dir ) 197 { 198 int NewX = g_PtX + Heading_X[ Dir ]; 199 int NewY = g_PtY + Heading_Y[ Dir ]; 200 201 if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NumCells || NewY >= NumCells ) return false; 202 203 return !g_Maze[ NewX + NumCells * NewY ]; 204 } 205 206 eDirection Hover::GetDirection() 207 { 208 eDirection Dir = eDirection( 1 << RandomInt4() ); 209 210 while ( true ) 211 { 212 for ( int x = 0; x < 4; x++ ) 213 { 214 if ( IsDirValid( Dir ) ) { return eDirection( Dir ); } 215 216 Dir = eDirection( Dir << 1 ); 217 218 if ( Dir > eDirection_Left ) { Dir = eDirection_Up; } 219 } 220 221 Dir = eDirection( ( g_Maze[ CellIdx() ] & 0xf0 ) >> 4 ); 222 223 // nowhere to go 224 if ( !Dir ) return eDirection_Invalid; 225 226 g_PtX += Heading_X[ Dir ]; 227 g_PtY += Heading_Y[ Dir ]; 228 229 Dir = eDirection( 1 << RandomInt4() ); 230 } 231 } 232 233 void Hover::GenerateMaze() 234 { 235 int Cells = 0; 236 237 for ( eDirection Dir = GetDirection(); Dir != eDirection_Invalid; Dir = GetDirection() ) 238 { 239 // a progress indicator, kind of 240 // if ( ++Cells % 1000 == 0 ) std::cout << "."; 241 242 g_Maze[ CellIdx() ] |= Dir; 243 244 g_PtX += Heading_X[ Dir ]; 245 g_PtY += Heading_Y[ Dir ]; 246 247 g_Maze[ CellIdx() ] = Mask[ Dir ]; 248 } 249 250 std::cout << std::endl; 251 } 252 253 254 void Hover::MazeOut(){ 255 for ( int y = 0; y < NumCells; y++ ) 256 { 257 for ( int x = 0; x < NumCells; x++ ) 258 { 259 char v = g_Maze[ y * NumCells + x ]; 260 orxout()<<"["; 261 if ( ( v & eDirection_Up ) ) orxout()<<"U"; 262 else orxout()<<" "; 263 if ( ( v & eDirection_Right ) ) orxout()<<"R"; 264 else orxout()<<" "; 265 if ( ( v & eDirection_Down ) ) orxout()<<" "; 266 else orxout()<<" "; 267 if ( ( v & eDirection_Left ) ) orxout()<<" "; 268 else orxout()<<" "; 269 orxout()<<"]"; 270 } 271 orxout()<<endl; 272 } 273 274 } 275 276 void Hover::LevelOut(){ 277 for ( int y = 0; y < NumCells; y++ ) 278 { 279 for ( int x = 0; x < NumCells; x++ ) 280 { 281 /*orxout()<<"["; 282 if ( levelcode[x][y] < 2) orxout()<<"U"; 283 else orxout()<<" "; 284 if ( levelcode[x][y] % 2 == 0) orxout()<<"R"; 285 else orxout()<<" "; 286 287 orxout()<<" "; 288 orxout()<<" "; 289 orxout()<<"]";*/ 290 291 orxout()<<levelcode[x][y]; 292 } 293 orxout()<<endl; 294 } 295 296 297 298 } 299 300 void Hover::RenderMaze() 301 { 302 for ( int y = 0; y < NumCells; y++ ) 303 { 304 for ( int x = 0; x < NumCells; x++ ) 305 { 306 char v = g_Maze[ y * NumCells + x ]; 307 308 if ( !( v & eDirection_Up ) && y >0) levelcode[y][x] |= 2; 309 if ( !( v & eDirection_Right ) && x <9) levelcode[y][x] |= 1; 310 //if ( !( v & eDirection_Down ) && y>0) levelcode[x][y-1] += 2; 311 //if ( !( v & eDirection_Left ) && x>0) levelcode[x-1][y] += 1; 312 } 313 } 314 for ( int y = 3; y < 7; y++ ) 315 { 316 for ( int x = 3; x < 7; x++ ) 317 { 318 319 if(y == 3 && x != 7) 320 levelcode[y][x] &= 2; 321 else if (x == 7 && y != 3) 322 levelcode[y][x] &= 1; 323 else if(x != 7) 324 levelcode[y][x] = 0; 325 } 326 } 327 328 } 329 330 331 124 332 } -
code/branches/hoverHS15/src/modules/hover/Hover.h
r10751 r10835 58 58 #include "tools/Timer.h" 59 59 60 61 60 62 namespace orxonox 61 63 { 64 65 enum eDirection 66 { 67 eDirection_Invalid = 0, 68 eDirection_Up = 1, 69 eDirection_Right = 2, 70 eDirection_Down = 4, 71 eDirection_Left = 8 72 }; 62 73 63 74 class _HoverExport Hover : public Gametype … … 80 91 WeakPtr<HoverOrigin> origin_; 81 92 93 private: 94 int CellIdx(); 95 int RandomInt(); 96 int RandomInt4(); 97 98 99 bool IsDirValid( eDirection Dir ); 100 eDirection GetDirection(); 101 void GenerateMaze(); 102 void RenderMaze(); 103 void MazeOut(); 104 void LevelOut(); 105 106 82 107 }; 83 108 }
Note: See TracChangeset
for help on using the changeset viewer.