void Game::update() { if (isPaused) { return; } framesSinceBlocksMoved++; grid.clearCurrentShapeBlocks(); grid.setCurrentShapeBlocks(); int oldLevel = level; int oldLinesScored = linesScored; linesScored = grid.getLinesScored(); int combo = linesScored - oldLinesScored; if (combo) { incrementScore(combo); } level = linesScored / 2; if (oldLevel != level) { silkworm.stop(); silkworm.setPitch(1 - (float)level / 10); silkworm.play(); } linesScoredText.setString("Lines: " + std::to_string(linesScored)); scoreText.setString("Score: " + std::to_string(score)); levelText.setString("Level: " + std::to_string(level)); if (framesSinceBlocksMoved > 30 / (level + 1) || pressedDown) { grid.tryMovingDown(); pressedDown = false; framesSinceBlocksMoved = 0; if (grid.didILose()) { mWindow.close(); } } }
void Battleship::gameLoop() { bool end = false; while (!end) { // Ask user for co-ordinates int x, y; cout << endl << "Choose your co-ordinates in the " << GRID_SIZE << "x" << GRID_SIZE << " grid:" << endl; cout << "Your x co-ord: "; cin >> x; cout << "Your y co-ord: "; cin >> y; // Validate data inputted by user if (x < 1 || x > GRID_SIZE || y < 1 || y > GRID_SIZE) { cout << "You chose co-ordinates outside of the battleground!" << endl; cout << "Try again..." << endl; } else { if (battleground[y - 1][x - 1]) { // HIT if (player_battleground[y - 1][x - 1] == TileType::NONE) { incrementScore(); player_battleground[y - 1][x - 1] = TileType::HIT; cout << endl << "HIT!" << endl; } else { cout << "You have already shot at this co-ordinate!" << endl; } } else { // MISS if (player_battleground[y - 1][x - 1] == TileType::NONE){ loseLife(); player_battleground[y - 1][x - 1] = TileType::MISS; cout << endl << "MISS!" << endl; } else { cout << "You have already shot at this co-ordinate!" << endl; } } printPlayerBattleground(); end = checkEnd(); } } }
//This is the function the game loop calls void globalHitTest(){ //Iterate through array of geese for(int i = 0; i < maxGeese; i++){ //Iterate through array of bullets for(int j = 0; j < maxBullet; j++){ //Perform hit test if(hitTestBullet(b[j], ge[i])){ //Set invalid b[j].valid = false; ge[i].valid = false; //Update score score+=incrementScore(); } } //Check if goose has hit the gun if(hitTestGun(ge[i], g)){ //Set goose to invalid and lose a life ge[i].valid = false; lives--; } } }
void Game::tick() { ballMove(); forceRacketIntoField(); while (true) { bool hit = false; Brick* pBrickRef = nullptr; HitRecord hr; HitRecord lhr; if (hitTopField(lhr) == true && lhr.getRollback() > hr.getRollback()) { hit = true; hr = lhr; } if (hitRightField(lhr) == true && lhr.getRollback() > hr.getRollback()) { hit = true; hr = lhr; } //Bottom border if (hitBottomField(lhr) == true && lhr.getRollback() > hr.getRollback()) { setBallOwner(); ballExit(); hr = lhr; break; } if (hitLeftField(lhr) && lhr.getRollback() > hr.getRollback()) { hit = true; hr = lhr; } hitRacket(lhr, hr, hit); pBrickRef = hitBrick(lhr, hr, hit); if (hit) { setBallPosition(hr); if (pBrickRef != nullptr) { pBrickRef->strength()--; incrementScore(); if (pBrickRef->strength() == 0) { removeBrick(pBrickRef); } } } else { break; } } }
void Game::incrementScore() { incrementScore(m_pPlayer); }
void painting(void){ //receive from other players if (ir_uart_read_ready_p ()){ paintP2 = 1; //get their position from the signal player2_pen.pos.x = ir_uart_getc(); player2_pen.pos.y = ir_uart_getc(); /* update the information about other player territory. */ setTerritoryP2(player2_pen.pos.y, player2_pen.pos.x); tinygl_update (); } if (navswitch_push_event_p (NAVSWITCH_NORTH) && player1_pen.pos.y > 0) { player1_pen.pos.y--; paintP1= 1; ir_uart_putc(player1_pen.pos.x); ir_uart_putc(player1_pen.pos.y); //check if the player lands on their own territory if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){ //check if the player lands on other player territory if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){ specialScore(); } //the player lands on territory that hasn't been painted else{ incrementScore(); } } //update information about the player territory setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x); } if (navswitch_push_event_p (NAVSWITCH_SOUTH) && player1_pen.pos.y < TINYGL_HEIGHT - 1) { player1_pen.pos.y++; paintP1= 1; ir_uart_putc(player1_pen.pos.x); ir_uart_putc(player1_pen.pos.y); //check if the player lands on their own territory if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){ //check if the player lands on other player territory if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){ specialScore(); } //the player lands on territory that hasn't been painted else{ incrementScore(); } } //update information about the player territory setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x); } if (navswitch_push_event_p (NAVSWITCH_EAST) && player1_pen.pos.x < TINYGL_WIDTH - 1) { player1_pen.pos.x++; paintP1= 1; ir_uart_putc(player1_pen.pos.x); ir_uart_putc(player1_pen.pos.y); //check if the player lands on their own territory if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){ //check if the player lands on other player territory if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){ specialScore(); } //the player lands on territory that hasn't been painted else{ incrementScore(); } } //update information about the player territory setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x); } if(navswitch_push_event_p(NAVSWITCH_WEST) && player1_pen.pos.x > 0) { player1_pen.pos.x--; paintP1= 1; ir_uart_putc(player1_pen.pos.x); ir_uart_putc(player1_pen.pos.y); //check if the player lands on their own territory if(!isTerritoryTakenP1(player1_pen.pos.y, player1_pen.pos.x)){ //check if the player lands on other player territory if(isTerritoryTakenP2(player1_pen.pos.y, player1_pen.pos.x)){ specialScore(); } //the player lands on territory that hasn't been painted else{ incrementScore(); } } //update information about the player territory setTerritoryP1(player1_pen.pos.y, player1_pen.pos.x); } if (paintP1) tinygl_draw_point (player1_pen.pos, player1_pen.state); tinygl_update(); if (paintP2) tinygl_draw_point (player2_pen.pos, player2_pen.state); tinygl_update(); }