/* Keep these headers */ #include #include #include #include /* Standard headers - it's recommended to leave them included */ #include #include #include #include /* CE Graphics C Library */ #include #include /* Main Function */ void main(void) { /* Some variable intialization */ unsigned int x, y, x_ball, y_ball, loop; int vie; signed int delta_x, delta_y; unsigned char color; unsigned char key; signed char buf[10]; srand(*(unsigned long*)0xF30044); gc_InitGraph(); for(vie = 3; vie >0 ; vie--){ x = 135; y = 100; x_ball = 50+rand()%200; y_ball = 22; loop = 0; delta_x = 1; delta_y = 1; color = 0; gc_FillScrn(0x00); gc_SetTransparentColor(30); gc_SetTextColor(255); gc_SetColorIndex(255); sprintf(buf,"Vie : %d",vie); gc_PrintStringXY(buf,260,1); gc_PrintStringXY("PONG 2.4 - Made by Peter \"PT_\" Tillema", 1, 1); gc_NoClipHorizLine(0, 9, 320); gc_NoClipRectangle(5, y, 5, 51); gc_NoClipRectangle(310, 199-y, 5, 51); gc_NoClipRectangle(135, 15, 51, 5); gc_NoClipRectangle(134, 230, 51, 5); while(kb_ScanGroup(kb_group_1) != kb_2nd) { gc_NoClipRectangle(x_ball, y_ball, 3, 3); key = kb_ScanGroup(kb_group_7); // need to make a loop - otherwise too fast if (loop % 5 == 0) { if (key == kb_Left && x > 10) x--; if (key == kb_Right && x < 259) x++; if (key == kb_Up && y > 20) y--; if (key == kb_Down && y < 179) y++; if (key) { gc_NoClipHorizLine(310, 249-y, 5); gc_NoClipHorizLine(310, 199-y, 5); gc_NoClipHorizLine(5, y, 5); gc_NoClipHorizLine(5, y+50, 5); gc_NoClipVertLine(x+50, 15, 5); gc_NoClipVertLine(x, 15, 5); gc_NoClipVertLine(319-x, 230, 5); gc_NoClipVertLine(269-x, 230, 5); gc_SetColorIndex(0); gc_NoClipHorizLine(5, y+51, 5); gc_NoClipHorizLine(5, y-1, 5); gc_NoClipHorizLine(310, 250-y, 5); gc_NoClipHorizLine(310, 198-y, 5); gc_NoClipVertLine(x+51, 15, 5); gc_NoClipVertLine(x-1, 15, 5); gc_NoClipVertLine(320-x, 230, 5); gc_NoClipVertLine(268-x, 230, 5); } } gc_SetColorIndex(0); if (loop % 7 == 0) { gc_NoClipRectangle(x_ball, y_ball, 3, 3); // check for losing if (x_ball == 11 && (y_ball < y || y_ball > y+50)) break; else if (x_ball == 307 && (y_ball < 200-y || y_ball > 250-y)) break; else if (y_ball == 21 && (x_ball < x || x_ball > x+50)) break; else if (y_ball == 227 && (x_ball < 270-x || x_ball > 320-x)) break; else { // update position of ball x_ball += delta_x; y_ball += delta_y; if (x_ball == 11 || x_ball == 307) delta_x *= -1; if (y_ball == 21 || y_ball == 227) delta_y *= -1; } } gc_SetColorIndex(255); loop++; } } /* Close the graphics canvas and return to the OS */ gc_FillScrn(0x00); gc_SetTransparentColor(30); gc_SetTextColor(255); gc_SetColorIndex(255); gc_PrintStringXY("PERDU !!!", 110, 70); gc_PrintStringXY("Press 2NDE to exit...",80,120); while(kb_ScanGroup(kb_group_1) != kb_2nd); gc_CloseGraph(); _OS( asm("call _DrawStatusBar")); }