home *** CD-ROM | disk | FTP | other *** search
/ Gamer's Paradise: Czech / Hracuv-raj_Ceske-hry_cd1.bin / Lizard / liz006.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-25  |  11.3 KB  |  198 lines

  1. // lizard004 * 13.6.00
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #include "allegro.h"
  6.  
  7. #define MAXPOCHRAC 3
  8. #define MAXPOCINSECT 20
  9. #define POCINSECTS 4
  10.  
  11. #define INFO
  12.  
  13. typedef struct TPOZADI {
  14.     int x, y;
  15.     BITMAP *bmp;
  16.   } TPOZADI;
  17.  
  18. typedef struct THRAC {
  19.     int i, x, y, xx, yy;
  20.     int kl, kp, kn, kd, kf;
  21.     int jaz, body;
  22.     int insect[POCINSECTS];
  23.     fixed angle;
  24.   } THRAC;
  25.  
  26. typedef struct TINSECT_INFO {
  27.     int i, x, y, rych, Bool;
  28.     fixed angle;
  29.   } TINSECT_INFO;
  30.  
  31. typedef struct TINSECTSINFO {
  32.     char *name;
  33.     int poc, body, nord, maxrych, maxzryc, maxang;
  34.     TINSECT_INFO info[MAXPOCINSECT];
  35.     BITMAP *bmp[4];
  36.   } TINSECTS;
  37.  
  38. THRAC hraci[MAXPOCHRAC] =
  39.   {// i,   x,   y, xx,  yy, kl, kp, kn, kd, kf, jaz, body, fly, spider, ang
  40.     { 0, 160, 120,  0, -10, 75, 77, 72, 80, 28,   0,   0,  { 0,   0},   0 },
  41.     { 0, 160, 120,  0, -10, 30, 32, 17, 31, 45,   0,   0,  { 0,   0},   0 },
  42.     { 0, 160, 120,  0, -10, 33, 35, 20, 34, 48,   0,   0,  { 0,   0},   0 },
  43.   };
  44.  
  45. TPOZADI pozadi;
  46. BITMAP *screen2;
  47. BITMAP *lizards[4];
  48. BITMAP *flys[4];
  49. BITMAP *spiders[4];
  50. BITMAP *jaz;
  51. BITMAP *lizjaz;
  52. int pochrac = 1;
  53. TINSECTS insects[POCINSECTS];
  54.  
  55. volatile int speed_counter = 0;
  56.  
  57. void increment_speed_counter()
  58.   { speed_counter++; }
  59. END_OF_FUNCTION( increment_speed_counter);
  60.  
  61. int main()
  62. {
  63.   PALLETE pal;
  64.   int i, i0, i1, pom1, pom2, pom3;
  65.   char poms[13];
  66.  
  67.   allegro_init();
  68.   install_keyboard();
  69.   install_timer();
  70.   set_gfx_mode( GFX_MODEX, 320, 240, 0, 0);
  71.   set_color_depth( 8);
  72.  
  73.   pozadi.bmp=load_bitmap( "pozadi8.bmp", pal); if ( !pozadi.bmp) { allegro_exit(); printf( "Error reading \n"); return 1; }
  74.   /*lizard*/screen2=load_bitmap( "lizard8.bmp", pal); if ( !screen2) { allegro_exit(); printf( "Error reading \n"); return 1; }
  75.   for ( i=0; i<4; i++) {
  76.     lizards[i]=create_bitmap( screen2->h, screen2->h);
  77.     blit( screen2, lizards[i], i*screen2->h, 0, 0, 0, screen2->h, screen2->h);
  78.   } jaz=create_bitmap( 10, screen2->h); blit( screen2, jaz, screen2->h*4, 0, 0, 0, 10, screen2->h); destroy_bitmap( screen2);
  79.   //insects info
  80.   insects[0].name="fly";    insects[1].name="spider"; insects[2].name="ant";   insects[3].name="ladybird";
  81.   insects[0].poc=10;        insects[1].poc=5;         insects[2].poc=5;        insects[3].poc=5;
  82.   insects[0].body=3;        insects[1].body=2;        insects[2].body=1;       insects[3].body=1;
  83.   insects[0].nord=1;        insects[1].nord=0;        insects[2].nord=0;       insects[3].nord=0;
  84.   insects[0].maxrych=10;    insects[1].maxrych=7;     insects[2].maxrych=5;    insects[3].maxrych=5;
  85.   insects[0].maxzryc=2;     insects[1].maxzryc=1;     insects[2].maxzryc=1;    insects[3].maxzryc=1;
  86.   insects[0].maxang=16<<16; insects[1].maxang=8<<16;  insects[2].maxang=4<<16; insects[3].maxang=4<<16;
  87.  
  88.   for ( i=0; i<POCINSECTS; i++) {
  89.     strcpy( poms, insects[i].name);
  90.     strcat( poms, "8.bmp");
  91.     screen2=load_bitmap( poms, pal); if ( !screen2) { allegro_exit(); printf( "Error reading \n"); return 1; }
  92.     for ( i0=0; i0<4; i0++) {
  93.       insects[i].bmp[i0]=create_bitmap( screen2->h, screen2->h);
  94.       blit( screen2, insects[i].bmp[i0], i0*screen2->h, 0, 0, 0, screen2->h, screen2->h);
  95.     } destroy_bitmap( screen2);
  96.     for ( i0=0; i0<MAXPOCINSECT; i0++) {
  97.       insects[i].info[i0].i = 0; insects[i].info[i0].x = rand() % pozadi.bmp->w; insects[i].info[i0].y = rand() % pozadi.bmp->h; insects[i].info[i0].rych = 0; insects[i].info[i0].Bool = 1; insects[i].info[i0].angle = 0;
  98.     }
  99.   }
  100.  
  101.   set_pallete( pal); text_mode( -1);
  102.   lizjaz=create_bitmap( 50, 100);
  103.   screen2=create_bitmap( SCREEN_W, SCREEN_H);
  104.   // delay
  105.   LOCK_VARIABLE( speed_counter); LOCK_FUNCTION( increment_speed_counter);
  106.   install_int( increment_speed_counter, 40);
  107.  
  108.   do {
  109.     while ( speed_counter > 0) {
  110.       // ostatni hraci
  111.       if ( key[KEY_PLUS_PAD] && pochrac < MAXPOCHRAC) pochrac++;
  112.       if ( key[KEY_MINUS_PAD] && pochrac > 1) pochrac--;
  113.       // insects
  114.       for ( i=0; i<POCINSECTS; i++) for ( i0=0; i0<insects[i].poc; i0++) if ( insects[i].info[i0].Bool) {
  115.         insects[i].info[i0].angle+=( rand() % ( ( insects[i].maxang>>16)*2+1)-( insects[i].maxang>>16))<<16; if ( insects[i].info[i0].angle<0) insects[i].info[i0].angle+=256<<16; if ( insects[i].info[i0].angle>256<<16) insects[i].info[i0].angle-=256<<16;
  116.         insects[i].info[i0].rych+=rand() % (insects[i].maxzryc*2+1)-insects[i].maxzryc; if ( insects[i].info[i0].rych<0) insects[i].info[i0].rych=0; if ( insects[i].info[i0].rych>insects[i].maxrych) insects[i].info[i0].rych=insects[i].maxrych;
  117.         insects[i].info[i0].x+=fixtoi( fsin( insects[i].info[i0].angle)*insects[i].info[i0].rych); insects[i].info[i0].y+=fixtoi( fcos( insects[i].info[i0].angle+( 128<<16))*insects[i].info[i0].rych);
  118.         if ( insects[i].info[i0].x+insects[i].bmp[0]->w<0) insects[i].info[i0].x=pozadi.bmp->w-insects[i].bmp[0]->w; if ( insects[i].info[i0].x>pozadi.bmp->w) insects[i].info[i0].x=0;
  119.         if ( insects[i].info[i0].y+insects[i].bmp[0]->h<0) insects[i].info[i0].y=pozadi.bmp->h-insects[i].bmp[0]->h; if ( insects[i].info[i0].y>pozadi.bmp->h) insects[i].info[i0].y=0;
  120.         if ( insects[i].info[i0].i<3) insects[i].info[i0].i++; else insects[i].info[i0].i=0;
  121.       }
  122.       #define DELJAZ 2
  123.       // hejbani hracu
  124.       for ( i=0; i<pochrac; i++) {
  125.         /*l*/if ( key[hraci[i].kl]) { hraci[i].angle-=8<<16; if ( hraci[i].angle<0) hraci[i].angle+=256<<16;
  126.           hraci[i].xx=fixtoi( fsin( hraci[i].angle)*10); hraci[i].yy=fixtoi( fcos( hraci[i].angle+( 128<<16))*10); }
  127.         /*p*/if ( key[hraci[i].kp]) { hraci[i].angle+=8<<16; if ( hraci[i].angle>256<<16) hraci[i].angle-=256<<16;
  128.           hraci[i].xx=fixtoi( fsin( hraci[i].angle)*10); hraci[i].yy=fixtoi( fcos( hraci[i].angle+(128<<16))*10); }
  129.         /*n*/if ( key[hraci[i].kn]) { hraci[i].x+=hraci[i].xx; hraci[i].y+=hraci[i].yy; };
  130.         /*d*/if ( key[hraci[i].kd]) { hraci[i].x-=hraci[i].xx; hraci[i].y-=hraci[i].yy; };
  131.         /*i*/if ( key[hraci[i].kl] || key[hraci[i].kp] || key[hraci[i].kn] || key[hraci[i].kd]) (hraci[i].i==3)? hraci[i].i=0: hraci[i].i++;
  132.         /*jaz*/if ( key[hraci[i].kf]) { if ( hraci[i].jaz >= 0) hraci[i].jaz+=1; if ( hraci[i].jaz > 5) hraci[i].jaz*=-1; } else if ( hraci[i].jaz > 0) hraci[i].jaz*=-1; if ( hraci[i].jaz < 0) { hraci[i].jaz+=1; if ( hraci[i].jaz == 0) for ( i0=0; i0<POCINSECTS; i0++) hraci[i].insect[i0]=0; }
  133.         if ( hraci[i].x+hraci[i].xx*DELJAZ < pozadi.x) hraci[i].x=pozadi.x-hraci[i].xx*DELJAZ; if ( hraci[i].x+hraci[i].xx*DELJAZ > pozadi.x+SCREEN_W-lizards[0]->w) hraci[i].x=pozadi.x-hraci[i].xx*DELJAZ+SCREEN_W-lizards[0]->w;
  134.         if ( hraci[i].y+hraci[i].yy*DELJAZ < pozadi.y) hraci[i].y=pozadi.y-hraci[i].yy*DELJAZ; if ( hraci[i].y+hraci[i].yy*DELJAZ > pozadi.y+SCREEN_H-lizards[0]->h) hraci[i].y=pozadi.y-hraci[i].yy*DELJAZ+SCREEN_H-lizards[0]->h;
  135.         /*sez insects*/pom1=hraci[i].x+lizards[0]->w/2+fixtoi( ( pom3=fsin( hraci[i].angle))*abs( hraci[i].jaz)*3+pom3*20);
  136.         pom2=hraci[i].y+lizards[0]->h/2+fixtoi( ( pom3=fcos( hraci[i].angle+( 128<<16)))*abs( hraci[i].jaz)*3+pom3*20);
  137.  
  138.         for ( i0=0; i0<POCINSECTS; i0++) for ( i1=0; i1<insects[i0].poc; i1++) if ( insects[i0].info[i1].Bool) {
  139.           if ( ( pom1>insects[i0].info[i1].x) && ( pom1<insects[i0].info[i1].x+insects[i0].bmp[0]->w)
  140.             && ( pom2>insects[i0].info[i1].y) && ( pom2<insects[i0].info[i1].y+insects[i0].bmp[0]->h) && ( hraci[i].jaz != 0)) {
  141.             hraci[i].body+=insects[i0].body; hraci[i].insect[i0]=1; insects[i0].info[i1].Bool=0;
  142.           }
  143.         } else {
  144.           insects[i0].info[i1].x = rand() % (pozadi.bmp->w-SCREEN_W); if ( ( insects[i0].info[i1].x>pozadi.x) && ( insects[i0].info[i1].x<pozadi.x+SCREEN_W) ) insects[i0].info[i1].x+=SCREEN_W;
  145.           insects[i0].info[i1].y = rand() % (pozadi.bmp->h-SCREEN_H); if ( ( insects[i0].info[i1].y>pozadi.y) && ( insects[i0].info[i1].y<pozadi.y+SCREEN_H) ) insects[i0].info[i1].y+=SCREEN_H;
  146.           insects[i0].info[i1].Bool=1;
  147.         }
  148.       }
  149.       // obrazovka
  150.       /*x*/                        pom3=hraci[0].x+hraci[0].xx*DELJAZ+lizards[0]->w/2; pom1=pom3; pom2=pom3;
  151.       for ( i=1; i<pochrac; i++) { pom3=hraci[i].x+hraci[i].xx*DELJAZ+lizards[0]->w/2; if ( pom1 > pom3) pom1=pom3; else if ( pom2 < pom3) pom2=pom3; }
  152.       pozadi.x+=( ( pom1+pom2-SCREEN_W)/2-pozadi.x)/5; if ( pozadi.x < 0) pozadi.x=0; else if ( pozadi.x > pozadi.bmp->w-SCREEN_W) pozadi.x=pozadi.bmp->w-SCREEN_W;
  153.       /*y*/                        pom3=hraci[0].y+hraci[0].yy*DELJAZ+lizards[0]->h/2; pom1=pom3; pom2=pom3;
  154.       for ( i=1; i<pochrac; i++) { pom3=hraci[i].y+hraci[i].yy*DELJAZ+lizards[0]->h/2; if ( pom1 > pom3) pom1=pom3; else if ( pom2 < pom3) pom2=pom3; }
  155.       pozadi.y+=( ( pom1+pom2-SCREEN_H)/2-pozadi.y)/5; if ( pozadi.y < 0) pozadi.y=0; else if ( pozadi.y > pozadi.bmp->h-SCREEN_H) pozadi.y=pozadi.bmp->h-SCREEN_H;
  156.  
  157.       speed_counter--;
  158.     }
  159.  
  160.     // sestaveni screen2
  161.     blit( pozadi.bmp, screen2, pozadi.x, pozadi.y, 0, 0, screen2->w, screen2->h);
  162.     #ifdef INFO
  163.                                  textprintf( screen2, font, 0, 0*8, makecol( 256, 256, 256), "h  bod  ");
  164.       for ( i=0; i<pochrac; i++) textprintf( screen2, font, 0, (1+i)*8, makecol( 256, 256, 256), "%d %4d", i, hraci[i].body);
  165.     #endif
  166.     /*insect*/
  167.     for ( i=0; i<POCINSECTS; i++) if ( insects[i].nord=0) for ( i0=0; i0<insects[i].poc; i0++) if ( insects[i].info[i0].Bool) {
  168.       if ( ( insects[i].info[i0].x+insects[i].bmp[0]->w > pozadi.x) && ( insects[i].info[i0].x < pozadi.x+pozadi.bmp->w)
  169.         && ( insects[i].info[i0].y+insects[i].bmp[0]->h > pozadi.y) && ( insects[i].info[i0].y < pozadi.y+pozadi.bmp->h) )
  170.         rotate_sprite( screen2, insects[i].bmp[insects[i].info[i0].i], insects[i].info[i0].x-pozadi.x, insects[i].info[i0].y-pozadi.y, insects[i].info[i0].angle);
  171.     }
  172.     /*hraci*/for ( i=0; i<pochrac; i++) {
  173.       clear( lizjaz);
  174.       for ( i0=0; i0<POCINSECTS; i0++) if ( hraci[i].insect[i0]) { masked_blit( insects[i0].bmp[insects[i0].info[0].i], lizjaz, 0, 0, (lizjaz->w-insects[i0].bmp[0]->w)/2, lizjaz->h/2-28-abs( hraci[i].jaz)*3, insects[i0].bmp[0]->w, insects[i0].bmp[0]->h); }
  175.       masked_blit( jaz, lizjaz, 0, 0, (lizjaz->w-jaz->w)/2, lizjaz->h/2-20-abs( hraci[i].jaz)*3, jaz->w, abs( hraci[i].jaz)*3);
  176.       masked_blit( lizards[hraci[i].i], lizjaz, 0, 0, 0, ( lizjaz->h-lizards[hraci[i].i]->h)/2, lizards[hraci[i].i]->w, lizards[hraci[i].i]->h);
  177.       rotate_sprite( screen2, lizjaz, hraci[i].x-pozadi.x, hraci[i].y-pozadi.y-( lizjaz->h-lizards[hraci[i].i]->h)/2, hraci[i].angle);
  178.     }
  179.     /*insect*/
  180.     for ( i=0; i<POCINSECTS; i++) if ( insects[i].nord=1) for ( i0=0; i0<insects[i].poc; i0++) if ( insects[i].info[i0].Bool) {
  181.       if ( ( insects[i].info[i0].x+insects[i].bmp[0]->w > pozadi.x) && ( insects[i].info[i0].x < pozadi.x+pozadi.bmp->w)
  182.         && ( insects[i].info[i0].y+insects[i].bmp[0]->h > pozadi.y) && ( insects[i].info[i0].y < pozadi.y+pozadi.bmp->h) )
  183.         rotate_sprite( screen2, insects[i].bmp[insects[i].info[i0].i], insects[i].info[i0].x-pozadi.x, insects[i].info[i0].y-pozadi.y, insects[i].info[i0].angle);
  184.     }
  185.  
  186.     blit( screen2, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
  187.  
  188.   } while ( !key[KEY_ESC]);
  189.   destroy_bitmap( screen2);
  190.   destroy_bitmap( pozadi.bmp);
  191.   for ( i=0; i<4; i++) {
  192.     destroy_bitmap( lizards[i]);
  193.     for ( i0=0; i0<POCINSECTS; i0++) destroy_bitmap( insects[i0].bmp[i]);
  194.   }
  195.  
  196.   return 0;
  197. }
  198.