home *** CD-ROM | disk | FTP | other *** search
/ CD Action 54 / cdactioncoverdisc54.iso / Bonus / c.exe / CAut / caut.cpp next >
C/C++ Source or Header  |  2000-09-07  |  1KB  |  71 lines

  1. # include <stdio.h>
  2. # include <allegro.h>
  3. # include <math.h>
  4.  
  5. int x = 320, y = 200;
  6. int azymut = 1; // 0 = N , 1 = NE, 2 = E, 3 = SE
  7.                 // 4 = S , 5 = SW, 6 = W, 7 = NW
  8. int ta[256][8]; // tablica azymutow
  9.  
  10. BITMAP* bufor_e;
  11.  
  12. void cInit()
  13. {
  14.   int i,j;
  15.   for (i=0; i<256; i++)
  16.     for (j=0; j<8; j++)
  17.       ta[i][j]=rand()%8;
  18. //      ta[i][j]=(255*(int)sqrt(i+j))%8;
  19. }
  20.  
  21. void cAut()
  22. {
  23.    int i, r, nr;
  24.    char buf[80];
  25.    clear(bufor_e);
  26.    r=0;
  27.    while (!kbhit())
  28.    {
  29.       switch(azymut) {
  30.          case 0 : y-=1;break;
  31.          case 4 : y-=1;x+=1;break;
  32.          case 1 : x+=1;break;
  33.          case 5 : x+=1;y+=1;break;
  34.          case 2 : y+=1;break;
  35.          case 6 : y+=1;x-=1;break;
  36.          case 3 : x-=1;break;
  37.          case 7 : x-=1;y-=1;break;
  38.       }
  39.       if (x<0) x=639;
  40.       if (x>639) x=0;
  41.       if (y<0) y=479;
  42.       if (y>479) y=0;
  43.  
  44.       r=getr32( ((int *)bufor_e->line[y])[x] );
  45.  
  46.       azymut = ta[r][azymut];
  47.  
  48.       ((int *)bufor_e->line[y])[x] = makecol32(r+1, r+1, r+1);
  49.  
  50.       blit(bufor_e, screen, x, y, x, y, 1, 1);
  51.    }
  52. }
  53.  
  54. int main()
  55. {
  56.  
  57.  
  58.    allegro_init();
  59.    set_color_depth(32);
  60.    bufor_e = create_bitmap(640, 480);
  61.  
  62.    set_color_depth(16);
  63.    set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
  64.  
  65.    cInit();
  66.    cAut();
  67.  
  68.    destroy_bitmap(bufor_e);
  69.    text_mode(0);
  70. }
  71.