home *** CD-ROM | disk | FTP | other *** search
Wrap
// lizard004 * 13.6.00 #include <stdlib.h> #include <stdio.h> #include "allegro.h" #define MAXPOCHRAC 3 #define MAXPOCINSECT 20 #define POCINSECTS 4 #define INFO typedef struct TPOZADI { int x, y; BITMAP *bmp; } TPOZADI; typedef struct THRAC { int i, x, y, xx, yy; int kl, kp, kn, kd, kf; int jaz, body; int insect[POCINSECTS]; fixed angle; } THRAC; typedef struct TINSECT_INFO { int i, x, y, rych, Bool; fixed angle; } TINSECT_INFO; typedef struct TINSECTSINFO { char *name; int poc, body, nord, maxrych, maxzryc, maxang; TINSECT_INFO info[MAXPOCINSECT]; BITMAP *bmp[4]; } TINSECTS; THRAC hraci[MAXPOCHRAC] = {// i, x, y, xx, yy, kl, kp, kn, kd, kf, jaz, body, fly, spider, ang { 0, 160, 120, 0, -10, 75, 77, 72, 80, 28, 0, 0, { 0, 0}, 0 }, { 0, 160, 120, 0, -10, 30, 32, 17, 31, 45, 0, 0, { 0, 0}, 0 }, { 0, 160, 120, 0, -10, 33, 35, 20, 34, 48, 0, 0, { 0, 0}, 0 }, }; TPOZADI pozadi; BITMAP *screen2; BITMAP *lizards[4]; BITMAP *flys[4]; BITMAP *spiders[4]; BITMAP *jaz; BITMAP *lizjaz; int pochrac = 1; TINSECTS insects[POCINSECTS]; volatile int speed_counter = 0; void increment_speed_counter() { speed_counter++; } END_OF_FUNCTION( increment_speed_counter); int main() { PALLETE pal; int i, i0, i1, pom1, pom2, pom3; char poms[13]; allegro_init(); install_keyboard(); install_timer(); set_gfx_mode( GFX_MODEX, 320, 240, 0, 0); set_color_depth( 8); pozadi.bmp=load_bitmap( "pozadi8.bmp", pal); if ( !pozadi.bmp) { allegro_exit(); printf( "Error reading \n"); return 1; } /*lizard*/screen2=load_bitmap( "lizard8.bmp", pal); if ( !screen2) { allegro_exit(); printf( "Error reading \n"); return 1; } for ( i=0; i<4; i++) { lizards[i]=create_bitmap( screen2->h, screen2->h); blit( screen2, lizards[i], i*screen2->h, 0, 0, 0, screen2->h, screen2->h); } jaz=create_bitmap( 10, screen2->h); blit( screen2, jaz, screen2->h*4, 0, 0, 0, 10, screen2->h); destroy_bitmap( screen2); //insects info insects[0].name="fly"; insects[1].name="spider"; insects[2].name="ant"; insects[3].name="ladybird"; insects[0].poc=10; insects[1].poc=5; insects[2].poc=5; insects[3].poc=5; insects[0].body=3; insects[1].body=2; insects[2].body=1; insects[3].body=1; insects[0].nord=1; insects[1].nord=0; insects[2].nord=0; insects[3].nord=0; insects[0].maxrych=10; insects[1].maxrych=7; insects[2].maxrych=5; insects[3].maxrych=5; insects[0].maxzryc=2; insects[1].maxzryc=1; insects[2].maxzryc=1; insects[3].maxzryc=1; insects[0].maxang=16<<16; insects[1].maxang=8<<16; insects[2].maxang=4<<16; insects[3].maxang=4<<16; for ( i=0; i<POCINSECTS; i++) { strcpy( poms, insects[i].name); strcat( poms, "8.bmp"); screen2=load_bitmap( poms, pal); if ( !screen2) { allegro_exit(); printf( "Error reading \n"); return 1; } for ( i0=0; i0<4; i0++) { insects[i].bmp[i0]=create_bitmap( screen2->h, screen2->h); blit( screen2, insects[i].bmp[i0], i0*screen2->h, 0, 0, 0, screen2->h, screen2->h); } destroy_bitmap( screen2); for ( i0=0; i0<MAXPOCINSECT; i0++) { 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; } } set_pallete( pal); text_mode( -1); lizjaz=create_bitmap( 50, 100); screen2=create_bitmap( SCREEN_W, SCREEN_H); // delay LOCK_VARIABLE( speed_counter); LOCK_FUNCTION( increment_speed_counter); install_int( increment_speed_counter, 40); do { while ( speed_counter > 0) { // ostatni hraci if ( key[KEY_PLUS_PAD] && pochrac < MAXPOCHRAC) pochrac++; if ( key[KEY_MINUS_PAD] && pochrac > 1) pochrac--; // insects for ( i=0; i<POCINSECTS; i++) for ( i0=0; i0<insects[i].poc; i0++) if ( insects[i].info[i0].Bool) { 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; 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; 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); 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; 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; if ( insects[i].info[i0].i<3) insects[i].info[i0].i++; else insects[i].info[i0].i=0; } #define DELJAZ 2 // hejbani hracu for ( i=0; i<pochrac; i++) { /*l*/if ( key[hraci[i].kl]) { hraci[i].angle-=8<<16; if ( hraci[i].angle<0) hraci[i].angle+=256<<16; hraci[i].xx=fixtoi( fsin( hraci[i].angle)*10); hraci[i].yy=fixtoi( fcos( hraci[i].angle+( 128<<16))*10); } /*p*/if ( key[hraci[i].kp]) { hraci[i].angle+=8<<16; if ( hraci[i].angle>256<<16) hraci[i].angle-=256<<16; hraci[i].xx=fixtoi( fsin( hraci[i].angle)*10); hraci[i].yy=fixtoi( fcos( hraci[i].angle+(128<<16))*10); } /*n*/if ( key[hraci[i].kn]) { hraci[i].x+=hraci[i].xx; hraci[i].y+=hraci[i].yy; }; /*d*/if ( key[hraci[i].kd]) { hraci[i].x-=hraci[i].xx; hraci[i].y-=hraci[i].yy; }; /*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++; /*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; } 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; 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; /*sez insects*/pom1=hraci[i].x+lizards[0]->w/2+fixtoi( ( pom3=fsin( hraci[i].angle))*abs( hraci[i].jaz)*3+pom3*20); pom2=hraci[i].y+lizards[0]->h/2+fixtoi( ( pom3=fcos( hraci[i].angle+( 128<<16)))*abs( hraci[i].jaz)*3+pom3*20); for ( i0=0; i0<POCINSECTS; i0++) for ( i1=0; i1<insects[i0].poc; i1++) if ( insects[i0].info[i1].Bool) { if ( ( pom1>insects[i0].info[i1].x) && ( pom1<insects[i0].info[i1].x+insects[i0].bmp[0]->w) && ( pom2>insects[i0].info[i1].y) && ( pom2<insects[i0].info[i1].y+insects[i0].bmp[0]->h) && ( hraci[i].jaz != 0)) { hraci[i].body+=insects[i0].body; hraci[i].insect[i0]=1; insects[i0].info[i1].Bool=0; } } else { 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; 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; insects[i0].info[i1].Bool=1; } } // obrazovka /*x*/ pom3=hraci[0].x+hraci[0].xx*DELJAZ+lizards[0]->w/2; pom1=pom3; pom2=pom3; 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; } 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; /*y*/ pom3=hraci[0].y+hraci[0].yy*DELJAZ+lizards[0]->h/2; pom1=pom3; pom2=pom3; 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; } 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; speed_counter--; } // sestaveni screen2 blit( pozadi.bmp, screen2, pozadi.x, pozadi.y, 0, 0, screen2->w, screen2->h); #ifdef INFO textprintf( screen2, font, 0, 0*8, makecol( 256, 256, 256), "h bod "); for ( i=0; i<pochrac; i++) textprintf( screen2, font, 0, (1+i)*8, makecol( 256, 256, 256), "%d %4d", i, hraci[i].body); #endif /*insect*/ 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) { if ( ( insects[i].info[i0].x+insects[i].bmp[0]->w > pozadi.x) && ( insects[i].info[i0].x < pozadi.x+pozadi.bmp->w) && ( insects[i].info[i0].y+insects[i].bmp[0]->h > pozadi.y) && ( insects[i].info[i0].y < pozadi.y+pozadi.bmp->h) ) 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); } /*hraci*/for ( i=0; i<pochrac; i++) { clear( lizjaz); 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); } 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); 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); 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); } /*insect*/ 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) { if ( ( insects[i].info[i0].x+insects[i].bmp[0]->w > pozadi.x) && ( insects[i].info[i0].x < pozadi.x+pozadi.bmp->w) && ( insects[i].info[i0].y+insects[i].bmp[0]->h > pozadi.y) && ( insects[i].info[i0].y < pozadi.y+pozadi.bmp->h) ) 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); } blit( screen2, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } while ( !key[KEY_ESC]); destroy_bitmap( screen2); destroy_bitmap( pozadi.bmp); for ( i=0; i<4; i++) { destroy_bitmap( lizards[i]); for ( i0=0; i0<POCINSECTS; i0++) destroy_bitmap( insects[i0].bmp[i]); } return 0; }