/* Worms. Written by Justin Todd April 11-12, 2000 Revised - May 27, 2000 */ #include #include"worms.h" int PlayArea[PLAYAREA_WIDTH][PLAYAREA_HIEGHT]; void Init(){ allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); Virtual=create_bitmap(SCREEN_W,SCREEN_H); srandom(time(NULL)); text_mode(55); } void Game_Init(){ Worm.Length=DEFAULT_WORM_LENGTH; Worm.XPos=WORM_START_X; Worm.YPos=WORM_START_Y; Worm.XVel=1; Worm.YVel=0; for(y=0;y=PLAYAREA_WIDTH)||(Worm.YPos<1)||(Worm.YPos>=PLAYAREA_HIEGHT)) Game_Init(); //If player hits a boundry if(Worm.Length==WORM_MAX_LENGTH) Worm.Length=DEFAULT_WORM_LENGTH; //If the worm is a certain lenth restart at 1 if(PlayArea[Worm.XPos][Worm.YPos]==FOOD){ //If player runs into a food... PlayArea[1+(random()%PLAYAREA_WIDTH-1)][1+random()%(PLAYAREA_HIEGHT-1)]=FOOD; //Place food block at random location Worm.Length+=1; //Increment worm length } if(PlayArea[Worm.XPos][Worm.YPos]>=WORM) Game_Init(); //If Player hits his own body PlayArea[Worm.XPos][Worm.YPos]=WORM; //Record worm position to the "PlayArea" array for(x=0;x<=PLAYAREA_WIDTH;x++) for(y=0;y<=PLAYAREA_HIEGHT;y++) if(PlayArea[x][y]>=WORM) if(PlayArea[x][y]>=Worm.Length+WORM) PlayArea[x][y]=0; else ++PlayArea[x][y]; } void Update_Graphics(){ textout(Virtual,font,"CIPHERSOFT PRESENTS... WORMS! Written by Justin Todd. Revised May 27, 2000 ",1,1,15); for(x=0;x=WORM) rectfill(Virtual,x*BLOCK_SIZE,y*BLOCK_SIZE,x*BLOCK_SIZE+BLOCK_SIZE,y*BLOCK_SIZE+BLOCK_SIZE,PlayArea[x][y]+25); else if(PlayArea[x][y]==FOOD) rectfill(Virtual,x*BLOCK_SIZE,y*BLOCK_SIZE,x*BLOCK_SIZE+BLOCK_SIZE,y*BLOCK_SIZE+BLOCK_SIZE,14); vsync(); if(key[KEY_S]) save_bmp("ScrShot.bmp",Virtual,NULL); blit(Virtual,screen,0,0,0,0,SCREEN_W,SCREEN_H); clear(Virtual); } void DeInit(){ destroy_bitmap(Virtual); allegro_exit(); }