//Setup void Start() { OpenFileSystem(); OpenGraphics(); SetLineWidth(1); //needed otherwise we draw huge thick points! //Register bitmaps OpenImageRegister(); logoImage = RegisterImage(_binary_Images_battle_bmp_start,_binary_Images_battle_bmp_end - _binary_Images_battle_bmp_start); signatureImage = RegisterImage(_binary_Images_rorschach_bmp_start,_binary_Images_rorschach_bmp_end - _binary_Images_rorschach_bmp_start); tankImage = RegisterImage(_binary_Images_tank_bmp_start,_binary_Images_tank_bmp_end - _binary_Images_tank_bmp_start); CloseImageRegister(); sweepStepCount=0; ResetTimer(); arrowRefAngle=0; sweepAngle = 2 * PI / SWEEPSTEPS; arrowX=20; arrowY=20; radarX=140; radarY=20; sweepArm.x=140; sweepArm.y=20; oldKeystate=0; refreshCount=0; //Load calibration data, if any exists rotateSleep = ROTATESLEEP; LoadCalibration(); Splash(); }
void Start() { OpenFileSystem(); OpenGraphics(); OpenMotors(); OpenIR(); //Register images OpenImageRegister(); logoImage = RegisterImage(_binary_Images_bigtrakr_bmp_start,_binary_Images_bigtrakr_bmp_end - _binary_Images_bigtrakr_bmp_start); signatureImage = RegisterImage(_binary_Images_rorschach_bmp_start,_binary_Images_rorschach_bmp_end - _binary_Images_rorschach_bmp_start); upImage = RegisterImage(_binary_Images_up_bmp_start,_binary_Images_up_bmp_end - _binary_Images_up_bmp_start); downImage = RegisterImage(_binary_Images_down_bmp_start,_binary_Images_down_bmp_end - _binary_Images_down_bmp_start); markerImage = RegisterImage(_binary_Images_marker_bmp_start,_binary_Images_marker_bmp_end - _binary_Images_marker_bmp_start); CloseImageRegister(); steps=0; menuItem=1; menuNum = 1; mode=1; //menu IRState=false; rotateSleep = ROTATESLEEP; LoadCalibration(); white=RGBColor(255,255,255,0); green=RGBColor(0,255,0,0); red=RGBColor(255,0,0,0); blue=RGBColor(0,0,255,0); black=RGBColor(0,0,0,0); grey=RGBColor(128,128,128,0); //Splash Splash(); Sleep( 2000 ); ClearScreen(); Show(); }
void LoseLife(char *reason) { //Draw cracked screen - but draw all the rest of the world & hud first CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); //finally! DrawCrackedScreen(); SetTextColor(RED); DrawText(25,40,reason); if (--lives<=0) { SetTextColor(GREEN); DrawText(30,55,"GAME OVER!"); } Show(); PlaySound(SOUND_EXPLOSION); //dead? if (lives<=0) { Sleep(2000); //Reset back to splash screen ResetTimer(); mode=0; Splash(); } else { // Hit but still going InitialiseWorld(); } }
void PlaySound(char *filename) { CloseGraphics();// free up our processor to do audio digitizing StartAudioPlayback(filename); // begin playing file // wait for audio to finish while( IsAudioPlaying() ) { Sleep( 50 ); } OpenGraphics();// open the display again }
//Splash screen void Splash() { ResetTimer(); //we're going to use it for random seed //Setup a world with a tank and a pyramid in specific places CloseGraphics(); OpenGraphics(); Point3d centre; world=CreateNewWorld(); //A tank pointing straight at us centre=CreatePoint(0.0,0.0,45.0); obj=CreateTank(GREEN, centre, 4.5); RotateObjectYAxis(&obj, 2.0 * PI / 360.0 * 195); AddObjectToWorld(&world, obj); //A yellow pyramid behind the tank and to the right centre=CreatePoint(10.0, 0.0, 70.0); obj=CreatePyramid(YELLOW, centre, 5.0); RotateObjectYAxis(&obj, 3.0*PI/5.0); AddObjectToWorld(&world, obj); //A blue cube behind the tank and to the left centre=CreatePoint(-10.0, 0.0, 60.0); obj=CreateCube(BLUE, centre, 5.0); RotateObjectYAxis(&obj, 195.0*PI/180.0); AddObjectToWorld(&world,obj); //Draw world, add splash graphics, prompt to start cameraPos=CreatePoint(0.0,5.0,0.0); cameraAngle=CreatePoint(0.0,0.0,0.0); DrawWorld(&world, cameraPos, cameraAngle); SetTextColor(GREEN); DrawText(5,25, "by RorschachUK"); SetTextColor(CYAN); DrawText(5,100, "Help"); DrawText(110,100,"Start"); DrawImage(logoImage, 5,5,RGBColor(253,255,252,0)); DrawImage(signatureImage, 135,24,BLACK); Show(); Sleep(100); mode=0; }
//Help screen void ShowHelp() { CloseGraphics(); OpenGraphics(); //DrawImage(logoImage, 5,5,RGBColor(253,255,252,0)); SetTextColor(WHITE); DrawText(6, 7, "Find the enemy &"); DrawText(6, 22, "shoot him before"); DrawText(6, 37, "he shoots you!"); SetTextColor(GREEN); DrawText(6, 52, "Press GO to fire,"); SetTextColor(RED); DrawText(6, 67, "beware of the red"); DrawText(6, 82, "exploding barrels!"); SetTextColor(CYAN); DrawText(120,100, "OK"); Show(); mode=2; }
int main() { int r; #if GRAPHICS struct Button *but,*button; boolean quit=FALSE; context = (struct Context *)malloc(sizeof(struct Context)); but= context->Buttons= CreateButton(RUN_BUTTON,"RUN/STOP",WINDOW_W-50,WINDOW_H-90); but= but->Next=CreateButton(DISPLAY_RATE_UP_BUTTON,"+",WINDOW_W-40,WINDOW_H-60); but= but->Next=CreateButton(DISPLAY_RATE_DOWN_BUTTON,"-",WINDOW_W-60,WINDOW_H-60); but= but->Next=CreateButton(QUIT_BUTTON,"QUIT",WINDOW_W-50,WINDOW_H-30); display_rate=1L; OpenGraphics(); #endif robots = (struct Robot **)malloc(NR*sizeof(struct Robot*)); for (r=0;r<NR;r++) { robots[r] = (struct Robot *)malloc(sizeof(struct Robot)); } InitFiles(); InitGlobal(); for (r=0;r<NR;r++) { InitRobot(r,robots[r]); } #if GRAPHICS while(quit == FALSE) { button=PressButton(context); switch(button->Value) { case QUIT_BUTTON: quit = TRUE; break; case DISPLAY_RATE_UP_BUTTON: display_rate*=10L; if (display_rate>100000L) display_rate=100000L; display_rate-=display_rate%10L; if (display_rate<1L) display_rate=1L; DrawWindow(context); break; case DISPLAY_RATE_DOWN_BUTTON: if (display_rate>9L) display_rate/=10L; display_rate-=display_rate%10L; if (display_rate<1L) display_rate=1L; DrawWindow(context); break; case RUN_BUTTON: #endif do { for (r=0;r<NR;r++) { RunRobot(r,robots[r]); EvalRobot(t,r,robots[r]); } t++; if (t>TM) { #if GRAPHICS CloseGraphics(); #endif return(1); exit(1); } #if GRAPHICS if (t%display_rate==0L) { DrawWindow(context); #if DISTY*(DISTY-2) if (t%(250L*display_rate)==0L) { DrawPlate(0,0,WINDOW_W-1,WINDOW_H-1,BLACK,PLATE_UP); } #endif } #endif } #if GRAPHICS while (UnpressButton(context,button)==FALSE); break; #else while (TRUE); #endif #if GRAPHICS } button->State = PLATE_UP; } CloseGraphics(); #endif return(1); }
//Main program loop - Run gets called until it returns false bool Run() { //Main loop - get keypresses and interpret them keystate=GetRemoteKeys(); if(keystate & KEY_HOME) { return false; } switch(mode) { case 0: { //Splash screen if (keystate & KEY_INPUT2) { //Button B //Start game InitialiseGame(); PlaySound(SOUND_BEEP); } if (keystate & KEY_INPUT1) { //Button A //show help ShowHelp(); PlaySound(SOUND_BEEP); } } break; case 2: { //Help - wait for 'OK' press if (keystate & KEY_INPUT2) { //Button B //Reset back to splash screen ResetTimer(); mode=0; Splash(); PlaySound(SOUND_BEEP); } } break; case 1: { //Game if (keystate & KEY_INPUT1) { //Button A //Reset back to splash screen ResetTimer(); mode=0; Splash(); } if (keystate & KEY_RUN) { //Go button //Fire! PlaySound(SOUND_SHOOT); refreshCount = 0; int hit; hit = LineHitsObject(cameraPos, cameraAngle); if (hit == tankObjectIndex) { //we hit the tank! score += 100; CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); DrawExplosion(); DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); PlaySound(SOUND_EXPLOSION); PlaceTank(cameraPos, cameraAngle); } } //Have the movement sticks changed? This bit doesn't care about buttons if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) { MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); arrowRefAngle=cameraAngle.y; baselinePos=cameraPos; ResetTimer(); oldKeystate = keystate; if (keystate==0) //we've just stopped moving refreshCount=0; } if (mode==1) { if (sweepStepCount == SWEEPSTEPS) sweepStepCount=0; if (--behaviourCount<0) ChooseBehaviour(); MoveTank(); MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate); //is it time to reset the tank model? Otherwise it gradually gets distorted if (--resetCount<0) { //Refresh the tank model which is prone to getting distorted //due to cumulative inaccuracies of sin/cos approximations Point3d angle=world.objects[tankObjectIndex].heading; Point3d tankPos=world.objects[tankObjectIndex].centre; world.objects[tankObjectIndex]=tank; MoveObject(&(world.objects[tankObjectIndex]), tankPos); RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y); resetCount=50; } //Is it time to redraw the world? if (--refreshCount<0) { //Seems a bit brutal to have to close graphics but it's //the only way to clear the screen that'll let us draw //on it properly again - ClearScreen or ClearRectangle mess up CloseGraphics(); OpenGraphics(); DrawWorld(&world, cameraPos, cameraAngle); DrawHUD(); refreshCount=2; } DrawArrow(cameraAngle.y); DrawRadarDots(true); DrawRadarArm(sweepAngle * sweepStepCount++); DrawRadarDots(false); SetTextColor(CYAN); DrawText(6,100,"Quit"); Show(); //just in case we changed mode... if (mode==0) Splash(); } } } Sleep(50); return true; }