void advanceGame(void* gameMemory, OOGameInput* input, OOGameOutput* output) { cbgame * game = (cbgame*) gameMemory; oofloat respawnTime = 2.f; if(game->p1.score == CombatGame_ScoreLimit) { //Player 1 wins } else if (game->p2.score == CombatGame_ScoreLimit) { //Player 2 Wins } if(!game->p1.alive && game->time >= game->p1.timeOfDeath + respawnTime) { respawnPlayer(game, &game->p1); } else if (!game->p2.alive && game->time >= game->p2.timeOfDeath + respawnTime) { respawnPlayer(game, &game->p2); } game->input = input; game->output = output; if( !game->initialised ) { initGame(game); } game->moveDelta = game->p1.x; updateGame(game); game->moveDelta -= game->p1.x; clearScreen(game); moveWall(game); drawPlayer(game, &game->p2); drawPlayer(game, &game->p1); drawArena(game); if(game->p1.missile.isFiring) { drawMissile(game,&game->p1); } if(game->p2.missile.isFiring) { drawMissile(game,&game->p2); } game->time += game->input->dt; }
/******************************************************************* * Function: char moveBehavior (int) * Input Variables: int * Output Return: char * Overview: This is the flow for the behavior of the robot ********************************************************************/ char moveBehavior( int behavior) { // Check the moveAway behavior for obstacles if(moveAway()){ Ierror = 0; return 1; } // Check the moveLight behavior for light. // If it sees light track the light. // If it is in front of the light kill moveLight and move to moveRetreat if(lightFlagStatus==0){ if(moveTrackLight()){ Ierror = 0; return 2; } } // Check the moveRetreat behavior. // If it returns a zero (contacts detect obstacle) have it stop itself and inhibit moveWall if(retreatFlagStatus==1){ if(moveRetreat()){ Ierror = 0; return 3; } } // Run the moveWall behavior if(moveWall()){ Ierror = 0; return 4; } // if(moveWander()){ // Ierror = 0; // return 5; // } return 0; }
/******************************************************************* * Function: void moveMap(void) * Input Variables: void * Output Return: void * Overview: moves the robot through the map ********************************************************************/ void moveMap( void ) { char isDone = 0; pidController(0,RESET); switch(currentMove){ case MOVE_LEFT: move_arc_stwt(POINT_TURN, LEFT_TURN, 30, 30, 0); STEPPER_stop(STEPPER_BOTH, STEPPER_BRK_ON); TMRSRVC_delay(BRAKE_DELAY); STEPPER_stop(STEPPER_BOTH, STEPPER_BRK_OFF); break; case MOVE_FORWARD: setOdometry(WALL_STEP); while(!isDone){ checkIR(); isDone = moveWall(); } STEPPER_stop(STEPPER_BOTH, STEPPER_BRK_ON); TMRSRVC_delay(BRAKE_DELAY); STEPPER_stop(STEPPER_BOTH, STEPPER_BRK_OFF); // move_arc_stwt(NO_TURN, 45, 10, 10, 0); break; case MOVE_RIGHT: move_arc_stwt(POINT_TURN, RIGHT_TURN, 30, 30, 0); STEPPER_stop(STEPPER_BOTH, STEPPER_BRK_ON); TMRSRVC_delay(BRAKE_DELAY); STEPPER_stop(STEPPER_BOTH, STEPPER_BRK_OFF); break; default: LCD_printf("Whatz2?!"); break; } }