void main(void) { int gdriver = DETECT, gmode, errorcode; void *body,*food,*tail1,*tail2,*tail3,*tail4,*head1,*head2,*head3,*head4; int x, y,X[5000],Y[5000],i=3, maxx,maxy,speed=100,bo=10,t[10],score=0,hscore=20; unsigned int size; char a='6',b,scor[4],hs[4]; int k=2,l,r1,r2,f=0,z=100,first=0,second=1;; r1=300; r2=350; ifstream infile("c:\tc\bin\rattle.txt"); infile.getline(hs,4); infile.close(); hscore = atoi(hs); /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } maxx = getmaxx(); maxy = getmaxy(); y = 160; x = 80; for(int j=0; j<=3; j++) { X[i-j]=x-bo*(j+1); Y[i-j]=y; } //body setfillstyle(1,2); bar(10,10,20,20); setcolor(0); setlinestyle(0,1,3); line(9,9,21,21); line(9,21,21,9); size = imagesize(10,10,20,20); body = malloc(size); getimage(10,10,20,20,body); cleardevice(); setcolor(0); //tail1-right t[0]=20; t[1]=10; t[2]=10; t[3]=10; t[4]=20; t[5]=15; t[6]=10; t[7]=20; t[8]=20; t[9]=21; fillpoly(5, t); size = imagesize(10,10,20,21); tail1 = malloc(size); getimage(10,10,20,21,tail1); cleardevice(); //tail2-left t[0]=10; t[1]=10; t[2]=20; t[3]=10; t[4]=10; t[5]=15; t[6]=20; t[7]=20; t[8]=10; t[9]=21; fillpoly(5, t); size = imagesize(10,10,20,21); tail2 = malloc(size); getimage(10,10,20,21,tail2); cleardevice(); //tail3-up t[0]=10; t[1]=20; t[2]=10; t[3]=10; t[4]=15; t[5]=20; t[6]=20; t[7]=10; t[8]=20; t[9]=21; fillpoly(5, t); size = imagesize(10,10,20,21); tail3 = malloc(size); getimage(10,10,20,21,tail3); cleardevice(); //tail4-down t[0]=10; t[1]=10; t[2]=10; t[3]=21; t[4]=15; t[5]=10; t[6]=20; t[7]=21; t[8]=20; t[9]=10; fillpoly(5, t); size = imagesize(10,10,20,21); tail4 = malloc(size); getimage(10,10,20,21,tail4); cleardevice(); //head1-right setlinestyle(1,1,1); setcolor(2); fillellipse(10,10,10,5); setcolor(4); //eyes fillellipse(15,7,1,1); fillellipse(15,13,1,1); size = imagesize(10,5,20,15); head1 = malloc(size); getimage(10,5,20,15,head1); //head2-left //eyes fillellipse(5,7,1,1); fillellipse(5,13,1,1); size = imagesize(0,5,10,15); head2 = malloc(size); getimage(0,5,10,15,head2); cleardevice(); //head3-up //eyes setcolor(2); fillellipse(12,12,5,10); setcolor(4); fillellipse(9,6,1,1); fillellipse(15,6,1,1); size = imagesize(7,2,18,12); head3 = malloc(size); getimage(7,2,18,12,head3); //head4-down //eyes fillellipse(9,17,1,1); fillellipse(15,17,1,1); size = imagesize(7,12,18,22); head4 = malloc(size); getimage(7,12,18,22,head4); cleardevice(); //food setcolor(15); setfillstyle(1,15); fillellipse(10,10,3,5); size = imagesize(5,3,15,17); food = malloc(size); getimage(5,3,15,17,food); cleardevice(); /* repeat until a key is pressed */ maxx=getmaxx(); maxy=getmaxy(); setlinestyle(0,1,3); setcolor(9); rectangle(0,0,maxx,maxy); setlinestyle(0,1,2); line(maxx-150,0,maxx-150,maxy); setcolor(8); setfillstyle(1,8); bar(maxx-147,3,maxx-3,63); setcolor(12); int maze=1; if(maze==1) { setfillstyle(1,6); bar(4,4,maxx-154,14); bar(4,4,14,maxy-4); bar(4,maxy-4,maxx-154,maxy-14); bar(maxx-154-10,4,maxx-154,maxy-4); } settextstyle(0,0,1); delay(300); outtextxy(maxx-125,30,"RATTLE SNAKE"); delay(300); setcolor(11); setlinestyle(0,1,2); rectangle(maxx-145,65,maxx-5,205); outtextxy(maxx-128,70,"INSTRUCTIONS"); delay(200); setcolor(6); outtextxy(maxx-140,90,"Commands Key"); delay(300); setcolor(8); outtextxy(maxx-140,110," Move Up 8"); delay(50); outtextxy(maxx-140,130," Move Down 5"); delay(50); outtextxy(maxx-140,150," Move Right 6"); delay(50); outtextxy(maxx-140,170," Move Left 4"); delay(50); outtextxy(maxx-140,190," Exit 0"); delay(200); setcolor(12); setlinestyle(0,1,2); rectangle(maxx-145,210,maxx-5,350); setcolor(1); outtextxy(maxx-130,220,"Player's Name"); setcolor(15); outtextxy(maxx-100,230,"Yellow"); setcolor(4); delay(200); itoa(score,scor,10); outtextxy(maxx-140,250,"Score"); outtextxy(maxx-50,250,scor); delay(200); setcolor(10); outtextxy(maxx-140,280,"Level"); delay(200); setcolor(13); outtextxy(maxx-140,310,"Maze 1"); delay(200); setcolor(14); outtextxy(maxx-140,340,"High Score "); outtextxy(maxx-50,340,hs); for(j=0; j<=1000; j++) { putpixel(random(maxx-150),random(maxy),6); delay(1); } while (a!='0') { // plot new image if(a=='6') putimage(x, y, head1, XOR_PUT); if(a=='4') putimage(x, y, head2, XOR_PUT); if(a=='8') putimage(x, y, head3, XOR_PUT); if(a=='5') putimage(x, y, head4, XOR_PUT); for(j=0; j<k; j++) { putimage(X[i-j], Y[i-j], body, XOR_PUT); } if((X[i-j-1]-X[i-j])<0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail1, XOR_PUT); if((X[i-j-1]-X[i-j])>0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail2, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])<0) putimage(X[i-j], Y[i-j], tail3, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])>0) putimage(X[i-j], Y[i-j], tail4, XOR_PUT); delay(speed); if(second==1) { setcolor(15); outtextxy(maxx-140,360,"Press Any Key..."); getch(); setcolor(0); outtextxy(maxx-140,360,"Press Any Key..."); a='6'; second=2; } if(first==1) { setcolor(15); outtextxy(maxx-140,360,"Congratulations "); sound(100); delay(300); nosound(); getch(); setcolor(0); outtextxy(maxx-140,360,"Congratulations "); second++; first=2; } // erase old image if(a=='6') putimage(x, y, head1, XOR_PUT); if(a=='4') putimage(x, y, head2, XOR_PUT); if(a=='8') putimage(x, y, head3, XOR_PUT); if(a=='5') putimage(x, y, head4, XOR_PUT); for(j=0; j<k; j++) { putimage(X[i-j], Y[i-j], body, XOR_PUT); } if((X[i-j-1]-X[i-j])<0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail1, XOR_PUT); if((X[i-j-1]-X[i-j])>0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail2, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])<0) putimage(X[i-j], Y[i-j], tail3, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])>0) putimage(X[i-j], Y[i-j], tail4, XOR_PUT); if(f==0) { putimage(r1,r2,food,XOR_PUT); f=1; } z--; if((x>=r1 && y>=r2 && x<=r1+10 && y<=r2+10) || (x<=r1 && y<=r2 && x>=r1-10 && y>=r2-10) || z==0) { if(z!=0) { sound(800); delay(20); setcolor(0); score += 10; outtextxy(maxx-50,250,scor); itoa(score,scor,10); if(score>hscore) { strcpy(hs,scor); setfillstyle(1,1); bar(maxx-140,337,maxx-20,348); setcolor(14); outtextxy(maxx-50,340,hs); outtextxy(maxx-140,340,"High Score "); if(first==0) { first=1; } } setcolor(4); outtextxy(maxx-50,250,scor); k++; nosound(); } z=100; putimage(r1,r2,food,XOR_PUT); repr1: r1=random(450); if(r1<50) goto repr1; repr2: r2=random(400); if(r2<50) goto repr2; f=0; } i++; X[i]=x; Y[i]=y; b=a; if(kbhit()) { rep: a=getche(); if((b=='6' && a=='4') || (b=='4' && a=='6')) a=b; if((b=='8' && a=='5') || (b=='5' && a=='8')) a=b; if(a!='6' && a!='4' && a!='8' && a!='0' && a!='5') a=b; } /* if(x>maxx-170) x=0; if(y>maxy) y=0;*/ if(a=='8') y -= bo; if(a=='5') y += bo; if(a=='4') x -= bo; if(a=='6') x += bo; for(j=i+1; j<i-k; j--) { if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10)) { if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10)) { a='0'; } outtextxy(maxx-140,360,"C "); } if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10)) { if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10)) { a='0'; } outtextxy(maxx-140,360,"C "); } } /* for(j=i; j<i-k; j--) { if((y>=Y[j] && y<=Y[j]+10) || (y<=Y[j] && y>=Y[j]-10)) { if((x>=X[j] && x<=X[j]+10) || (x<=X[j] && x>=X[j]-10)) { a='5'; } } if((x>=X[j] && x<=X[j]+10) || (x<=X[j] && x>=X[j]-10)) { if((y>=Y[j] && y<=Y[j]+10) || (y<=Y[j] && y>=Y[j]-10)) { a='5'; } } if(j==0) break; } */ /* if(x<=0) x=maxx-170; if(y<=0) y=maxy;*/ if(maze==1) { if(x<=14 || x>=maxx-184 || y<=14 || y>=maxy-14) { a='0'; } } } if(score>hscore) { ofstream onfile("c:\tc\bin\rattle.txt"); onfile<<scor; onfile.close(); } setcolor(15); outtextxy(maxx-140,390," Gameover"); sound(100); delay(400); nosound(); getch(); /* clean up */ free(body); closegraph(); }
char obj_figura::edita() { ctela.limpa_teclado(); MouseFun mouse(getmaxx() / 2, getmaxy() / 2, 0); if (carquivo_somente_leitura) return FALSO; else if (!carquivo_definido) return FALSO; else { tipo_xy cx, cy; tipo_xy cxant, cyant; tipo_xy ccentrox, ccentroy; tipo_angulo cangulo = 0; tipo_raio craio = 1; char ccirculo = FALSO; char ccor = 15; char* cursor = (char*) malloc(sizeof(char) * 2); char caracter = NULL; char clicado = FALSO; char velocidade = 1; cx = (tipo_xy) (ctela.max_x + 1) / 2; cy = (tipo_xy) (ctela.max_y + 1) / 2; ccentrox = cx; ccentroy = cy; cor(8); line(cx, 0, cx, ctela.max_y); line(0, cy, ctela.max_x, cy); putpixel(0, 0, 15); getimage(0, 0, 0, 0, cursor); putpixel(0, 0, 0); do { cx = mouse.x(); cy = mouse.y(); if (keypressed) { ctela.le_teclado(&caracter); switch (caracter) { case CARACTER_NULO: ctela.le_teclado(&caracter); if (!ccirculo) { switch (caracter) { case SETA_CIMA: cy -= velocidade; break; case SETA_BAIXO: cy += velocidade; break; case SETA_DIREITA: cx += velocidade; break; case SETA_ESQUERDA: cx -= velocidade; break; } } else { switch (caracter) { case SETA_CIMA: craio += velocidade; break; case SETA_BAIXO: craio -= velocidade; break; case SETA_DIREITA: cangulo += velocidade; break; case SETA_ESQUERDA: cangulo -= velocidade; break; } converte(cangulo, craio, &cx, &cy, ccentrox, ccentroy); } break; case BARRA_DE_ESPACO: if (!clicado) { clicado = VERDADEIRO; cxant = cx; cyant = cy; } else { clicado = FALSO; poe(cx, cy, cxant, cyant, ccor); } break; case CTRL_A: poe(cx + 5, cy, cx + 20, cy + 13, ccor); poe(cx, cy, cx + 15, cy + 16, ccor); poe(cx - 2, cy + 5, cx + 13, cy + 19, ccor); poe(cx - 4, cy + 7, cx + 11, cy + 20, ccor); poe(cx - 5, cy + 14, cx + 12, cy, ccor); poe(cx - 1, cy + 16, cx + 15, cy + 2, ccor); poe(cx + 3, cy + 19, cx + 17, cy + 5, ccor); poe(cx + 6, cy + 20, cx + 20, cy + 8, ccor); break; case CTRL_B: ccor++; if (ccor > 15) ccor = 0; break; case CTRL_D: if (!ccirculo) { ccentrox = cx; ccentroy = cy; } else if (ccirculo) { cx = ccentrox; cy = ccentroy; } ccirculo = !ccirculo; break; case MAIS: velocidade++; break; case MENOS: velocidade--; break; case CTRL_Z: tira(); break; } } putimage(cx, cy, cursor, XOR_PUT); delay(1); putimage(cx, cy, cursor, XOR_PUT); } while(caracter != ENTER); return VERDADEIRO; } }
void main() { int sss,q,ll,gd=DETECT,p,gm,area,a=(450-(50*5)),d,cat=77,ch,dh,eh,t1,t2,t12,t22,len,cc,hh; char *str,*str1,*tim; initgraph(&gd,&gm,""); p=1; front(); dr: viewport(); q=menu(); if(q==3) { arun: hh=help(); if(hh==1) { how(); goto arun; } if(hh==2) { select(); goto arun; } if(hh==3) { credit(); goto arun; } if(hh==4) { design(); goto arun; } if(hh==5) goto dr; } if(q==2) { rr: ll=sivakumar(); if(ll==1) { p=m2(); goto rr; } if(ll==2) { a=speed(); viewport(); goto rr; } if(ll==3) { topscore(); goto rr; } if(ll==4) goto dr; } if(q==4) exit(0); if(q==1) { names(); hide(); viewport(); x[0]=85; x[1]=70; x[2]=55; x[3]=40; y[0]=y[1]=y[2]=y[3]=35; setcolor(4); rectangle(24,19,626,396); ra(); setcolor(15); setfillstyle(1,10); bar(32,32,43,43); area=imagesize(30,30,45,45); buff=malloc(area); getimage(30,30,45,45,buff); putimage(30,30,buff,XOR_PUT); setpos(0,0); setfillstyle(1,0); bar(100,100,500,350); prakash(p); level=p; putimage(40,35,buff,XOR_PUT); putimage(55,35,buff,XOR_PUT); putimage(70,35,buff,XOR_PUT); putimage(85,35,buff,XOR_PUT); textcolor(GREEN+BLINK); len=0; status("Game Play: Arrow keys Menu: Esc Pause (or) Play: Others key"); while(1) { sss=getpixel(5,5); if(sss!=0); { setfillstyle(SOLID_FILL,0); bar(0,0,15,15); } if(((i-4)%11==0)&&(bon==0)&&(len!=(i-4))) { len=(i-4); gettime(&t); bonous(); bon=1; t1=t.ti_sec; cc=10; } gettime(&t); if((t1!=t.ti_sec)&&(bon==1)) { cc--; t1=t.ti_sec; itoa(cc,tim,10); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); outtextxy(500,0,tim); } if((cc==0)&&(bon==1)) { putimage(xc1,yc1,f2,XOR_PUT); bar(470,0,530,18); bon=0; } gotoxy(68,1); setcolor(6); itoa(score,str,10); setfillstyle(1,0); settextstyle(3,0,1); if(strcmp(str,str1)!=0) { bar(80,400,350,450); outtextxy(100,420,"Score : "); outtextxy(180,420,str); strcpy(str1,str); } if(kbhit()) { // ch=getch(); dh=getch(); cat=dh; } else { arrange(x,y,i); if(set==0) food(); if(cat!=dupli) cat=lock(cat,dupli); switch(cat) { case 72: if(y[1]==20) y[0]=380; else y[0]=y[1]-15; x[0]=x[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; set=0; sound(800); delay(40); score+=bb; nosound(); putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 80: if(y[1]==380) y[0]=20; else y[0]=y[1]+15; x[0]=x[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; score+=bb; sound(800); delay(40); set=0; nosound(); putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 75: if(x[1]==25) x[0]=610; else x[0]=x[1]-15; y[0]=y[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; sound(800); delay(40); set=0; nosound(); score+=bb; putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 77: if(x[1]==610) x[0]=25; else x[0]=x[1]+15; y[0]=y[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; set=0; sound(800); delay(40); score+=bb; nosound(); putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 27: goto dx; // break; } dupli=cat; } } } dx: call(); }
void End(int flag) { int i; int key=0; char *buffer; char *s[]={"真的退出吗?(y/n):","是","否","制作小组",\ "图形相关:谭歆","主程序:汪航勋","碰撞相关:林远骥",\ "菜单等:黄懿可","指导老师:肖少拥","版权所有,盗版不究","谢谢!"}; noplay(); if (flag) { buffer=malloc(imagesize(200,210,440,290)); getimage(200,210,440,290,buffer); draw_window(210,220,430,280); outchinese(220,227,s[0],YELLOW,1,0); for (i=1;i<=2;i++) outchinese(150+i*100,245,s[i],GREEN,1,0); drawmouse(mousex,mousey); while(1) { while(bioskey(1)!=0) getch(); position(0); drawmouse(mousex,mousey); key=bioskey(1); if (button==1) { for (i=1;i<=2;i++) { if (150+i*100 < mousex && mousex <166+i*100 && 245 <mousey && mousey <261) break; } } if (key== LOWER_y || i==1) break; else if (key == LOWER_n || i==2) { position(0); putimage(200,210,buffer,COPY_PUT); free(buffer); if (Music_on) play(2); return; } } } free(mouse); free(mouse_temp); free(dash_dot); cleardevice(); while(bioskey(1)!=0) getch(); for (i=3;i<10;i++) { outchinese(maxx/2-strlen(s[i])*4,100+18*i+200*(i/9),s[i],WHITE,1,0); delay(30000); delay(30000); } getch(); cleardevice(); outchinese(250,200,s[10],GREEN,4,1); sleep(1); closegraph(); exit(0); }
void main() { start: time_t t; int spe,ar,xc,j,yc,xr=0,yr=195,a=1,b=1,c=0,are; int X=0,Y=0,s,area1,si,bs=1; int gd,gm,level,speed,re,i,b_int; FILE *fp; gd=DETECT; initgraph(&gd,&gm,"..//BGI "); char user[100],l[5]; /* setfillstyle(1,BLUE); bar(0,0,getmaxx(),getmaxy()); printf("\n%d",getpixel(10,10)); getchar(); */ //input menu cleardevice(); outtextxy(1,1,"plz enter level u want to play 1,2,3"); l[0]=getch(); outtextxy(1,20,l); level=l[0]-48; printf("\nlevel %d",level); getchar(); void *bomb; //fp=fopen("data","w"); //fprintf(fp,"\n%s",user); //bomb rectangle(0,0,50,25); setfillstyle(1,YELLOW); floodfill(2,2,15); b_int=imagesize(0,0,50,25); bomb=malloc(b_int); getimage(0,0,50,25,bomb); cleardevice(); gotoxy(1,1); void *bu,*buf; void *buff1,*steel; void *spp; //green bricks rectangle(0,0,50,25); setfillstyle(1,GREEN); floodfill(2,2,15); spe=imagesize(0,0,50,25); spp=malloc(spe); getimage(0,0,50,25,spp); //putimage(0,0,spp,XOR_PUT); //g bricks ends rectangle(0,0,50,25); setfillstyle(6,6); floodfill(2,2,15); ar=imagesize(0,0,50,25); bu=malloc(ar); getimage(0,0,50,25,bu); putimage(0,0,bu,XOR_PUT); rectangle(0,0,50,25); setfillstyle(6,8); floodfill(2,2,15); are=imagesize(0,0,50,25); buf=malloc(are); getimage(0,0,50,25,buf); putimage(0,0,buf,XOR_PUT); cleardevice(); if(level<4) { for( j=0;j<180;j+=27) for( i=0;i<600;i+=52) { if(i==104&&j==54) { putimage(0+i,27+j,bomb,XOR_PUT); //putimage(0,27,bomb,XOR_PUT); //putimage(572,27,bomb,XOR_PUT); //putimage(0,27,buf,XOR_PUT); //putimage(572,27,buf,XOR_PUT); } else if(i>0&&j>0&&i*rand()%100==0) { putimage(0+i,27+j,spp,XOR_PUT); putimage(0,27,spp,XOR_PUT); putimage(572,27,spp,XOR_PUT); putimage(0,27,buf,XOR_PUT); putimage(572,27,buf,XOR_PUT); } else { putimage(0+i,27+j,bu,XOR_PUT); putimage(0,27,bu,XOR_PUT); putimage(572,27,bu,XOR_PUT); putimage(0,27,buf,XOR_PUT); putimage(572,27,buf,XOR_PUT); } } if(level==2) { srand(time(&t)); //steel starts si=random(100); rectangle(si,300,si+200,320); setfillstyle(1,RED) ; floodfill(si+10,310,15); steel=malloc(re); //getimage(si,300,si+200,320,steel); //putimage(0,0,steel,XOR_PUT); //steel ends for(i=si;i<(si+200);i+=4) { putpixel(i,303,BLACK); putpixel(i,317,BLACK); } } } setcolor(3); rectangle(80,445,159,452); setfillstyle(1,1); floodfill(82,447,3); area1=imagesize(80,445,159,452); buff1=malloc(area1); getimage(80,445,159,452,buff1); setcolor(4); line(0,479,640,479); int area,x=325,y=325,ch,xdirn=-1,ydirn=-1,step; int maxx,maxy; void *buff; setcolor(WHITE); setfillstyle(SOLID_FILL,RED); circle(350,350,5); floodfill(350,350,WHITE); area=imagesize(345,345,355,355); buff=malloc(area); getimage(345,345,355,355,buff); putimage(345,345,buff,XOR_PUT); speed=16; while (1) { if(level==3) { invisible(); if(y<getmaxy()/2+50||y>getmaxy()-60) { putimage(x, y, buff, XOR_PUT); delay(speed); putimage(x, y, buff, XOR_PUT); } else delay(speed); } else if(level==1||level==2) { putimage(x, y, buff, XOR_PUT); delay(speed); putimage(x, y, buff, XOR_PUT); } else { cout<<"\nthis level is under construction"; getchar(); break; // cout<<"plz selsect correct level"; } x=x+(xdirn*2); y=y+(ydirn*3); if ( x + 10 - 1 > 640 ) { xdirn*=-1; x = 640 - 10 + 1; } if (x < 0) { xdirn*=-1; x = 0; } if ( y + 10 - 1 > 470 ) { // ydirn*=-1; // y = 470 - 10 + 1; cleardevice(); settextstyle(1,0,4); outtextxy(100,200,"Sorry! You loose the game."); outtextxy(150,240,"Type 't' to Try Again!!!"); gotoxy(30,8); cout<<"Total Score : "<<c; if(getchar()=='t') { free(bu); free(buff); free(buff1); closegraph(); goto start; } else goto tt; } if(c==1020) { outtextxy(180,200,"Congrats! You have finished thegame."); gotoxy(30,8); cout<<"Total Score : "<<c; delay(5000); getch(); goto tt; } if ( getpixel(x,y)==1 ) { sound(500); delay(15); nosound(); ydirn*=-1; xc=x; yc=y; a=xc/52; b=(yc/27); xr=a*52; yr=b*27; } if (getpixel(x,y)==6) { sound(100); delay(50); nosound(); ydirn*=-1; xc=x; yc=y; a=xc/52; b=(yc/27); xr=a*52; yr=b*27; putimage(xr,yr,bu,XOR_PUT); c+=10; } if (getpixel(x,y)==RED) { sound(100); delay(50); nosound(); ydirn*=-1; xc=x; yc=y; a=xc/52; b=(yc/27); xr=a*52; yr=b*27; // putimage(xr,yr,steel,XOR_PUT); } //bomb if (getpixel(x,y)==YELLOW) { sound(400); delay(50); nosound(); bomb_blasts(); setcolor(RED); settextstyle(1,0,4); outtextxy(40,40,"BLAST....."); setcolor(BLUE); outtextxy(150,240,"Type 't' to Try Again!!!"); if(getchar()=='t') goto start; else goto tt; } if(getpixel(x,y+3)==2) { sound(100); delay(50); nosound(); ydirn*=-1; xc=x; yc=y; a=xc/52; b=(yc/27); xr=a*52; yr=b*27; putimage(xr,yr,spp,XOR_PUT); speed-=2; bs++; // c+=10; gotoxy(1,1); cout<<"speed: "<<bs<<"x"; } if (getpixel(x,y-3)==8) { sound(800); delay(200); nosound(); ydirn*=-1; xc=x; yc=y; a=xc/52; b=(yc/27); xr=a*52; yr=b*27; putimage(xr,yr,buf,XOR_PUT); c+=100; } if( y < 0 ) { ydirn*=-1; y=0; } gotoxy(65,1); cout<<"SCORE : "<<c; fprintf(fp," score %d",c); // cout<<"last users"; fclose(fp); if( kbhit() ) { s=getkey(); if(s!=1) { if(X>480) { X=480; putimage(160+X,445+Y,buff1,XOR_PUT); } if(X<-80) { X=-80; putimage(80+X,445+Y,buff1,XOR_PUT); } putimage(80+X,445+Y,buff1,XOR_PUT); //if(s==72) // Y+=-40; if(s==75) X+=-40; //if(s==80) // Y+=40; if(s==77) X+=40; putimage(80+X,445+Y,buff1,XOR_PUT); //cout<<X; } if(s==1) { tt: free(bu); free(buff); free(buff1); closegraph(); } } } }
void main() { int gd=DETECT,gm,area,x=25,y=25,ch,xdirn=1,ydirn=1; int maxx,maxy; char *buff; initgraph(&gd,&gm,"d:\\tc\\bgi"); setcolor(WHITE); setfillstyle(SOLID_FILL,LIGHTRED); circle(50,50,25); floodfill(50,50,WHITE); area=imagesize(25,25,75,75); buff=(char *)malloc(area); getimage(25,25,75,75,buff); maxx=getmaxx(); maxy=getmaxy(); rectangle(0,20,maxx,maxy); outtextxy(250,10,"Animation"); while(1) { if(kbhit()) { ch=getch(); if(ch=='\r') { xdirn*=-1; ydirn*=-1; } else { if(ch==27) break; } } putimage(x,y,buff,OR_PUT); delay(0); x=x+(xdirn*5); y=y+(ydirn*2); putimage(x,y,buff,OR_PUT); if(x>maxx-50||x<0); { sound(50); delay(10); nosound(); xdirn*=-1; } if(y>maxy-50||y<20) { sound(50); delay(10); nosound(); ydirn*=-1; } } getch(); closegraph(); restorecrtmode(); }