/* A Flying Space Ship Program */ /* A Screen Saver Program Jason Gradziel April 1 1997 */ #include #include #include #include #include #include int drawship(int x7); // Draws the four different moving objects int drawland(int y_str); // Draws the random land int y7, s; // Variables for the comet in drawship int main () { clrscr (); int gdriver = DETECT, gmode, errorcode; initgraph (&gdriver, &gmode, "c:\\turboc\\bgi"); errorcode = graphresult (); if (errorcode != grOk) { printf ("Graphics error: %s\n", grapherrormsg (errorcode)); printf ("Press Anykey to halt: "); getch (); exit (1); } /* "graphics main prorgam lines" go here */ int y_str, y_end, x7, xmax=getmaxx(), ymax=getmaxy(); randomize; y_str = getmaxy() / 2 + 110; // starting point for the land in drawland s = 1; // starting size of the comet y7 = 20; // starting points of the comet (x, y) x7 = 20; while ( !kbhit() ) // main program loops { y_end = drawland(y_str); setfillstyle(SOLID_FILL, 15); floodfill(xmax/2, ymax, 15); y_str = y_end; x7 = drawship(x7); cleardevice(); } getch (); closegraph (); return 0; } int drawship(int x7) { randomize; int MaxX, MaxY, MaxColors; MaxX = getmaxx(); MaxY = getmaxy(); static int r = 20; // points for the objects to be drawn static int StartX = 100; // in so they can be read in memory static int StartY = 50; struct viewporttype vp; struct viewporttype vp1; struct viewporttype vp2; struct viewporttype vp3; int PauseTime, ulx, uly, lrx, lry, i, size, x, y, width, height, step, // Saucer variables size1, y1, x1, width1, height1, step1, // Ty Fighter variables size2, x2, y2, step2, // Sun variables size3, step3; // Comet variables void *Saucer; void *TyFighter; void *Sun; void *Comet; /* Saucer Ship */ getviewsettings( &vp ); setfillstyle( SOLID_FILL, 15 ); //main part setcolor(15); ellipse(StartX, StartY, 0, 360, r, (r/3)+2); fillellipse(StartX, StartY, r, (r/3)+2); line(StartX+7, StartY+7, StartX+12, StartY+13); //Bellow wheels setcolor(7); setfillstyle( SOLID_FILL, 7); fillellipse(StartX+12, StartY+13, 2, 2); setcolor(15); line(StartX-7, StartY+7, StartX-12, StartY+13); setcolor(7); setfillstyle( SOLID_FILL, 7); fillellipse(StartX-12, StartY+13, 2, 2); line(StartX, StartY-8, StartX, StartY-15); //entena on top setcolor(14); circle(StartX, StartY-15, 1); setcolor(15); line(StartX-4, StartY-15, StartX-5, StartY-15); // line around entena line(StartX+4, StartY-15, StartX+5, StartY-15); line(StartX, StartY-19, StartX, StartY-20); line(StartX-3, StartY-17, StartX-4, StartY-18); line(StartX+3, StartY-17, StartX+4, StartY-18); line(StartX-23, StartY, StartX-20, StartY); //lines on the side line(StartX+20, StartY, StartX+23, StartY); setcolor(8); setfillstyle( SOLID_FILL, 8); fillellipse(StartX-6, StartY-3, 3, 2); // eyes fillellipse(StartX+6, StartY-3, 3, 2); setcolor(4); ellipse(StartX-6, StartY-3, 0, 360, 1, 1); // iner eyes ellipse(StartX+6, StartY-3, 0, 360, 1, 1); setcolor(8); ellipse(StartX, StartY+2, 200, 340, 8, 2); //mouth /* Read Saucer image */ ulx = StartX-(r+3); uly = StartY-20; lrx = StartX+(r+3); lry = StartY+(r/3)+10; 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); /* Ty Fighter */ getviewsettings( &vp1 ); setcolor(15); circle(StartX, StartY, r-5); //main circle ellipse(StartX-22, StartY-8, 200, 0, 8, 4); //left side of attachment ellipse(StartX-22, StartY+8, 0, 160, 8, 4); ellipse(StartX+22, StartY-8, 180, 340, 8, 4); //right side of attachment ellipse(StartX+22, StartY+8, 20, 180, 8, 4); line(StartX-30, StartY-20, StartX-30, StartY+20); //left side wing line(StartX-30, StartY-20, StartX-32, StartY-22); line(StartX-32, StartY-22, StartX-34, StartY-20); line(StartX-30, StartY+20, StartX-32, StartY+22); line(StartX-32, StartY+22, StartX-34, StartY+20); line(StartX-34, StartY-20, StartX-34, StartY+20); setcolor(1); line(StartX-32, StartY-6, StartX-32, StartY+6); setcolor(15); line(StartX+30, StartY-20, StartX+30, StartY+20); //right side wing line(StartX+30, StartY-20, StartX+32, StartY-22); line(StartX+32, StartY-22, StartX+34, StartY-20); line(StartX+30, StartY+20, StartX+32, StartY+22); line(StartX+32, StartY+22, StartX+34, StartY+20); line(StartX+34, StartY-20, StartX+34, StartY+20); setcolor(1); line(StartX+32, StartY-6, StartX+32, StartY+6); setcolor(7); circle(StartX, StartY, 7); //window circle(StartX, StartY, 1); line(StartX-1, StartY, StartX-7, StartY); line(StartX+1, StartY, StartX+7, StartY); line(StartX, StartY, StartX-5, StartY-5); line(StartX, StartY, StartX+5, StartY+5); line(StartX, StartY, StartX-5, StartY+5); line(StartX, StartY, StartX+5, StartY-5); setcolor(1); ellipse(StartX-23, StartY-4, 270, 0, 7, 4); //left side decal ellipse(StartX-23, StartY+4, 0, 90, 7, 4); ellipse(StartX+23, StartY-4, 180, 270, 7, 4); //right side decal ellipse(StartX+23, StartY+4, 90, 180, 7, 4); setcolor(14); line(StartX, StartY-15, StartX, StartY-17); //lights on ship setcolor(4); line(StartX-8, StartY+14, StartX-8, StartY+16); setcolor(2); line(StartX+8, StartY+14, StartX+8, StartY+16); /* Read Ty Fighter image */ ulx = StartX-(r+14); uly = StartY-22; lrx = StartX+(r+14); lry = StartY+(r/3)+16; width1 = lrx - ulx + 1; height1 = lry - uly + 1; size1 = imagesize(ulx, uly, lrx, lry); TyFighter = malloc( size1 ); getimage(ulx, uly, lrx, lry, TyFighter); putimage(ulx, uly, TyFighter, XOR_PUT); /* Sun */ getviewsettings( &vp2 ); setcolor(14); circle(StartX, StartY, r-5); line(StartX-19, StartY, StartX-28, StartY); line(StartX+19, StartY, StartX+28, StartY); line(StartX, StartY-19, StartX, StartY-28); line(StartX, StartY+19, StartX, StartY+28); line(StartX-13, StartY-13, StartX-20, StartY-20); line(StartX+13, StartY+13, StartX+20, StartY+20); line(StartX-13, StartY+13, StartX-20, StartY+20); line(StartX+13, StartY-13, StartX+20, StartY-20); ellipse(StartX-6, StartY-4, 0, 360, 3, 2); ellipse(StartX+6, StartY-4, 0, 360, 3, 2); ellipse(StartX, StartY+4, 200, 340, 8, 3); /* Read Sun image */ ulx = StartX-(r+10); uly = StartY-30; lrx = StartX+(r+10); lry = StartY+(r/3)+22; width = lrx - ulx + 1; height = lry - uly + 1; size2 = imagesize(ulx, uly, lrx, lry); Sun = malloc( size2 ); getimage(ulx, uly, lrx, lry, Sun); putimage(ulx, uly, Sun, XOR_PUT); /* Moving Comet */ getviewsettings( &vp3 ); setfillstyle(SOLID_FILL, 15); fillellipse(x7, y7, s, s); putpixel(x7-s, y7, WHITE); putpixel(x7-s-1, y7, WHITE); putpixel(x7-s-2, y7, WHITE); ulx = x7-s-5; uly = y7-s-5; lrx = x7+s+5; lry = y7+s+5; width = lrx - ulx + 1; height = lry - uly + 1; size3 = imagesize(ulx, uly, lrx, lry); Comet = malloc( size3 ); getimage(ulx, uly, lrx, lry, Comet); putimage(ulx, uly, Comet, XOR_PUT); /* Plot some "stars" */ for ( i=0 ; i<1000; ++i ) putpixel(random(MaxX), random(MaxY), WHITE); /* variables for the objects to be moved by */ x = MaxX; y = random(MaxY/2+70); x1 = MaxX; y1 = random(MaxY/2+70); x2 = 0; y2 = 0; PauseTime = 50; /* variables of the moving stars */ int c, x6, y6, x3, y3, x4, y4, x5, y5, x8, y8, x9, y9, x10, y10; c = random(14)+1; y6 = random(MaxY/2+100); y3 = random(MaxY/2+100); y4 = random(MaxY/2+100); y5 = random(MaxY/2+100); y8 = random(MaxY/2+100); y9 = random(MaxY/2+100); y10 = random(MaxY/2+100); x6 = random (MaxX); x3 = random (MaxX); x4 = random (MaxX); x5 = random (MaxX); x8 = random (MaxX); x9 = random (MaxX); x10 = random (MaxX); /* until a key is hit */ while ( !kbhit() ) { /* draws moving stars */ putpixel(x8, y8, BLACK); x8++; putpixel(x8, y8, c); if (x8 == MaxX) x8 = 0; putpixel(x9, y9, BLACK); x9++; putpixel(x9, y9, c); if (x9 == MaxX) x9 = 0; putpixel(x10, y10, BLACK); x10++; putpixel(x10, y10, c); if (x10 == MaxX) x10 = 0; putpixel(x6, y6, BLACK); x6++; putpixel(x6, y6, c); if (x6 == MaxX) x6 = 0; putpixel(x3, y3, BLACK); x3++; putpixel(x3, y3, c); if (x3 == MaxX) x3 = 0; putpixel(x4, y4, BLACK); x4++; putpixel(x4, y4, c); if (x4 == MaxX) x4 = 0; putpixel(x5, y5, BLACK); x5++; putpixel(x5, y5, c); if (x5 == MaxX) x5 = 0; /* Draw the Objects */ putimage(x, y, Saucer, XOR_PUT); /* draw image */ putimage(x1, y1, TyFighter, XOR_PUT); putimage(x2, y2, Sun, XOR_PUT); putimage(x7, y7, Comet, XOR_PUT); delay(PauseTime); putimage(x, y, Saucer, XOR_PUT); /* erase image */ putimage(x1, y1, TyFighter, XOR_PUT); putimage(x2, y2, Sun, XOR_PUT); putimage(x7, y7, Comet, XOR_PUT); /* Move Images */ x--; x1--; x2++; x7++; if (x7 == MaxX) // sets the variables of the comet { // if goes off the screen x7 = s+10; y7 = y7 + 20; s++; free( Comet ); getviewsettings( &vp3 ); setcolor(15); fillellipse(x7, y7, s, s); line(x7-s+1, y7, x7-s*2, y7); ulx = x7-s*2; uly = y7-s-5; lrx = x7+s+5; lry = y7+s+5; width = lrx - ulx + 1; height = lry - uly + 1; size3 = imagesize(ulx, uly, lrx, lry); Comet = malloc( size3 ); getimage(ulx, uly, lrx, lry, Comet); putimage(ulx, uly, Comet, XOR_PUT); } if (y7 >= MaxY || s >= 10) // if comet gets to big it resets { y7 = 20; s = 1; } if (x2 >= MaxX-75) // if sun goes off the screen it sets { // it on the other side x2 = 0; } if (x <= 0 || x1 <= 0) // if sauser or fighter goes off the { // the screen returns to redraw the land return x7; } 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 - 100) y = vp.bottom-100-vp.top-height + 1; else if (y < 0) y = 0; step1 = random( 2*r ); if ((step1/2) % 2 != 0 ) step1 = -1 * step1; x1 = x1 + step1; step1 = random( r ); if ((step1/2) % 2 != 0 ) step1 = -1 * step1; y1 = y1 + step1; if (vp1.left + x1 + width1 - 1 > vp1.right) x1 = vp1.right-vp1.left-width1 + 1; else if (x1 < 0) x1 = 0; if (vp1.top + y1 + height1 - 1 > vp1.bottom-100) y1 = vp1.bottom-100-vp1.top-height1 + 1; else if (y1 < 0) y1 = 0; } free( Saucer ); // frees the menery block for the images free( TyFighter ); free( Sun ); free( Comet ); return 0; } int drawland(int y_str) { randomize; int x_str, x_end, // left and right points y_end, // up and down points a, b, x_point, i,nus, ymax=getmaxy(); x_str = getmaxx(); /* hoizontal line */ //line(0, ymax/2+100, x_str, ymax/2+100); //ellipse (xmax/2, ymax/2+110, 0, 180, xmax/2+20, 10); //floodfill(xmax/2, ymax, 0); while (!kbhit()) { a = rand()%100; x_end = x_str - a; if (y_end > ymax-100) // end of up/down line bellow bottom { b = rand()%100; y_end = y_str - b; } else if (y_end < ymax/2+80) // end of up/down line above middle of screen { b = rand()%100; y_end = y_str + b; } else // if in middle of ends { // of up/down random which way to go nus = random (1); if (nus==0) // moves line randomly op/down { b = rand()%100; y_end = y_str + b; } else if (nus==1) { b = rand()%100; y_end = y_str - b; } } line (x_str, y_str, x_end, y_end); // draws the line //if (y_str >= ymax || y_end >= ymax) //{ } //else //{ //line (x_str, ymax/2+100, x_end, ymax/2+100); // draws horizontal line //ellipse (xmax, ymax/2+110, -10, 190, xmax, 5); //} x_str = x_end; // sets the next start point of the line y_str = y_end; // to the end of the last end point if (x_end <= 0) // returns at the end of drawing off the screen { return y_end; } } return 0; }