Game::Game(){ //initialise the invaders invader_group = new InvaderGroup(Position(50,450), Scale(20,15), 15, MoveDistance(0,5,5,5), MoveRange(700,230,10,790), 11, 5, 2); //invader group //initialise the tank theTank = Tank("image/tank.png", Position(400,60), Scale(25,15), MoveDistance(0,0,10,10), MoveRange(0,0,10,790),3); //tank for(int i = 0; i < 4; i++) { //initialise the shields theShield[i] = Shield("image/shield.png", Position(100+i*200,200), Scale(50,30), 10); } invader_last_time = -1; invader_current_time = -1; invader_step_time = 300; //300 ms bullet_last_time = -1; bullet_current_time = -1; bullet_step_time = 30; //30 ms //Assignment 4 tank_last_time = -1; tank_last_milli = -1; tank_current_time = -1; tank_current_milli = -1; tank_step_time = 500; // 500 ms conti = true; srand(time(NULL)); lose = false; theTank.readHighScore(); }
void IDT_MapIntersection(char* leftPath, char* rightPath, char* forwardPath) { MoveDistance(1, 100); StandardMessage msg; xQueueReset(MsgQueue_MapSensor_Interrupt); xQueueReceive( MsgQueue_MapSensor_Interrupt, &msg, 500 ); *leftPath = (char)(msg.data == 15 || msg.data == 47); *rightPath = (char)(msg.data == 60 || msg.data == 62); MoveDistance(39, 600); xQueueReset(MsgQueue_MapSensor_Interrupt); xQueueReceive( MsgQueue_MapSensor_Interrupt, &msg, 500 ); *forwardPath = (msg.data != 0); }
void ExecuteTurn(char data) { PLIB_PORTS_Write(PORTS_ID_0, PORT_CHANNEL_B, data); switch(data) { case 'r': TurnRight(); break; case 'l': TurnLeft(); break; case 'f': MoveDistance(16, 600); break; case 't': TurnAround(); MoveDistance(16, 600); break; case 'S': moveRobot(0, 0); while(true); } }
int main() { //Main demonstration execution order Init(); //Short course: // - FW 2 meters (using mouse) // - Follow wall for 2 meters (wall following algorithm) // - FW until line reached // - Follow line until dock detected (line following algorithm) if(1) { currentState = TRAVEL; Play(BEEP); Init_RIT(INTERVAL); while(!go); MoveDistance(200.0f,0); RIT_Cmd(LPC_RIT, DISABLE); currentState = WALLF; Play(BEEP); FollowWall(30.0f, LEFT); currentState = LINEF; Play(BEEP); StartLineFollowing(); } //Long course: // - FW 2 meters (using mouse) // - Follow wall for 2 meters (wall following algorithm) // - Turn 90 degrees right (using mouse) // - FW 2 meters (using mouse) // - Turn 90 degrees left (using mouse) // - FW 2 meters (using mouse) // - Follow wall for 2 meters (wall following algorithm) // - FW until line reached // - Follow line until dock detected (line following algorithm) if(0) { currentState = TRAVEL; Play(BEEP); Init_RIT(INTERVAL); while(!go); MoveDistance(200.0f,0); RIT_Cmd(LPC_RIT, DISABLE); currentState = WALLF; Play(BEEP); FollowWall(30.0f, LEFT); currentState = TRAVEL; Play(BEEP); Init_RIT(INTERVAL); TurnAngle(90.0f); RoughMoveDistance(120.0f); TurnAngle(-90.0f); RoughMoveDistance(200.0f); RIT_Cmd(LPC_RIT, DISABLE); currentState = WALLF; Play(BEEP); FollowWall(28.0f, RIGHT); currentState = LINEF; Play(BEEP); StartLineFollowing(); } if(0) { Calibrate(); dockNotFound = true; WriteByte((char) 0xBB); // Start PID WriteByte((char)((int)127.0f*0.4f)); // Max motor speed char parameters[4] = {0x02, 0x01, 0x03, 0x02}; Write(parameters, 4); // Parameters to adjust motor speed differences while (dockNotFound); } //After the run the Pololu will halt here until it is reset. Stop(); while(1); }