Beispiel #1
0
void Game::showMenu()
{
	sf::Font font;
	if (!font.loadFromFile("fonts/Square.ttf"))
	{
		std::cout << "Could not load font.\n";
	}
	else
	{
		sf::RectangleShape blackScreen(sf::Vector2f(1024, 768));
		blackScreen.setFillColor(sf::Color(0, 0, 0));
	
		sf::Text buttonText;
		buttonText.setFont(font);
		buttonText.setString("Start Loading...");
		buttonText.setCharacterSize(100);
		buttonText.setPosition(512 - buttonText.getGlobalBounds().width / 2, 384 - buttonText.getGlobalBounds().height / 2);

		sf::RectangleShape button(sf::Vector2f(buttonText.getGlobalBounds().width + 20, buttonText.getGlobalBounds().height + 30));
		button.setPosition(512 - buttonText.getGlobalBounds().width / 2, 384 - buttonText.getGlobalBounds().height + 50);
		button.setFillColor(sf::Color(128, 128, 128));
		mainWindow_.draw(blackScreen);
		mainWindow_.draw(button);
		mainWindow_.draw(buttonText);
		sf::Rect<float> bSpriteRect = button.getGlobalBounds();
		sf::Event event;
		while (mainWindow_.pollEvent(event))
		{
			if (event.type == sf::Event::MouseButtonPressed)
			{
				float x = event.mouseButton.x;
				float y = event.mouseButton.y;
				if (bSpriteRect.height + bSpriteRect.top> y
					&& bSpriteRect.top < y
					&& bSpriteRect.left < x
					&& bSpriteRect.width + bSpriteRect.left > x)
				{
					gameState_ = Game::Playing;
				}
			}
			if (event.type == sf::Event::Closed)
			{
				gameState_ = Game::Exiting;
				break;
			}
		}
	}
}
Beispiel #2
0
void Game::displayText()
{
	sf::RectangleShape blackScreen(sf::Vector2f(1024, 768));
	blackScreen.setFillColor(sf::Color(0, 0, 0));
	mainWindow_.draw(blackScreen);

	sf::Font font;
	if (!font.loadFromFile("fonts/Square.ttf"))
	{
		std::cout << "Could not load font.\n";
	}
	else
	{
		sf::Text gameOver;
		gameOver.setFont(font);
		gameOver.setString("GAME OVER");
		gameOver.setCharacterSize(100);
		gameOver.setPosition(512 - gameOver.getGlobalBounds().width / 2, 200);

		sf::Text finalScore;
		finalScore.setFont(font);
		int amountLoaded = (int)(dynamic_cast<LoadingBar*>(gameObjectManager_.get("LoadingBar"))->getPosition().x) + 1024;
		int numHits = dynamic_cast<Player*>(gameObjectManager_.get("Player"))->getNumHits();
		finalScore.setString("Final Score: " + std::to_string(amountLoaded - numHits * 150));
		finalScore.setCharacterSize(100);
		finalScore.setPosition(512 - finalScore.getGlobalBounds().width / 2, 300);

		sf::Text tryAgain;
		tryAgain.setFont(font);
		tryAgain.setString("Reload?");
		tryAgain.setCharacterSize(100);
		tryAgain.setPosition(512 - tryAgain.getGlobalBounds().width / 2, 400);

		sf::RectangleShape tryAgainBox(sf::Vector2f(tryAgain.getGlobalBounds().width + 20, tryAgain.getGlobalBounds().height + 30));
		tryAgainBox.setPosition(512 - tryAgain.getGlobalBounds().width / 2, 384 - tryAgain.getGlobalBounds().height + 100);
		tryAgainBox.setFillColor(sf::Color(128, 128, 128));

		mainWindow_.draw(gameOver);
		mainWindow_.draw(finalScore);
		mainWindow_.draw(tryAgainBox);
		mainWindow_.draw(tryAgain);

		sf::Rect<float> bSpriteRect = tryAgainBox.getGlobalBounds();
		sf::Event event;
		while (mainWindow_.pollEvent(event))
		{
			if (event.type == sf::Event::MouseButtonPressed)
			{
				float x = event.mouseButton.x;
				float y = event.mouseButton.y;
				if (bSpriteRect.height + bSpriteRect.top> y
					&& bSpriteRect.top < y
					&& bSpriteRect.left < x
					&& bSpriteRect.width + bSpriteRect.left > x)
				{
					gameObjectManager_.remove("Player");
					gameObjectManager_.remove("LoadingBar");
					gameObjectManager_.remove("Enemy1");
					gameObjectManager_.remove("Enemy2");
					gameObjectManager_.remove("Enemy3");
					gameObjectManager_.remove("Enemy4");
					gameObjectManager_.remove("Enemy5");
					init();
				}
			}
			if (event.type == sf::Event::Closed)
			{
				gameState_ = Game::Exiting;
				break;
			}
		}
	}
}
Beispiel #3
0
int main()
{

	/********************** TouchSensor Setup *********************/
	Status = TouchSensor_Initialize(&touchSensor, XPAR_TOUCHSENSOR_0_DEVICE_ID);
	if (Status != XST_SUCCESS)
	{
	//	printf("TouchSensor initialisation error\n\r\r");
	}
    TouchSensorButtons_InitializeManager(&Manager, &touchSensor, &PrintTouchCoordinates);

    button_t GameboardGridButton;
    Button_SetGridDim(&GameboardGridButton, SQUARE_DIM, SQUARE_DIM, BOARD_OFFSET_X, BOARD_OFFSET_Y, BOARD_SIZE, BOARD_SIZE);
    Button_AssignHandler(&GameboardGridButton, &HandleGameboardTouch);
    TouchSensorButtons_RegisterButton(&Manager, &GameboardGridButton);
    TouchSensorButtons_EnableButton(&GameboardGridButton);

    button_t WhiteModeButton;
    Button_SetGridDim(&WhiteModeButton, 50, 50, 300, 10 , 3, 1);
    Button_AssignHandler(&WhiteModeButton, &HandleWhiteModeTouch);
    TouchSensorButtons_RegisterButton(&Manager, &WhiteModeButton);
    TouchSensorButtons_EnableButton(&WhiteModeButton);

    button_t BlackModeButton;
    Button_SetGridDim(&BlackModeButton, 50, 50, 300, 75, 3, 1);
    Button_AssignHandler(&BlackModeButton, &HandleBlackModeTouch);
    TouchSensorButtons_RegisterButton(&Manager, &BlackModeButton);
    TouchSensorButtons_EnableButton(&BlackModeButton);

    button_t ResetButton;
    Button_SetRectDim(&ResetButton, 100, 50, 325, 200);
    Button_AssignHandler(&ResetButton, &HandleResetTouch);
    TouchSensorButtons_RegisterButton(&Manager, &ResetButton);
    TouchSensorButtons_EnableButton(&ResetButton);

    /********************** BoardCount Accelerator Setup********************/
    initialize_accelerator(&board_count_accelerator, XPAR_GENERATE_BOARD_COUNTS_TOP_0_S_AXI_CTRL_BASEADDR);

    /********************** TFT Setup *********************/
    blackScreen();


	TFT_Initialize(&tft, XPAR_TFT_PERHIPHERAL_0_DEVICE_ID);
	TFT_SetImageAddress(&tft, XPAR_MCB_DDR2_S0_AXI_BASEADDR);
	TFT_SetBrightness(&tft, 7);
	TFT_TurnOn(&tft);


	//Render Buttons
	//TouchSensorButtons_RenderButton(&MyCircle, GREEN, &tft);
	//TouchSensorButtons_RenderButton(&MyRect, RED, &tft);
	TouchSensorButtons_RenderButton(&GameboardGridButton, BLUE, &tft);
	TouchSensorButtons_RenderButton(&ResetButton, ORANGE, &tft);
	TouchSensorButtons_RenderButton(&WhiteModeButton, WHITE, &tft);
	TouchSensorButtons_RenderButton(&BlackModeButton, RED, &tft);


    Gameboard.TftPtr = &tft;

    /********************** UART Setup *********************/

    Status = XUartLite_Initialize(&Uart, XPAR_UARTLITE_1_DEVICE_ID);
    if (Status != XST_SUCCESS)
    {
        printf("XUartLite initialization error\n\r");
    }

    XUartLite_SetRecvHandler(&Uart, (XUartLite_Handler) &RecvUartCommand, &Uart);



/********************** Interrupt Controller Setup *********************/
   /*
	* Initialize the interrupt controller driver so that it's ready to use,
	* using the device ID that is generated in xparameters.h
	*/
   Status = XIntc_Initialize(&InterruptController, XPAR_AXI_INTC_0_DEVICE_ID);
   if (Status != XST_SUCCESS)
   {
	   //printf("Interrupt controller initialization error\n\r");
   }

   /*
	* Connect the device driver handler that will be called when an interrupt
	* for the device occurs, the device driver handler performs the specific
	* interrupt processing for the device
	*/
   Status = XIntc_Connect(&InterruptController,
		   XPAR_AXI_INTC_0_TOUCHSENSOR_0_INTERRUPT_INTR,
						  (XInterruptHandler)TouchSensorButtons_InterruptHandler,
						  &Manager);
   if (Status != XST_SUCCESS)
   {
	   //printf("Interrupt controller connect error\n\r");
   }

   Status = XIntc_Connect(&InterruptController,
		   XPAR_AXI_INTC_0_RS232_UART_1_INTERRUPT_INTR,
						  (XInterruptHandler)XUartLite_InterruptHandler,
						  &Uart);
   if (Status != XST_SUCCESS)
   {
	   printf("Interrupt controller connect to Uart error\n\r");
   }


   Status = XIntc_Start(&InterruptController, XIN_REAL_MODE);
   if (Status != XST_SUCCESS)
   {
	   //printf("Interrupt controller start error\n\r");
   }

   XIntc_Enable(&InterruptController,
		   XPAR_AXI_INTC_0_TOUCHSENSOR_0_INTERRUPT_INTR);
   XIntc_Enable(&InterruptController,
		   XPAR_AXI_INTC_0_RS232_UART_1_INTERRUPT_INTR);

   XUartLite_ResetFifos(&Uart);
   XUartLite_EnableInterrupt(&Uart);

   AI_PLAYER ai = default_ai();
   PLAYER Player1, Player2;
   Player1.num = P1;
   Player2.num = P2;
   Gameboard_Initialize(&Gameboard,human,fpga);
   microblaze_enable_interrupts();

   while (1) {
		PLAYER Curr_P, Opp_P;

		//Workaround to enable multiple resets on turn 0.
		if (Gameboard.MoveBufferSize == -1)
			Gameboard.MoveBufferSize++;

		int CurrentMove = Gameboard.MoveBufferSize;
		player_mode_t CurrentPlayerMode = (CurrentMove % 2) ? Gameboard.WhiteMode : Gameboard.BlackMode;
		Curr_P = (CurrentMove % 2) ? Player1 : Player2;
		Opp_P = (CurrentMove % 2) ? Player2 : Player1;
		switch (CurrentPlayerMode){
			case human:
				TouchSensorButtons_EnableButton(&GameboardGridButton);
				break;
			case fpga:
				TouchSensorButtons_DisableButton(&GameboardGridButton);
				HandleAiMove(ai, Gameboard.master_board, Curr_P, Opp_P);
				break;
			case uart:
				TouchSensorButtons_DisableButton(&GameboardGridButton);
				if(Gameboard.MoveBufferSize > 0){
					SendUartCommand(&Uart, Gameboard.MoveBuffer[Gameboard.MoveBufferSize-1].X,
										Gameboard.MoveBuffer[Gameboard.MoveBufferSize-1].Y);
				}
				break;
			default:
				TouchSensorButtons_EnableButton(&GameboardGridButton);
				break;
		}
		/*
		if (check_board_full(Gameboard.master_board)) {
			//printf("Gameboard full\n\r");
			break;
		}
		*/
		if (check_board_win(Gameboard.master_board, Curr_P)) {
			xil_printf("Player %s won\n\r", (Curr_P.num == P1) ? "white" : "black");
			//Spin waiting on reset
			while(Gameboard.MoveBufferSize != -1);
		}

		while(CurrentMove == Gameboard.MoveBufferSize);

   }

	return 0;
}