int movingCount(int threshold, int rows, int cols)
		{
			int result = 0;
			vector<vector<bool>> miniMap(rows, vector<bool>(cols, true));
			move(threshold, rows, cols, 0, 0, result, miniMap);
			return result;
		}
Esempio n. 2
0
	//-------------------------------------------------------------------------------------
	GUIManager::GUIManager(Ogre::Root *root, TankWarWorld *world, Ogre::RenderWindow *window, Ogre::SceneManager *sceneMgr, InputHandler* inputHandler, TankFactory* tankFactory, CollisionManager *mCollisionManager):
		mRoot(root), mWorld(world), mWindow(window), mSceneMgr(sceneMgr), mInputHandler(inputHandler), tankFactory(tankFactory), mCollisionManager(mCollisionManager)
	{
		setupVariables();
		initGUI();
		setupMenuGUI();

		miniMap();
		
	}
Esempio n. 3
0
	void Engine::Execute()
	{
		// we don't have a state stack processor system yet
		// so lets just get a basic while loop running for testing
		
		
		Position playerPosition(0, 0, 0); 
		char hudActionMessage[0x100];
		char compassMessage[0x32];
		bool requestUpdateDisplay = true;
		bool requestClearActionMessage = false;
		int actionMessageClearDelay = 50;
		int actionMessageClearCounter = actionMessageClearDelay;
		
				
		sprintf(hudActionMessage, "%s", "Starting Out...");
		
		int actionMessageX = ((screen_->w / 2) - ((strlen(hudActionMessage) * 9) / 2));
		
		playerPosition.Copy(gameState_->GetPlayerPosition());
		
		int playerX = playerPosition.x_;
		int playerZ = playerPosition.y_;
		int compass = playerPosition.facing_;
		
		sprintf(compassMessage, "You are facing %s.",
			(0x0 == playerPosition.facing_) ? "North" :
			(0x1 == playerPosition.facing_) ? "East" :
			(0x2 == playerPosition.facing_) ? "South" :
			(0x3 == playerPosition.facing_) ? "West" : "<Invalid Direction>");

		int gameScreenX = 40;
		int gameScreenY = mainScreen_->h / 2 - screen_->h / 2;
		
		
		SDL_Surface* mainScreenOverlay = Engine::LoadImageResource("resources/overlays/mainscreen.png");
		
		if (!mainScreenOverlay)
		{
			this->Stop();
			return;
		}
		
		// small compass overlay images
		SDL_Surface** smallCompassOverlay = new SDL_Surface* [4];
		
		smallCompassOverlay[0] = Engine::LoadImageResource("resources/overlays/sm_compass_n.png");
		smallCompassOverlay[1] = Engine::LoadImageResource("resources/overlays/sm_compass_e.png");
		smallCompassOverlay[2] = Engine::LoadImageResource("resources/overlays/sm_compass_s.png");
		smallCompassOverlay[3] = Engine::LoadImageResource("resources/overlays/sm_compass_w.png");


		

		// better input handling
		const int MOTIONBUTTON_UP 			= 0x0;
		const int MOTIONBUTTON_DOWN 		= 0x1;
		const int MOTIONBUTTON_STRAFELEFT 	= 0x2;
		const int MOTIONBUTTON_STRAFERIGHT 	= 0x3;
		bool motionButtonDown[4] = { false, false, false, false };
		
		// slow the f*****g player down!
		int playerMotionDelay = 10;
		int playerMotionCounter = playerMotionDelay;
		
		
		// a minimap
		MiniMap miniMap(gameState_->GetCurrentMap(), 140, 140);

		// while the engine is running
		while(engineIsRunning_)
		{
			// process the events
			while(SDL_PollEvent(event_))
			{
				switch(event_->type)
				{
					// the window was closed
					case SDL_QUIT:
					{
						// stop the engine
						this->Stop();
					} break;

					// a key was pressed
					case SDL_KEYDOWN:
					{
						// what key is down
						switch(event_->key.keysym.sym)
						{
							case SDLK_ESCAPE:
							{
								// stop the engine
								this->Stop();
							} break;
							
							case 'w':
							case 'W':
							case SDLK_UP:
							{
								motionButtonDown[MOTIONBUTTON_UP] = true;
							} break;
							
							case 's':
							case 'S':
							case SDLK_DOWN:
							{
								motionButtonDown[MOTIONBUTTON_DOWN] = true;
							} break;
							
							case 'q':
							case 'Q':
							case SDLK_COMMA:
							case SDLK_LESS:
							{
								motionButtonDown[MOTIONBUTTON_STRAFELEFT] = true;
							} break;
							
							case 'e':
							case 'E':
							case SDLK_PERIOD:
							case SDLK_GREATER:
							{
								motionButtonDown[MOTIONBUTTON_STRAFERIGHT] = true;
							} break;
							
							default: break;
						} // end switch
					} break;
					
					// a key was released
					case SDL_KEYUP:
					{
						// what key is up
						switch(event_->key.keysym.sym)
						{
							case 'w':
							case 'W':
							case SDLK_UP:
							{
								motionButtonDown[MOTIONBUTTON_UP] = false;
							} break;
							
							case 's':
							case 'S':
							case SDLK_DOWN:
							{
								motionButtonDown[MOTIONBUTTON_DOWN] = false;
							} break;
							
							case 'q':
							case 'Q':
							case SDLK_COMMA:
							case SDLK_LESS:
							{
								motionButtonDown[MOTIONBUTTON_STRAFELEFT] = false;
							} break;
							
							case 'e':
							case 'E':
							case SDLK_PERIOD:
							case SDLK_GREATER:
							{
								motionButtonDown[MOTIONBUTTON_STRAFERIGHT] = false;
							} break;
							
							case 'a':
							case 'A':
							case SDLK_LEFT:
							{
								gameState_->TurnPlayerLeft();
								sprintf(hudActionMessage, "%s", "Turned Left...");
								requestUpdateDisplay = true;
							} break;
							
							case 'd':
							case 'D':
							case SDLK_RIGHT:
							{
								gameState_->TurnPlayerRight();
								sprintf(hudActionMessage, "%s", "Turned Right...");
								requestUpdateDisplay = true;
							} break;
							default: break;
						}
					} break;

					default: break;
				} // end switch
			} // end while
			
////////////////////////////////////////////////////////////////////////////////
// *************************** NEW PLAYER MOTION **************************** //
////////////////////////////////////////////////////////////////////////////////
			
			// are we moving forward?
			if (motionButtonDown[MOTIONBUTTON_UP])
			{
				if (--playerMotionCounter <= 0)
				{
					playerMotionCounter = playerMotionDelay;
					
					if (gameState_->MovePlayerForward())
					{
						sprintf(hudActionMessage, "%s", "Moved Forward...");
						requestUpdateDisplay = true;
					}
					else
					{
						sprintf(hudActionMessage, "%s", "That way is blocked!");
						requestUpdateDisplay = true;
					}
				}
			}
			
			// are we moving back?
			if (motionButtonDown[MOTIONBUTTON_DOWN])
			{
				if (--playerMotionCounter <= 0)
				{
					playerMotionCounter = playerMotionDelay;
					
					if (gameState_->MovePlayerBack())
					{
						sprintf(hudActionMessage, "%s", "Moved Back...");
						requestUpdateDisplay = true;
					}
					else
					{
						sprintf(hudActionMessage, "%s", "That way is blocked!");
						requestUpdateDisplay = true;
					}
				}
			}
			
			// are we strafing left?
			if (motionButtonDown[MOTIONBUTTON_STRAFELEFT])
			{
				if (--playerMotionCounter <= 0)
				{
					playerMotionCounter = playerMotionDelay;
					
					if (gameState_->MovePlayerLeft())
					{
						sprintf(hudActionMessage, "%s", "Stepped Left...");
						requestUpdateDisplay = true;
					}
					else
					{
						sprintf(hudActionMessage, "%s", "That way is blocked!");
						requestUpdateDisplay = true;
					}
				}
			}
			
			// are we strafing right?
			if (motionButtonDown[MOTIONBUTTON_STRAFERIGHT])
			{
				if (--playerMotionCounter <= 0)
				{
					playerMotionCounter = playerMotionDelay;
					
					if (gameState_->MovePlayerRight())
					{
						sprintf(hudActionMessage, "%s", "Stepped Right...");
						requestUpdateDisplay = true;
					}
					else
					{
						sprintf(hudActionMessage, "%s", "That way is blocked!");
						requestUpdateDisplay = true;
					}
				}
			}

			// is is time to request the action message be cleared?
			if (--actionMessageClearCounter <= 0)
			{
				actionMessageClearCounter = actionMessageClearDelay;
				requestClearActionMessage = true;
			}
			
			// should we clear the action message ?
			if (requestClearActionMessage)
			{
				sprintf(hudActionMessage, "%s", "Waiting...");
				requestClearActionMessage = false;
				requestUpdateDisplay = true;
			}
			
			// should we update the display?
			if (requestUpdateDisplay)
			{
				actionMessageX = ((screen_->w / 2) - ((strlen(hudActionMessage) * 9) / 2));
	
				playerPosition.Copy(gameState_->GetPlayerPosition());
	
				playerX = playerPosition.x_;
				playerZ = playerPosition.y_;
				compass = playerPosition.facing_;
	
				sprintf(compassMessage, "You are facing %s.",
					(0x0 == playerPosition.facing_) ? "North" :
					(0x1 == playerPosition.facing_) ? "East" :
					(0x2 == playerPosition.facing_) ? "South" :
					(0x3 == playerPosition.facing_) ? "West" : "<Invalid Direction>");
					
				
				mapView_->RenderMap(screen_, gameState_->GetCurrentMap(), gameState_->GetPlayerPosition());
				
				defaultFont_->Print(screen_, actionMessageX, 8, "%s", hudActionMessage);
				defaultFont_->Print(screen_, 8, screen_->h - 34, "Player X: %2d", playerX);
				defaultFont_->Print(screen_, 8, screen_->h - 25, "Player Z: %2d", playerZ);
				defaultFont_->Print(screen_, 8, screen_->h - 16, "%s", compassMessage);
			
				// blit the game screen onto the main screen
				Engine::BlitSprite(screen_, mainScreen_, gameScreenX, gameScreenY);
			
				// blit the overlays
				Engine::BlitSprite(mainScreenOverlay, mainScreen_, 0, 0);
				
				Engine::BlitSprite(smallCompassOverlay[compass], mainScreen_, 42, 42);
				
				// blit the minimap
				miniMap.Update();
				miniMap.Render(mainScreen_, 390, 290);
				
				requestUpdateDisplay = false;
			}
			
			
			
			// flip the screen
			this->FlipScreen();
			
			// reduce the cpu hoggingness of SDL ^-^
			SDL_Delay(20);
		} // end while
		
		Engine::UnloadImageResource(smallCompassOverlay[0]);
		Engine::UnloadImageResource(smallCompassOverlay[1]);
		Engine::UnloadImageResource(smallCompassOverlay[2]);
		Engine::UnloadImageResource(smallCompassOverlay[3]);
		delete [] smallCompassOverlay;
		
		Engine::UnloadImageResource(mainScreenOverlay);
		
		
	}