- Timestamp:
- Jan 4, 2016, 11:23:59 AM (9 years ago)
- Location:
- code/branches/presentationHS15/src/modules/hover
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationHS15/src/modules/hover/CMakeLists.txt
r11026 r11035 1 1 SET_SOURCE_FILES(Hover_SRC_FILES 2 Hover.cc 3 HoverShip.cc 4 HoverWall.cc 5 HoverOrigin.cc 6 TimeHUD.cc 7 FlagHUD.cc 8 HoverFlag.cc 2 Hover.cc 3 HoverShip.cc 4 HoverWall.cc 5 HoverOrigin.cc 6 HoverFlag.cc 7 TimeHUD.cc 8 FlagHUD.cc 9 MazeGenerator.cc 9 10 ) 10 11 … … 13 14 FIND_HEADER_FILES 14 15 LINK_LIBRARIES 16 orxonox 15 17 objects 16 orxonox17 18 overlays 18 19 SOURCE_FILES ${Hover_SRC_FILES} -
code/branches/presentationHS15/src/modules/hover/Hover.cc
r11026 r11035 32 32 */ 33 33 34 //#include "orxonox/worldentities/pawns/SpaceShip.h"35 34 #include "Hover.h" 36 35 37 36 #include "HoverWall.h" 38 37 #include "HoverFlag.h" 38 #include "MazeGenerator.h" 39 39 #include "core/CoreIncludes.h" 40 41 #include <iostream>42 #include <string>43 #include <time.h>44 #include <stdlib.h>45 #include <memory.h>46 #include <stdint.h>47 #include <fstream>48 #include <vector>49 40 50 41 namespace orxonox 51 42 { 52 bool firstTick = true;53 54 //Levelcode represents the pitch: It's a 10x10 field.55 // 1 represents a Wall on the right side of this square56 // 2 represents a Wall on the top of this square57 // 3 represents 2 and 1 at the same time58 // Note: the levelcode is generated from the Maze-Generator functions at the beginning of the game59 int levelcode[10][10] =60 {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 },64 { 0,0,0,0,0,0,0,0,0,0 },65 { 0,0,0,0,0,0,0,0,0,0 },66 { 0,0,0,0,0,0,0,0,0,0 },67 { 0,0,0,0,0,0,0,0,0,0 },68 { 0,0,0,0,0,0,0,0,0,0 },69 { 0,0,0,0,0,0,0,0,0,0 },70 { 0,0,0,0,0,0,0,0,0,0 }71 };72 73 const int NumCells = 10;74 unsigned char* g_Maze = new unsigned char[ NumCells* NumCells ];75 76 // current traversing position77 int g_PtX;78 int g_PtY;79 80 // return the current index in g_Maze81 int Hover::CellIdx()82 {83 return g_PtX + NumCells * g_PtY;84 }85 86 87 int Hover::RandomInt()88 {89 return (rand() % NumCells);90 }91 92 int Hover::RandomInt4()93 {94 return (rand() % 4);95 }96 97 98 43 RegisterUnloadableClass(Hover); 99 100 101 102 103 104 105 44 106 45 Hover::Hover(Context* context) : Gametype(context) … … 108 47 109 48 RegisterObject(Hover); 49 50 this->origin_ = NULL; 51 this->flags_ = 1; 52 this->firstTick_ = true; 53 110 54 this->setHUDTemplate("HoverHUD"); 111 55 } 112 56 113 114 115 57 void Hover::tick(float dt) 116 58 { 117 118 59 SUPER(Hover, tick, dt); 119 60 61 if(this->firstTick_) 62 { 63 this->firstTick_ = false; 120 64 65 MazeGenerator generator; 66 generator.generateMaze(); 67 generator.renderMaze(); 121 68 122 123 if(firstTick) 124 { 125 126 std::fill( g_Maze, g_Maze + NumCells * NumCells, 0 ); 127 g_PtX=0; 128 g_PtY=0; 129 GenerateMaze(); 130 RenderMaze(); 131 firstTick = false; 69 const int NUM_CELLS = generator.getNumCells(); 70 int* levelcode = generator.getLevelcode(); 132 71 133 72 //Outer Walls 134 for(int i = 0; i< 10; i++){73 for(int i = 0; i<NUM_CELLS; i++){ 135 74 new HoverWall(origin_->getContext(), 0, i+1, 1); 136 new HoverWall(origin_->getContext(), 10, i+1, 1);75 new HoverWall(origin_->getContext(), NUM_CELLS, i+1, 1); 137 76 new HoverWall(origin_->getContext(), i+1, 0, 2); 138 new HoverWall(origin_->getContext(), i+1, 10, 2);77 new HoverWall(origin_->getContext(), i+1, NUM_CELLS, 2); 139 78 } 140 79 141 80 //Generate inner Walls according to levelcode 142 for(int y=0; y< 10; y++){143 for(int x=0; x< 10; x++){144 switch(levelcode[ y][x]){145 case 1: new HoverWall(origin_->getContext(), x+1, 10-y, 1);81 for(int y=0; y<NUM_CELLS; y++){ 82 for(int x=0; x<NUM_CELLS; x++){ 83 switch(levelcode[ y * NUM_CELLS + x ]){ 84 case 1: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1); 146 85 break; 147 case 3: new HoverWall(origin_->getContext(), x+1, 10-y, 1);148 case 2: new HoverWall(origin_->getContext(), x+1, 10-y, 0);86 case 3: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1); 87 case 2: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 0); 149 88 default: break; 150 89 } 151 152 153 154 90 } 155 91 } … … 157 93 //Generate 5 flags randomly 158 94 for ( int i = 0; i < 5; i++ ) 159 flagVector .push_back(new HoverFlag(origin_->getContext(), rand()%10, rand()%10));95 flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%NUM_CELLS, rand()%NUM_CELLS)); 160 96 161 Flags_ = flagVector.size();97 flags_ = flagVector_.size(); 162 98 163 99 }//firsttick end 164 100 165 101 // Check if ship collided with one of the flags 166 for ( unsigned int i = 0; i < flagVector .size(); i++ ){167 if(flagVector [i]->getCollided()){168 flagVector [i]->destroyLater();169 flagVector .erase (flagVector.begin()+i);102 for ( unsigned int i = 0; i < flagVector_.size(); i++ ){ 103 if(flagVector_[i]->getCollided()){ 104 flagVector_[i]->destroyLater(); 105 flagVector_.erase (flagVector_.begin()+i); 170 106 } 171 107 } 172 Flags_ = flagVector.size(); 173 174 175 108 flags_ = flagVector_.size(); 176 109 } 177 110 178 111 int Hover::getFlags() 179 112 { 180 181 113 // Call start for the parent class. 182 return Flags_;114 return flags_; 183 115 } 184 116 185 117 void Hover::start() 186 118 { 187 188 119 // Call start for the parent class. 189 120 Gametype::start(); 190 191 121 } 192 193 122 194 123 void Hover::end() … … 200 129 GSLevel::startMainMenu(); 201 130 } 202 203 204 205 206 // Some definitions for the Maze-Generator207 208 // 0 1 2 3 4 5 6 7 8209 // U R D L210 int Heading_X[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 };211 int Heading_Y[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 };212 int Mask[9] = {213 0,214 eDirection_Down | eDirection_Down << 4,215 eDirection_Left | eDirection_Left << 4,216 0,217 eDirection_Up | eDirection_Up << 4,218 0,219 0,220 0,221 eDirection_Right | eDirection_Right << 4222 };223 224 225 /**226 @brief227 Checks if Direction is valid (for Maze-Generator)228 */229 bool Hover::IsDirValid( eDirection Dir )230 {231 int NewX = g_PtX + Heading_X[ Dir ];232 int NewY = g_PtY + Heading_Y[ Dir ];233 234 if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NumCells || NewY >= NumCells ) return false;235 236 return !g_Maze[ NewX + NumCells * NewY ];237 }238 239 /**240 @brief241 Generates new Direction (for Maze-Generator)242 */243 eDirection Hover::GetDirection()244 {245 eDirection Dir = eDirection( 1 << RandomInt4() );246 247 while ( true )248 {249 for ( int x = 0; x < 4; x++ )250 {251 if ( IsDirValid( Dir ) ) { return eDirection( Dir ); }252 253 Dir = eDirection( Dir << 1 );254 255 if ( Dir > eDirection_Left ) { Dir = eDirection_Up; }256 }257 258 Dir = eDirection( ( g_Maze[ CellIdx() ] & 0xf0 ) >> 4 );259 260 // nowhere to go261 if ( !Dir ) return eDirection_Invalid;262 263 g_PtX += Heading_X[ Dir ];264 g_PtY += Heading_Y[ Dir ];265 266 Dir = eDirection( 1 << RandomInt4() );267 }268 }269 270 /**271 @brief272 Generates a Maze (for Maze-Generator)273 */274 void Hover::GenerateMaze()275 {276 277 for ( eDirection Dir = GetDirection(); Dir != eDirection_Invalid; Dir = GetDirection() )278 {279 g_Maze[ CellIdx() ] |= Dir;280 281 g_PtX += Heading_X[ Dir ];282 g_PtY += Heading_Y[ Dir ];283 284 g_Maze[ CellIdx() ] = Mask[ Dir ];285 }286 }287 288 /**289 @brief290 Print Maze (for Debugging only)291 */292 void Hover::MazeOut(){293 for ( int y = 0; y < NumCells; y++ )294 {295 for ( int x = 0; x < NumCells; x++ )296 {297 char v = g_Maze[ y * NumCells + x ];298 orxout()<<"[";299 if ( ( v & eDirection_Up ) ) orxout()<<"U";300 else orxout()<<" ";301 if ( ( v & eDirection_Right ) ) orxout()<<"R";302 else orxout()<<" ";303 if ( ( v & eDirection_Down ) ) orxout()<<" ";304 else orxout()<<" ";305 if ( ( v & eDirection_Left ) ) orxout()<<" ";306 else orxout()<<" ";307 orxout()<<"]";308 }309 orxout()<<endl;310 }311 312 }313 314 /**315 @brief316 Print Levelcode (for Debugging only)317 */318 void Hover::LevelOut(){319 for ( int y = 0; y < NumCells; y++ )320 {321 for ( int x = 0; x < NumCells; x++ )322 {323 orxout()<<"[";324 if ( levelcode[x][y] < 2) orxout()<<"U";325 else orxout()<<" ";326 if ( levelcode[x][y] % 2 == 0) orxout()<<"R";327 else orxout()<<" ";328 329 orxout()<<" ";330 orxout()<<" ";331 orxout()<<"]";332 }333 orxout()<<endl;334 }335 }336 337 /**338 @brief339 Generate Levelcode from Maze340 */341 void Hover::RenderMaze()342 {343 for ( int y = 0; y < NumCells; y++ )344 {345 for ( int x = 0; x < NumCells; x++ )346 {347 char v = g_Maze[ y * NumCells + x ];348 349 if ( !( v & eDirection_Up ) && y >0) levelcode[y][x] |= 2;350 if ( !( v & eDirection_Right ) && x <9) levelcode[y][x] |= 1;351 }352 }353 for ( int y = 3; y < 7; y++ )354 {355 for ( int x = 3; x < 7; x++ )356 {357 358 if(y == 3 && x != 7)359 levelcode[y][x] &= 2;360 else if (x == 7 && y != 3)361 levelcode[y][x] &= 1;362 else if(x != 7)363 levelcode[y][x] = 0;364 }365 }366 367 }368 369 370 371 131 } -
code/branches/presentationHS15/src/modules/hover/Hover.h
r11026 r11035 59 59 namespace orxonox 60 60 { 61 62 enum eDirection63 {64 eDirection_Invalid = 0,65 eDirection_Up = 1,66 eDirection_Right = 2,67 eDirection_Down = 4,68 eDirection_Left = 869 };70 71 61 class _HoverExport Hover : public Gametype 72 62 { … … 80 70 81 71 void setOrigin(HoverOrigin* origin) 82 72 { this->origin_ = origin; } 83 73 84 74 int getFlags(); 85 WeakPtr<HoverOrigin> origin_;86 75 87 76 private: 88 int CellIdx(); 89 int RandomInt(); 90 int RandomInt4(); 91 int Flags_; 92 93 bool IsDirValid( eDirection Dir ); 94 eDirection GetDirection(); 95 void GenerateMaze(); 96 void RenderMaze(); 97 void MazeOut(); 98 void LevelOut(); 99 std::vector<HoverFlag*> flagVector; 100 101 77 WeakPtr<HoverOrigin> origin_; 78 std::vector<HoverFlag*> flagVector_; 79 int flags_; 80 bool firstTick_; 102 81 }; 103 82 } -
code/branches/presentationHS15/src/modules/hover/MazeGenerator.cc
r11026 r11035 28 28 29 29 /** 30 @file Hover.cc31 @brief Implementation of the Hover class. Sets up the whole Minigame30 @file MazeGenerator.cc 31 @brief Implementation of the MazeGenerator class. Generates the maze. 32 32 */ 33 33 34 //#include "orxonox/worldentities/pawns/SpaceShip.h" 35 #include "Hover.h" 36 37 #include "HoverWall.h" 38 #include "HoverFlag.h" 39 #include "core/CoreIncludes.h" 40 41 #include <iostream> 42 #include <string> 43 #include <time.h> 44 #include <stdlib.h> 45 #include <memory.h> 46 #include <stdint.h> 47 #include <fstream> 34 #include "MazeGenerator.h" 35 48 36 #include <vector> 37 38 #include "util/Output.h" 39 #include "util/Math.h" 49 40 50 41 namespace orxonox 51 42 { 52 bool firstTick = true; 53 54 //Levelcode represents the pitch: It's a 10x10 field. 55 // 1 represents a Wall on the right side of this square 56 // 2 represents a Wall on the top of this square 57 // 3 represents 2 and 1 at the same time 58 // Note: the levelcode is generated from the Maze-Generator functions at the beginning of the game 59 int levelcode[10][10] = 60 { 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 }, 64 { 0,0,0,0,0,0,0,0,0,0 }, 65 { 0,0,0,0,0,0,0,0,0,0 }, 66 { 0,0,0,0,0,0,0,0,0,0 }, 67 { 0,0,0,0,0,0,0,0,0,0 }, 68 { 0,0,0,0,0,0,0,0,0,0 }, 69 { 0,0,0,0,0,0,0,0,0,0 }, 70 { 0,0,0,0,0,0,0,0,0,0 } 71 }; 72 73 const int NumCells = 10; 74 unsigned char* g_Maze = new unsigned char[ NumCells* NumCells ]; 75 76 // current traversing position 77 int g_PtX; 78 int g_PtY; 79 80 // return the current index in g_Maze 81 int Hover::CellIdx() 82 { 83 return g_PtX + NumCells * g_PtY; 84 } 85 86 87 int Hover::RandomInt() 88 { 89 return (rand() % NumCells); 90 } 91 92 int Hover::RandomInt4() 93 { 94 return (rand() % 4); 95 } 96 97 98 RegisterUnloadableClass(Hover); 99 100 101 102 103 104 105 106 Hover::Hover(Context* context) : Gametype(context) 107 { 108 109 RegisterObject(Hover); 110 this->setHUDTemplate("HoverHUD"); 111 } 112 113 114 115 void Hover::tick(float dt) 116 { 117 118 SUPER(Hover, tick, dt); 119 120 121 122 123 if(firstTick) 124 { 125 126 std::fill( g_Maze, g_Maze + NumCells * NumCells, 0 ); 127 g_PtX=0; 128 g_PtY=0; 129 GenerateMaze(); 130 RenderMaze(); 131 firstTick = false; 132 133 //Outer Walls 134 for(int i = 0; i<10; i++){ 135 new HoverWall(origin_->getContext(), 0, i+1, 1); 136 new HoverWall(origin_->getContext(), 10, i+1, 1); 137 new HoverWall(origin_->getContext(), i+1, 0, 2); 138 new HoverWall(origin_->getContext(), i+1, 10, 2); 139 } 140 141 //Generate inner Walls according to levelcode 142 for(int y=0; y<10; y++){ 143 for(int x=0; x<10; x++){ 144 switch(levelcode[y][x]){ 145 case 1: new HoverWall(origin_->getContext(), x+1, 10-y, 1); 146 break; 147 case 3: new HoverWall(origin_->getContext(), x+1, 10-y, 1); 148 case 2: new HoverWall(origin_->getContext(), x+1, 10-y, 0); 149 default: break; 150 } 151 152 153 154 } 155 } 156 157 //Generate 5 flags randomly 158 for ( int i = 0; i < 5; i++ ) 159 flagVector.push_back(new HoverFlag(origin_->getContext(), rand()%10, rand()%10)); 160 161 Flags_ = flagVector.size(); 162 163 }//firsttick end 164 165 // Check if ship collided with one of the flags 166 for ( unsigned int i = 0; i < flagVector.size(); i++ ){ 167 if(flagVector[i]->getCollided()){ 168 flagVector[i]->destroyLater(); 169 flagVector.erase (flagVector.begin()+i); 170 } 171 } 172 Flags_ = flagVector.size(); 173 174 175 176 } 177 178 int Hover::getFlags() 179 { 180 181 // Call start for the parent class. 182 return Flags_; 183 } 184 185 void Hover::start() 186 { 187 188 // Call start for the parent class. 189 Gametype::start(); 190 191 } 192 193 194 void Hover::end() 195 { 196 // DON'T CALL THIS! 197 // Deathmatch::end(); 198 // It will misteriously crash the game! 199 // Instead startMainMenu, this won't crash. 200 GSLevel::startMainMenu(); 201 } 202 203 204 205 206 // Some definitions for the Maze-Generator 207 208 // 0 1 2 3 4 5 6 7 8 209 // U R D L 210 int Heading_X[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 }; 211 int Heading_Y[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 }; 212 int Mask[9] = { 213 0, 214 eDirection_Down | eDirection_Down << 4, 215 eDirection_Left | eDirection_Left << 4, 216 0, 217 eDirection_Up | eDirection_Up << 4, 218 0, 219 0, 220 0, 221 eDirection_Right | eDirection_Right << 4 222 }; 223 43 MazeGenerator::MazeGenerator() 44 { 45 //levelcode_ represents the pitch: It's a 10x10 field. 46 // 1 represents a Wall on the right side of this square 47 // 2 represents a Wall on the top of this square 48 // 3 represents 2 and 1 at the same time 49 // Note: the levelcode_ is generated from the Maze-Generator functions at the beginning of the game 50 this->levelcode_ = new int[ NUM_CELLS*NUM_CELLS ];; 51 std::fill( levelcode_, levelcode_ + NUM_CELLS*NUM_CELLS, 0 ); 52 53 this->maze_ = new unsigned char[ NUM_CELLS*NUM_CELLS ]; 54 std::fill( maze_, maze_ + NUM_CELLS*NUM_CELLS, 0 ); 55 56 // current traversing position 57 this->ptX_ = 0; 58 this->ptY_ = 0; 59 60 // 0 1 2 3 4 5 6 7 8 61 // U R D L 62 int headingX[9] = { 0, 0,+1, 0, 0, 0, 0, 0,-1 }; 63 int headingY[9] = { 0,-1, 0, 0,+1, 0, 0, 0, 0 }; 64 int mask[9] = { 65 0, 66 eDirection_Down | eDirection_Down << 4, 67 eDirection_Left | eDirection_Left << 4, 68 0, 69 eDirection_Up | eDirection_Up << 4, 70 0, 71 0, 72 0, 73 eDirection_Right | eDirection_Right << 4 74 }; 75 76 std::copy(headingX, headingX + 9, this->headingX_); 77 std::copy(headingY, headingY + 9, this->headingY_); 78 std::copy(mask, mask + 9, this->mask_); 79 } 224 80 225 81 /** … … 227 83 Checks if Direction is valid (for Maze-Generator) 228 84 */ 229 bool Hover::IsDirValid( eDirection Dir )230 { 231 int NewX = g_PtX + Heading_X[ Dir ];232 int NewY = g_PtY + Heading_Y[ Dir ];233 234 if ( !Dir || NewX < 0 || NewY < 0 || NewX >= N umCells || NewY >= NumCells) return false;235 236 return ! g_Maze[ NewX + NumCells* NewY ];85 bool MazeGenerator::isDirValid( eDirection Dir ) 86 { 87 int NewX = ptX_ + headingX_[ Dir ]; 88 int NewY = ptY_ + headingY_[ Dir ]; 89 90 if ( !Dir || NewX < 0 || NewY < 0 || NewX >= NUM_CELLS || NewY >= NUM_CELLS ) return false; 91 92 return !maze_[ NewX + NUM_CELLS * NewY ]; 237 93 } 238 94 … … 241 97 Generates new Direction (for Maze-Generator) 242 98 */ 243 eDirection Hover::GetDirection()244 { 245 eDirection Dir = eDirection( 1 << RandomInt4() );99 eDirection MazeGenerator::getDirection() 100 { 101 eDirection Dir = eDirection( 1 << randomInt4() ); 246 102 247 103 while ( true ) … … 249 105 for ( int x = 0; x < 4; x++ ) 250 106 { 251 if ( IsDirValid( Dir ) ) { return eDirection( Dir ); }107 if ( isDirValid( Dir ) ) { return eDirection( Dir ); } 252 108 253 109 Dir = eDirection( Dir << 1 ); … … 256 112 } 257 113 258 Dir = eDirection( ( g_Maze[ CellIdx() ] & 0xf0 ) >> 4 );114 Dir = eDirection( ( maze_[ cellIdx() ] & 0xf0 ) >> 4 ); 259 115 260 116 // nowhere to go 261 117 if ( !Dir ) return eDirection_Invalid; 262 118 263 g_PtX += Heading_X[ Dir ];264 g_PtY += Heading_Y[ Dir ];265 266 Dir = eDirection( 1 << RandomInt4() );119 ptX_ += headingX_[ Dir ]; 120 ptY_ += headingY_[ Dir ]; 121 122 Dir = eDirection( 1 << randomInt4() ); 267 123 } 268 124 } … … 272 128 Generates a Maze (for Maze-Generator) 273 129 */ 274 void Hover::GenerateMaze()275 { 276 277 for ( eDirection Dir = GetDirection(); Dir != eDirection_Invalid; Dir = GetDirection() )278 { 279 g_Maze[ CellIdx() ] |= Dir;280 281 g_PtX += Heading_X[ Dir ];282 g_PtY += Heading_Y[ Dir ];283 284 g_Maze[ CellIdx() ] = Mask[ Dir ];130 void MazeGenerator::generateMaze() 131 { 132 133 for ( eDirection Dir = getDirection(); Dir != eDirection_Invalid; Dir = getDirection() ) 134 { 135 maze_[ cellIdx() ] |= Dir; 136 137 ptX_ += headingX_[ Dir ]; 138 ptY_ += headingY_[ Dir ]; 139 140 maze_[ cellIdx() ] = mask_[ Dir ]; 285 141 } 286 142 } … … 290 146 Print Maze (for Debugging only) 291 147 */ 292 void Hover::MazeOut(){293 for ( int y = 0; y < N umCells; y++ )294 { 295 for ( int x = 0; x < N umCells; x++ )296 { 297 char v = g_Maze[ y * NumCells+ x ];148 void MazeGenerator::mazeOut(){ 149 for ( int y = 0; y < NUM_CELLS; y++ ) 150 { 151 for ( int x = 0; x < NUM_CELLS; x++ ) 152 { 153 char v = maze_[ y * NUM_CELLS + x ]; 298 154 orxout()<<"["; 299 155 if ( ( v & eDirection_Up ) ) orxout()<<"U"; … … 314 170 /** 315 171 @brief 316 Print Levelcode(for Debugging only)317 */ 318 void Hover::LevelOut(){319 for ( int y = 0; y < N umCells; y++ )320 { 321 for ( int x = 0; x < N umCells; x++ )172 Print levelcode_ (for Debugging only) 173 */ 174 void MazeGenerator::levelOut(){ 175 for ( int y = 0; y < NUM_CELLS; y++ ) 176 { 177 for ( int x = 0; x < NUM_CELLS; x++ ) 322 178 { 323 179 orxout()<<"["; 324 if ( levelcode [x][y] < 2) orxout()<<"U";325 else orxout()<<" "; 326 if ( levelcode [x][y] % 2 == 0) orxout()<<"R";180 if ( levelcode_[ y * NUM_CELLS + x ] < 2) orxout()<<"U"; 181 else orxout()<<" "; 182 if ( levelcode_[ y * NUM_CELLS + x ] % 2 == 0) orxout()<<"R"; 327 183 else orxout()<<" "; 328 184 … … 337 193 /** 338 194 @brief 339 Generate Levelcodefrom Maze340 */ 341 void Hover::RenderMaze()342 { 343 for ( int y = 0; y < N umCells; y++ )344 { 345 for ( int x = 0; x < N umCells; x++ )346 { 347 char v = g_Maze[ y * NumCells+ x ];348 349 if ( !( v & eDirection_Up ) && y >0) levelcode [y][x] |= 2;350 if ( !( v & eDirection_Right ) && x <9) levelcode [y][x] |= 1;195 Generate levelcode_ from Maze 196 */ 197 void MazeGenerator::renderMaze() 198 { 199 for ( int y = 0; y < NUM_CELLS; y++ ) 200 { 201 for ( int x = 0; x < NUM_CELLS; x++ ) 202 { 203 char v = maze_[ y * NUM_CELLS + x ]; 204 205 if ( !( v & eDirection_Up ) && y >0) levelcode_[ y * NUM_CELLS + x ] |= 2; 206 if ( !( v & eDirection_Right ) && x <9) levelcode_[ y * NUM_CELLS + x ] |= 1; 351 207 } 352 208 } … … 357 213 358 214 if(y == 3 && x != 7) 359 levelcode [y][x] &= 2;215 levelcode_[ y * NUM_CELLS + x ] &= 2; 360 216 else if (x == 7 && y != 3) 361 levelcode [y][x] &= 1;217 levelcode_[ y * NUM_CELLS + x ] &= 1; 362 218 else if(x != 7) 363 levelcode[y][x] = 0; 364 } 365 } 366 367 } 368 369 370 219 levelcode_[ y * NUM_CELLS + x ] = 0; 220 } 221 } 222 223 } 224 225 // return the current index in maze_ 226 int MazeGenerator::cellIdx() 227 { 228 return ptX_ + NUM_CELLS * ptY_; 229 } 230 231 int MazeGenerator::randomInt() 232 { 233 return (rand() % NUM_CELLS); 234 } 235 236 int MazeGenerator::randomInt4() 237 { 238 return (rand() % 4); 239 } 371 240 } -
code/branches/presentationHS15/src/modules/hover/MazeGenerator.h
r11026 r11035 28 28 29 29 /** 30 @file Hover.h 31 @brief Gametype. For more information see .cc file 30 @file MazeGenerator.h 32 31 @ingroup Hover 33 32 */ 34 33 35 #ifndef _ Hover_H__36 #define _ Hover_H__34 #ifndef _MazeGenerator_H__ 35 #define _MazeGenerator_H__ 37 36 38 37 #include "HoverPrereqs.h" 39 #include "HoverOrigin.h"40 41 #include "gametypes/Gametype.h"42 #include "core/EventIncludes.h"43 #include "core/command/Executor.h"44 #include "core/config/ConfigValueIncludes.h"45 46 #include "gamestates/GSLevel.h"47 #include "chat/ChatManager.h"48 #include <vector>49 50 // ! HACK51 #include "infos/PlayerInfo.h"52 53 #include "core/command/ConsoleCommand.h"54 55 #include "tools/Timer.h"56 57 58 38 59 39 namespace orxonox 60 40 { 61 62 41 enum eDirection 63 42 { … … 69 48 }; 70 49 71 class _HoverExport Hover : public Gametype50 class _HoverExport MazeGenerator 72 51 { 73 public:74 Hover(Context* context);52 public: 53 MazeGenerator(); 75 54 76 virtual void start(); 77 virtual void end(); 55 void generateMaze(); 56 void renderMaze(); 57 void mazeOut(); 58 void levelOut(); 78 59 79 virtual void tick(float dt); 80 81 void setOrigin(HoverOrigin* origin) 82 { this->origin_ = origin; } 83 84 int getFlags(); 85 WeakPtr<HoverOrigin> origin_; 60 int* getLevelcode() const 61 { return this->levelcode_; } 62 int getNumCells() const 63 { return NUM_CELLS; } 86 64 87 65 private: 88 int CellIdx(); 89 int RandomInt(); 90 int RandomInt4(); 91 int Flags_; 66 bool isDirValid( eDirection Dir ); 67 eDirection getDirection(); 92 68 93 bool IsDirValid( eDirection Dir ); 94 eDirection GetDirection(); 95 void GenerateMaze(); 96 void RenderMaze(); 97 void MazeOut(); 98 void LevelOut(); 99 std::vector<HoverFlag*> flagVector; 69 int cellIdx(); 70 int randomInt(); 71 int randomInt4(); 100 72 73 static const int NUM_CELLS = 10; 74 int* levelcode_; 75 unsigned char* maze_; 101 76 77 // current traversing position 78 int ptX_; 79 int ptY_; 80 81 int headingX_[9]; 82 int headingY_[9]; 83 int mask_[9]; 102 84 }; 103 85 } 104 86 105 #endif /* _ Hover_H__ */87 #endif /* _MazeGenerator_H__ */
Note: See TracChangeset
for help on using the changeset viewer.