void GameState::draw() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-.1, 1.1, 1.2, -.1, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); if (m_balls <= 0) { drawGameOver(); return; } glColor3f(1, 1, 1); glBegin(GL_LINE_STRIP); glVertex2d(0, 0); glVertex2d(1, 0); glVertex2d(1, 1); glVertex2d(0, 1); glVertex2d(0, 0); glEnd(); // draw the paddle glBegin(GL_QUADS); glVertex2d(m_paddle - .1, .95); glVertex2d(m_paddle + .1, .95); glVertex2d(m_paddle + .1, .98); glVertex2d(m_paddle - .1, .98); glEnd(); // draw the ball glBegin(GL_POINTS); glVertex2d(m_ball.position.x, m_ball.position.y); glEnd(); glBegin(GL_QUADS); // draw the blocks Block::List::iterator i = m_blocks.begin(); for (; i != m_blocks.end(); ++i) { glColor(i->color); const Point2d& ul = i->location.upper_left; const Point2d& lr = i->location.lower_right; glVertex2d(ul.x, ul.y); glVertex2d(lr.x, ul.y); glVertex2d(lr.x, lr.y); glVertex2d(ul.x, lr.y); } glEnd(); drawScore(); }
void CGreedySnakeView::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (m_bClose == FALSE && nIDEvent == TIMER1) { if(!Manager::theManager()->isAllDead()) { Manager::theManager()->refresh(); Invalidate(FALSE); } else { m_bClose = TRUE; drawGameOver(); /*if(Manager::theManager()->initialGame()) { setGame(); Invalidate(FALSE); }*/ } } else if(m_bClose == FALSE && nIDEvent == TIMER2) { if(Manager::theManager()->initialGame()) { setGame(); Invalidate(FALSE); } else { m_bClose = TRUE; drawGameOver(); } } CView::OnTimer(nIDEvent); }
int interruptManager (unsigned int * framePointer0) { init_platform(); // Initialize the GPIO peripherals. int success; // Used for CPU utilization. Uncomment if desired // XTmrCtr_Initialize(instPtr, 0); success = XGpio_Initialize(&gpPB, XPAR_PUSH_BUTTONS_5BITS_DEVICE_ID); // Set the push button peripheral to be inputs. XGpio_SetDataDirection(&gpPB, 1, 0x0000001F); // Enable the global GPIO interrupt for push buttons. XGpio_InterruptGlobalEnable(&gpPB); // Enable all interrupts in the push button peripheral. XGpio_InterruptEnable(&gpPB, 0xFFFFFFFF); // Reset the XAC97 Chip XAC97_HardReset(XPAR_AXI_AC97_0_BASEADDR); XAC97_mSetControl(XPAR_AXI_AC97_0_BASEADDR, AC97_ENABLE_IN_FIFO_INTERRUPT); XAC97_mSetControl(AC97_ExtendedAudioStat, AC97_EXTENDED_AUDIO_CONTROL_VRA); setVolLevel(AC97_VOL_MAX); clearAllSounds(); microblaze_register_handler(interrupt_handler_dispatcher, NULL); XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, (XPAR_FIT_TIMER_0_INTERRUPT_MASK | XPAR_PUSH_BUTTONS_5BITS_IP2INTC_IRPT_MASK | XPAR_AXI_AC97_0_INTERRUPT_MASK)); XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); microblaze_enable_interrupts(); // Uncomment for CPU utilization stats /*XTmrCtr Timer; XTmrCtr *instPtr = &Timer; XTmrCtr_Initialize(instPtr, 0); XTmrCtr_Start(instPtr, 0);*/ while(!isEndOfGame()); // Program never ends. // Uncomment for CPU utilization stats /*XTmrCtr_Stop(instPtr, 0); int val = (int) XTmrCtr_GetValue(instPtr, 0); xil_printf("%d\n\r", val);*/ clearAllSounds(); XAC97_ClearFifos(XPAR_AXI_AC97_0_BASEADDR); drawGameOver(); cleanup_platform(); return 0; }
//se l'utente si trova in un menu lo disegna e rit. true //altrim. non fa niente e rit. false bool MenuMgr::draw() { if (!showingGAMEOVER && !showingMainMenu && !showingWin && !showingHelp) return false; if (showingMainMenu) drawMainMenu(); else if (showingGAMEOVER) drawGameOver(); else if (showingWin) drawWin(); else if (showingHelp) { drawHelp(); } return true; }
void newGame(int** grid, int* score, int* backToMenu, int gameMode, int delay) { int eaten_flag, skip_sleep = 0; int backup_move = KEY_RIGHT, move = KEY_RIGHT; while (1) { eaten_flag = 0; if (!skip_sleep) { if (move == KEY_RIGHT || move == KEY_LEFT) { Sleep(delay - 20); } else { Sleep(delay); } } else { skip_sleep = 0; } if (_kbhit()) { move = playerMove(); } if (move == EXIT) { while (1) { clear_screen(); pauseGraphics(); if (mainMenu(0)) { break; } else { *backToMenu = 1; return; } } move = backup_move; restoreInGameGraphics(grid, *score); continue; } if (!checkValidMove(move) || move == INVALID_MOVE) { move = backup_move; skip_sleep = 1; continue; } backup_move = move; if (gameOverCheck(move, gameMode)) { drawGameOver(); Sleep(1000); if (*score > record) { record = *score; } break; } assignSnake2Matrix(grid, 0); moveSnake(move, gameMode); eaten_flag = checkIfEaten(grid); if (eaten_flag) { fattenSnake(); } assignSnake2Matrix(grid, 1); if (eaten_flag) { addFood(grid); updateSnakeGraphics(grid, 1); *score += 1; updateScore(*score); } else { updateSnakeGraphics(grid, 0); } } }
void runGameplay(GameVars* gameVars) { //GAME //Draw the court drawCourt(); //Draw the scores drawScores(gameVars); //Game play states switch (gameVars->gameState) { case GSGameStart: { #ifdef DEBUG debugPrint("START\x80"); #endif //Draw Ready message drawReady(0x80); //Wait for a number of frames waitForFramesThenMoveOnToNextState(60, gameVars); } break; case GSWaitForServe: { #ifdef DEBUG debugPrint("SERVE\x80"); #endif //Score max? if (gameVars->player1.score >= maxScoreForPlayer || gameVars->player2.score >= maxScoreForPlayer) { //Served - move to next state moveToNextGameState(gameVars, GEWinner); return; } //Draw player paddles movePaddles(gameVars); //Inform who is about to serve drawServe(gameVars->player1ServeNext); //wait for user to start game with button 4 readButton(); //Player 1 Button 4 or P2 Button 4 if ( (gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY1_B4)) || (!gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY2_B4)) ) { //Position the ball and make visible serve(gameVars); //Served - move to next state moveToNextGameState(gameVars, GENone); } } break; case GSPlay: { #ifdef DEBUG debugPrint("PLAY\x80"); #endif //GAME PLAY ACTION drawCenterLine(gameVars); //Draw player paddles movePaddles(gameVars); //Only deal with visible balls if(gameVars->ball.visibility == false) return; //Move ball - check for goal moveBallSprite(gameVars); } break; case GSScored: { #ifdef DEBUG debugPrint("SCORED\x80"); #endif //Goal! drawPoint(!gameVars->player1ServeNext); waitForFramesThenMoveOnToNextState(60, gameVars); } break; case GSGameOver: { #ifdef DEBUG debugPrint("GAMEOVER\x80"); #endif //Display 'Game Over' drawGameOver(gameVars->player1.score > gameVars->player2.score); //wait for user to select replay or menu readButton(); //Player 1 Button 1 if (_BTN_CUR_MASK & _JOY1_B1) { //Reset scores resetPlayerScores(gameVars); //Replay - move to next state moveToNextGameState(gameVars, GEPlayAgain); } else if (_BTN_CUR_MASK & _JOY1_B2) { //Reset scores resetPlayerScores(gameVars); //Menu - move to next state moveToNextGameState(gameVars, GEBackToMenu); } } break; default: break; } }
int main(void) { int addScore, position, pauseSel; // Initializations PLL_Init(); // Clock set at 80 MHz LCD_Init(); Board_Init(); Input_Init(); DAC_Init(); Random_Init(NVIC_ST_CURRENT_R); Timer2_Init(80000000); // time interrupt Timer1_Init(2000); // sound interrupt EnableInterrupts(); generateRandomTile(); drawAllTiles(); writeScore(0); writeHighscore(0); writeTime(0); displayHighestTile(); while(1) { // draw arrow if ready if (arrowReady == 1) { // acknowledge flag arrowReady = 0; // draw arrow drawArrow(); } // write time if ready if (timeReady == 1) { // acknowledge flag timeReady = 0; // write time writeTime(elapsedTime); } // Play mode and button1 is pushed if(Button1 && !pauseMode && !gameOver) { // Play sound playSound = 1; // shift and merge tiles towards arrow position = getSliderPosition(); if (position == 1) { shiftLeft(); addScore = mergeLeft(); shiftLeft(); } else if (position == 2) { shiftUp(); addScore = mergeUp(); shiftUp(); } else if (position == 3) { shiftRight(); addScore = mergeRight(); shiftRight(); } else { shiftDown(); addScore = mergeDown(); shiftDown(); } eraseBoard(); drawAllTiles(); // update score score += addScore; addScore = 0; writeScore(score); displayHighestTile(); // delay before adding new tile delay(200); // create new tile if (countEmptyTiles() != 0) { generateRandomTile(); } drawAllTiles(); // update highest tile image displayHighestTile(); // check if game over if (checkGameOver() == 1) { gameOver = 1; } // unset flag Button1 = 0; } // button 2 is pause else if (Button2 && !gameOver && !pauseMode) { pauseMode = 1; pauseSel = 0; // disable arrow and timer NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); // draw pause mode screen drawPauseMode(); // acknowledge button Button2 = 0; // wait until button is pushed while (pauseMode) { // Button 1 selects current pause selection button if (Button1) { // acknowledge button Button1 = 0; Button2 = 0; pauseMode = 0; // if pause selection = "continue" (pauseSel = 0), continue with game if (pauseSel == 0) { // redraw screen eraseBoard(); drawAllTiles(); // enable gameplay NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } // if pause selection = "restart" (pauseSel = 0), end game else if (pauseSel == 1) { if (score > highscore) { writeHighscore(score); } score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; } } // Button 2 changes pause selection else if (Button2) { Button2 = 0; if (pauseSel == 0) { pauseSel = 1; LCD_DrawRect(144,112,58,16,BLACK); LCD_DrawRect(222,112,51,16,WHITE); } else if (pauseSel == 1) { pauseSel = 0; LCD_DrawRect(222,112,51,16,BLACK); LCD_DrawRect(144,112,58,16,WHITE); } } } } // game over if (gameOver == 1) { NVIC_ST_CTRL_R = 0; TIMER2_CTL_R = 0x00000000; LCD_DrawFilledRect(156,38,100,20,BLACK); LCD_SetTextColor(255,255,240); LCD_Goto(30,5); printf("GAME OVER"); while (Button1 == 0 && Button2 == 0) {} Button1 = 0; Button2 = 0; LCD_DrawFilledRect(prevX,prevY,20,20,BLACK); drawGameOver(score, elapsedTime); if (score > highscore) { writeHighscore(score); gameOverHighscore(score); } // wait til button is pushed while (Button1 == 0 && Button2 == 0) {} // acknowledge buttons Button1 = 0; Button2 = 0; // start new game score = 0; eraseScore(); writeScore(0); clearBoard(); eraseBoard(); pauseMode = 0; generateRandomTile(); drawAllTiles(); elapsedTime = 0; eraseTime(); writeTime(0); displayHighestTile(); NVIC_ST_CTRL_R = 0x07; TIMER2_CTL_R = 0x00000001; // finish game over mode gameOver = 0; } } }