/* Fly saucer */ #ifdef __TINY__ #error BGIDEMO will not run in the tiny model. #endif #include #include #include #include #include #include #include int main (void) { clrscr (); int gdriver = DETECT, gmode, errorcode; initgraph (&gdriver, &gmode, "c:\\tclite\\bgi"); errorcode = graphresult (); if (errorcode != grOk) { printf ("Graphics error: %s\n", grapherrormsg (errorcode)); printf ("Press Anykey to halt: "); getch (); exit (1); } int MaxX, MaxY, MaxColors; MaxX = getmaxx(); MaxY = getmaxy(); static int r = 20; static int StartX = 100; static int StartY = 50; struct viewporttype vp; int PauseTime, x, y, ulx, uly, lrx, lry, size, i, width, height, step; void *Saucer; getviewsettings( &vp ); setfillstyle( SOLID_FILL, getmaxcolor() ); fillellipse(StartX, StartY, r, (r/3)+2); ellipse(StartX, StartY-4, 190, 357, r, r/3); line(StartX+7, StartY-6, StartX+10, StartY-12); circle(StartX+10, StartY-12, 2); line(StartX-7, StartY-6, StartX-10, StartY-12); circle(StartX-10, StartY-12, 2); /* Read saucer image */ ulx = StartX-(r+1); uly = StartY-14; lrx = StartX+(r+1); lry = StartY+(r/3)+3; width = lrx - ulx + 1; height = lry - uly + 1; size = imagesize(ulx, uly, lrx, lry); Saucer = malloc( size ); getimage(ulx, uly, lrx, lry, Saucer); putimage(ulx, uly, Saucer, XOR_PUT); /* Plot some "stars" */ //for ( i=0 ; i<1000; ++i ) //putpixel(random(MaxX), random(MaxY), random( MaxColors-1 )+1); x = MaxX / 2; y = MaxY / 2; PauseTime = 70; x = getmaxx(); y = getmaxy()/2; /* until a key is hit */ while ( !kbhit() ) { /* Draw the Saucer */ putimage(x, y, Saucer, XOR_PUT); /* draw image */ delay(PauseTime); putimage(x, y, Saucer, XOR_PUT); /* erase image */ /* Move Saucer */ x--; //for (i=0; i<1; i++ ) //delay (1); if (x == 0) { x = getmaxx(); } /* step = random( 2*r ); if ((step/2) % 2 != 0 ) step = -1 * step; x = x + step; step = random( r ); if ((step/2) % 2 != 0 ) step = -1 * step; y = y + step; */ if (vp.left + x + width - 1 > vp.right) x = vp.right-vp.left-width + 1; else if (x < 0) x = 0; if (vp.top + y + height - 1 > vp.bottom) y = vp.bottom-vp.top-height + 1; else if (y < 0) y = 0; } free( Saucer ); return 0; }