Facebook
From Mungo Ibis, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 327
  1. #include <dos.h>
  2. #include <math.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include <graphics.h>
  8.  
  9. struct body
  10. {
  11.     int x,y;
  12.     body *next;
  13. };
  14.  
  15. int main()
  16. {
  17.  
  18.  
  19.  
  20.  
  21.     int GraphDriver = DETECT;           /* Request auto-detection       */
  22.     int GraphMode;
  23.     int ErrorCode;
  24.     initgraph( &GraphDriver, &GraphMode, "" );
  25.     ErrorCode = graphresult();          /* Read result of initialization*/
  26.     if( ErrorCode != grOk )             /* Error occured during init    */
  27.     {
  28.         printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
  29.         exit( 1 );
  30.     }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     body *start;
  41.     body *curr;
  42.     curr = NULL;
  43.     start = NULL;
  44.     int dx = 10;
  45.     int dy = 0;
  46.     char znak = 0;
  47.     start = new body;
  48.     start -> x = 320;
  49.     start -> y = 240;
  50.     start -> next = NULL;
  51.  
  52.     do
  53.     {
  54.         if(kbhit())
  55.         {
  56.             znak = getch();
  57.             switch(znak)
  58.             {
  59.             case 'w':
  60.                 dy = -10;
  61.                 dx = 0;
  62.                 break;
  63.             case 's':
  64.                 dy = 10;
  65.                 dx = 0;
  66.                 break;
  67.             case 'a':
  68.                 dy = 0;
  69.                 dx = -10;
  70.                 break;
  71.             case 'd':
  72.                 dy = 0;
  73.                 dx = 10;
  74.                 break;
  75.             case ' ':
  76.                 curr = start;
  77.                 while(curr -> next != NULL)
  78.                 {
  79.                     curr = curr -> next;
  80.                 }
  81.                 curr -> next = new body;
  82.                 //curr = curr -> next;
  83.                 curr -> next = NULL;
  84.                 break;
  85.                
  86.             }
  87.             }
  88.             start -> x += dx;
  89.             start -> y += dy;
  90.             delay(150);
  91.             circle(start -> x,start -> y,5);
  92.             do
  93.             {
  94.                 curr = start;
  95.                 int tmpx, tmpy;
  96.                 tmpx = curr -> x;
  97.                 tmpy = curr -> y;
  98.  
  99.             }while(curr -> next != NULL);
  100.  
  101.     }while(znak!=27);
  102.  
  103.     while(!kbhit());    //czeka na naciśnięcie klawisza
  104.     closegraph();               /* Return the system to text mode       */
  105.  
  106.     return(0);
  107. }
  108.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Commodious Meerkat text 6 Years ago.