void WhistleHandler::update(GameInfo& gameInfo) { gameInfo = theRawGameInfo; if(gameInfo.state != lastGameState && gameInfo.state == STATE_SET) timeOfLastSetState = theFrameInfo.time; lastGameState = gameInfo.state; if(gameInfo.state != STATE_SET) overrideGameState = false; else if(!overrideGameState && gameInfo.gameType == GAME_PLAYOFF && gameInfo.secondaryState == STATE2_NORMAL) overrideGameState = checkWhistle() && checkBall(); if(overrideGameState) { if(checkForIllegalMotionPenalty()) { timeOfLastSetState = theFrameInfo.time; overrideGameState = false; } else { gameInfo.state = STATE_PLAYING; } } }
//================================ //MOVE //================================ void Match::moveUp(Player *p) { // cout << " Moves Forward" << endl; if(p->getStatus() == p->BALL_WITH_OPP) { dodge(p); } else { int team = p->getTeam(); if(team == 1) { p->setPosX(p->getPosX() + 1); } else if(team == 2) { p->setPosX(p->getPosX() - 1); } checkBall(p); if(p->getNumber() == ball->getPlayer()) { updateBall(p); screen->updateMove(p, p->MOVE_UP); } } checkWin(p); }
void SBTeam::createJobs() { checkBall(); checkEnemies(); checkPowerUps(); for (int i=0; i<botControllers_.size(); ++i) { addJob(Job(Job::jLand, 20)); addJob(Job(Job::jCharge, 20)); } }
//Assigns values to an array that stores the information around the robot void scan(int & distance, int & angle, int & color) { //stores angle of found ball angle = nMotorEncoder[motorA]; //Goes forward to check the ball checkBall(color, distance); //Returns back before continuing the scan returnPos(distance); }
void Match::moveRight(Player *p) { //cout << " Moves Right" << endl; int team = p->getTeam(); if(team == 1) { p->setPosY(p->getPosY() - 1); } else if(team == 2) { p->setPosY(p->getPosY() + 1); } checkBall(p); if(p->getNumber() == ball->getPlayer()) { updateBall(p); screen->updateMove(p, p->MOVE_RIGHT); } }
void Match::moveBack(Player *p) { //cout << " Moves Backward" << endl; int team = p->getTeam(); if(team == 1) { p->setPosX(p->getPosX() - 1); } else if(team == 2) { p->setPosX(p->getPosX() + 1); } checkBall(p); if(p->getNumber() == ball->getPlayer()) { updateBall(p); screen->updateMove(p, p->MOVE_DOWN); } }
void Board::setBall(int x, int y) { ball->setPos(x, y); checkBall(x, y); }
void Match::sim(MatchScreen* screen) { this->screen = screen; resetRound(); int timer; for(timer = 0; timer < 180 && roundOver == false; timer+=3) { screen->tick(timer); cout << teamOne->getPlayer(0)->getRole()<< endl; screen->resetKillFeed(); cout<< "TIME: " << timer << endl; setMoveOrder(); for(int i = 0; i < playersToMove.size() && roundOver == false; i++) { Player* p = playersToMove[i]; checkBall(p); setPlayerStatus(p); int act = p->getAction(); //cout << p->getName(); if(act == p->MOVE_UP) { moveUp(p); } else if(act == p->MOVE_DOWN) { moveBack(p); } else if(act == p->MOVE_LEFT) { moveLeft(p); } else if(act == p->MOVE_RIGHT) { moveRight(p); } else if(act == p->PASS) { pass(p); } else if(act == p->MOVE_TO_BALL) { moveTowardBall(p); } else if(act == p->ATTACK) { attack(p); } else if(act == p->MOVE_TO_GOAL) { moveTowardGoal(p); } else if(act == p->MOVE_TO_OWN_GOAL) { moveToOwnGoal(p); } } cout << "BALL TEAM: " << ball->getTeam() << " PLAYER: " << ball->getPlayer() << endl; screen->updateStatScreen(teamOne, teamTwo); screen->displayPlayers(teamOne, teamTwo, ball); QTime dieTime= QTime::currentTime().addSecs(1); while( QTime::currentTime() < dieTime ) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } cout << "GAME OVER TIME: " << timer << endl; if(winningTeam == 1 || winningTeam == 2) { cout << "WINNER: Team " << winningTeam << endl; } else { cout << "DRAW" << endl; } cout << teamOne->getScore() << "-" << teamTwo->getScore() << endl; }
void updateGame(void) { // Get game time timer.tick(); GameTime gameTime = timer.getGameTime(); // Get input keyboard.getState(currState); gameInput(); if (!paused && !won) { // Update game objects ball.update(gameTime, 0, window.height); player.update(gameTime, 0, window.height); ai.update(gameTime, 0, window.height, ball.position); GLuint halfPoints = static_cast<GLuint>(POINTS_TO_WIN * 0.5f); if (playerScore >= halfPoints || aiScore >= halfPoints) { // Increase obstacle speed as the stakes heighten GLuint higherScore = std::max(playerScore, aiScore); GLuint diff = POINTS_TO_WIN - higherScore; float t = 1.0f / diff; float minSpeed = 200.0f; float maxSpeed = 600.0f; float speed = Math::lerp(minSpeed, maxSpeed, t); o1.update(gameTime, 125.0f, 475.0f, speed); o2.update(gameTime, 125.0f, 475.0f, speed); } // Resolve collisions if(ball.position.distanceToSquared(player.position) <= 50.0f * 50.0f) { player.checkCollisions(ball); } else if(ball.position.distanceToSquared(ai.position) <= 50.0f * 50.0f) { ai.checkCollisions(ball); } else if(ball.position.distanceToSquared(o1.position) <= 50.0f * 50.0f) { o1.checkCollisions(ball); } else if(ball.position.distanceToSquared(o2.position) <= 50.0f * 50.0f) { o2.checkCollisions(ball); } // Scoring checkBall(); // Save input state prevState = currState; // Force game to redisplay glutPostRedisplay(); } }