// Don't be a lamer please! // (C)1997 Henrik Tingström // E-mail:henrik_tingstrom@hotmail.com #include #include #include #include #include #include void cls(int); void grafik(void); void vsync(void); void rita_spelare1(void); void rita_spelare2(void); void rita_mal(void); void sudda_spelare1(void); void sudda_spelare2(void); void sudda_mal(void); void sudda_boll(void); void rita_bana(void); void rita_boll(void); void spela(void); void game_over(void); void borja_spel(void); void antal_spelare(void); void nollstall(void); void sp1_vart(void); void dator_vart(void); void mal_vart(void); void boll_vart(void); void vem_har_bollen(void); void rita_poang(void); void svarighet(void); int sp1[1][5], sp2[1][5]; //x,y,vartx,varty,tacklingshastighet int mal[1][4], boll[1][6]; //x,y,vartx,varty,vart bollen „r,f„rg int poang1, poang2, ant, halla, level; int ch; float hast, boll_stor; void main(void) { grafik(); randomize(); settextjustify(CENTER_TEXT, CENTER_TEXT); borja_spel(); closegraph(); } void borja_spel(void) { ch=55; do{ // antal_spelare(); nollstall(); rita_bana(); rita_poang(); setcolor(WHITE); outtextxy(getmaxx()/2,getmaxy()/2-80,"***SHADER***"); setcolor(LIGHTGRAY); outtextxy(getmaxx()/2,getmaxy()/2-60,"Henrik Tingstr”m (c)1997"); setcolor(WHITE); outtextxy(getmaxx()/2,getmaxy()/2-20,"First To Ten Points!"); outtextxy(getmaxx()/2,getmaxy()/2+20,"You Are The Blue and Computerov Is The Red!"); outtextxy(getmaxx()/2,getmaxy()/2+40,"Use The Arrows And Space!"); outtextxy(getmaxx()/2,getmaxy()/2+80,"Quit A Started Game With '0' (zero)"); outtextxy(getmaxx()/2,getmaxy()/2+60,"Pause A Started Game With 'p'"); ch=55; do{ setcolor(random(14)+1); outtextxy(100,70,"You"); outtextxy(getmaxx()-100,70,"Computerov"); outtextxy(getmaxx()/2+50,getmaxy()/2,"The Goal"); outtextxy(getmaxx()/2,getmaxy()/2+100,"Choose Level: 1-2=EASY 3=MEDIUM 4-5=HARD"); rita_spelare1(); rita_spelare2(); rita_mal(); rita_boll(); // vsync(); delay(20); if(kbhit()) ch = getch(); }while(ch != 49 && ch != 50 && ch != 51 && ch != 52 && ch != 53); while(!kbhit()) { setcolor(WHITE); outtextxy(getmaxx()/2,getmaxy()/2+140,"Press Any Key To Begin!"); setcolor(random(14)+1); outtextxy(100,70,"You"); outtextxy(getmaxx()-100,70,"Computerov"); outtextxy(getmaxx()/2+50,getmaxy()/2,"The Goal"); setcolor(BLACK); outtextxy(getmaxx()/2,getmaxy()/2+100,"Choose Level: 1-2=EASY 3=MEDIUM 4-5=HARD"); rita_spelare1(); rita_spelare2(); rita_mal(); rita_boll(); // vsync(); delay(20); } if(ch == 49) level=2; else if(ch == 50) level=3; else if(ch == 51) level=4; else if(ch == 52) level=5; else if(ch == 53) level=6; else level=4; spela(); game_over(); }while(ch != 48); } void antal_spelare(void) { do{ setcolor(random(14)+1); outtextxy(getmaxx()/2,getmaxy()/2,"Players? (1/2)"); ch=getch(); if(ch == 49) ant=1; else ant=2; }while(ch != 49 && ch != 50); //1 eller 2 spelare } void spela(void) { int slump; rita_bana(); rita_poang(); do{ sudda_spelare1(); sudda_spelare2(); sudda_boll(); sudda_mal(); sp1_vart(); dator_vart(); slump=random(2); if(slump==0) //r„ttvist ska det vara... { rita_spelare1(); rita_spelare2(); } else { rita_spelare2(); rita_spelare1(); } mal_vart(); boll_vart(); rita_mal(); vem_har_bollen(); rita_boll(); // vsync(); delay(60); }while(ch != 48 && poang1 < 10 && poang2 < 10); } void vem_har_bollen(void) { if(boll[0][5] != 0) { if(DARKGRAY==getpixel(boll[0][0],boll[0][1]-6) || DARKGRAY==getpixel(boll[0][0]+6,boll[0][1]) || DARKGRAY==getpixel(boll[0][0],boll[0][1]+6) || DARKGRAY==getpixel(boll[0][0]+6,boll[0][1])) { boll[0][4]=3; boll_vart(); rita_boll(); rita_poang(); setcolor(WHITE); if(boll[0][5] == 1) { poang1++; outtextxy(getmaxx()/2,getmaxy()/2,"You Scored!"); } else if(boll[0][5] == 2) { poang2++; outtextxy(getmaxx()/2,getmaxy()/2,"Computerov Scored!"); } delay(2000); rita_bana(); rita_poang(); boll[0][5]=0; } } if(boll[0][4] != 3) { if(BLUE==getpixel(boll[0][0],boll[0][1]-6) || BLUE==getpixel(boll[0][0]+6,boll[0][1]) || BLUE==getpixel(boll[0][0],boll[0][1]+6) || BLUE==getpixel(boll[0][0]+6,boll[0][1])) { boll[0][4]=1; boll[0][5]=1; } else if(RED==getpixel(boll[0][0],boll[0][1]-6) || RED==getpixel(boll[0][0]+6,boll[0][1]) || RED==getpixel(boll[0][0],boll[0][1]+6) || RED==getpixel(boll[0][0]+6,boll[0][1])) { if(boll[0][4]==1) { halla=0; boll[0][4]=2; } else boll[0][4]=2; boll[0][5]=2; } } } void sp1_vart(void) { int ch2,r; int har_boll=0; if(kbhit()) { ch2=ch; ch=getch(); } if(ch != 112 && ch != 75 && ch != 77 && ch != 80 && ch != 72 && ch != 48 && ch != 32) ch = ch2; if(ch == 112) { while(ch == 112) { setcolor(random(14)+1); outtextxy(getmaxx()/2,getmaxy()/2-20,"PAUSE"); setcolor(WHITE); outtextxy(getmaxx()/2,getmaxy()/2+20,"Press Any Key To Continue"); while(kbhit()) ch = getch(); } setcolor(BLACK); outtextxy(getmaxx()/2,getmaxy()/2-20,"PAUSE"); outtextxy(getmaxx()/2,getmaxy()/2+20,"Press Any Key To Continue"); ch=ch2; } if(ch == 75) { sp1[0][2] = 0; //v„nster } else if(ch == 77) //h”ger { sp1[0][2] = 1; } else if(ch == 72) //upp { sp1[0][3] = 0; } else if(ch == 80) //ned { sp1[0][3] = 1; } if(sp1[0][0] < 50) sp1[0][2]=1; else if(sp1[0][0] > getmaxx()-50) sp1[0][2]=0; if(sp1[0][1] < 50) sp1[0][3]=1; else if(sp1[0][1] > getmaxy()-50) sp1[0][3]=0; if(boll[0][4] == 1) //spelare ett har bollen { har_boll=1; if(sp1[0][2] == 0) { boll[0][2] = 0; boll[0][0]-=25; } else if(sp1[0][2] == 1) { boll[0][2] = 1; boll[0][0]+=25; } if(sp1[0][3] == 0) { boll[0][3] = 0; boll[0][1]-=25; } else if(sp1[0][3] == 1) { boll[0][3] = 1; boll[0][1]+=25; } if(ch==32) { boll[0][4]=0; halla=80; hast=10; ch = ch2; } // else // halla--; boll[0][5]=1; } if(sp1[0][2]==0) sp1[0][0]-=4-har_boll; else if(sp1[0][2]==1) sp1[0][0]+=4-har_boll; if(sp1[0][3]==0) sp1[0][1]-=4-har_boll; else if(sp1[0][3]==1) sp1[0][1]+=4-har_boll; } void dator_vart(void) { int r=random(5);//slump om hur ofta int har_boll=0; if(boll[0][4] == 0) //bollen finns p† plan { if(boll[0][0] < sp2[0][0]) { sp2[0][2] = 0; //v„nster } else if(boll[0][0] > sp2[0][0]) //h”ger { sp2[0][2] = 1; } if(boll[0][1] < sp2[0][1]) //upp { sp2[0][3] = 0; } else if(boll[0][1] > sp2[0][1]) //ned { sp2[0][3] = 1; } } else if(boll[0][4] == 1 && r==0) //spelare 1 har bollen { if(sp1[0][0] < sp2[0][0]) { sp2[0][2] = 0; //v„nster } else if(sp1[0][0] > sp2[0][0]) //h”ger { sp2[0][2] = 1; } if(sp1[0][1] < sp2[0][1]) //upp { sp2[0][3] = 0; } else if(sp1[0][1] > sp2[0][1]) //ned { sp2[0][3] = 1; } } else if(boll[0][4] == 2) //datorn har bollen { har_boll=1; if(boll[0][0] > mal[0][0]) { boll[0][2] = 0; boll[0][0]-=25; } else if(boll[0][0] < mal[0][0]) { boll[0][2] = 1; boll[0][0]+=25; } if(boll[0][1] > mal[0][1]) { boll[0][3] = 0; boll[0][1]-=25; } else if(boll[0][1] < mal[0][1]) { boll[0][3] = 1; boll[0][1]+=25; } if(mal[0][0] < sp2[0][0]) { sp2[0][2] = 0; //v„nster } else if(mal[0][0] > sp2[0][0]) //h”ger { sp2[0][2] = 1; } if(mal[0][1] < sp2[0][1]) //upp { sp2[0][3] = 0; } else if(mal[0][1] > sp2[0][1]) //ned { sp2[0][3] = 1; } if(halla<=0) { boll[0][4]=0; halla=80; hast=10; } // else // halla--; boll[0][5]=2; } if(sp2[0][0] < 50) sp2[0][2]=1; else if(sp2[0][0] > getmaxx()-50) sp2[0][2]=0; if(sp2[0][1] < 50) sp2[0][3]=1; else if(sp2[0][1] > getmaxy()-50) sp2[0][3]=0; if(sp2[0][2]==0) sp2[0][0]-=level-har_boll; else if(sp2[0][2]==1) sp2[0][0]+=level-har_boll; if(sp2[0][3]==0) sp2[0][1]-=level-har_boll; else if(sp2[0][3]==1) sp2[0][1]+=level-har_boll; } void mal_vart(void) { if(boll[0][4]==3) { if(halla<0) { boll[0][0]=random(getmaxx()-80)+40; boll[0][1]=random(getmaxy()-80)+40; boll[0][2]=random(2); boll[0][3]=random(2); boll[0][4]=0; halla=80; boll_stor=0; hast=3; } else halla--; } if(mal[0][0] < 50) mal[0][2]=1; else if(mal[0][0] > getmaxx()-50) mal[0][2]=0; if(mal[0][1] < 50) mal[0][3]=1; else if(mal[0][1] > getmaxy()-50) mal[0][3]=0; if(mal[0][2]==0) mal[0][0]-=2; else if(mal[0][2]==1) mal[0][0]+=2; if(mal[0][3]==0) mal[0][1]-=2; else if(mal[0][3]==1) mal[0][1]+=2; } void boll_vart(void) { hast-=0.08; if(hast < 0) hast=0; if(boll[0][4] == 0) { if(boll[0][0] < 50) boll[0][2]=1; else if(boll[0][0] > getmaxx()-50) boll[0][2]=0; if(boll[0][1] < 50) boll[0][3]=1; else if(boll[0][1] > getmaxy()-50) boll[0][3]=0; if(boll[0][2]==0) boll[0][0]-=hast; else if(boll[0][2]==1) boll[0][0]+=hast; if(boll[0][3]==0) boll[0][1]-=hast; else if(boll[0][3]==1) boll[0][1]+=hast; } else if(boll[0][4] == 1) { boll[0][0] = sp1[0][0]; boll[0][1] = sp1[0][1]+3; } else if(boll[0][4] == 2) { boll[0][0] = sp2[0][0]; boll[0][1] = sp2[0][1]+3; } else if(boll[0][4] == 3) { boll[0][0] = mal[0][0]; boll[0][1] = mal[0][1]; } } void nollstall(void) { boll_stor=0; sp1[0][0]=100; sp1[0][1]=100; sp1[0][2]=1; sp1[0][3]=1; sp1[0][4]=3; sp2[0][0]=getmaxx()-100; sp2[0][1]=100; sp2[0][2]=0; sp2[0][3]=1; sp2[0][4]=3; mal[0][0]=getmaxx()/2; mal[0][1]=getmaxy()/2; boll[0][0]=getmaxx()/2; boll[0][1]=getmaxy()/2; mal[0][2]=random(2); mal[0][3]=random(2); mal[0][1]=getmaxy()/2; mal[0][2]=random(2); mal[0][3]=random(2); poang1=0; poang2=0; boll[0][4]=3; boll[0][5]=0; halla=80; hast=10; } void game_over(void) { char c; c = '1'; ch = 51; do{ while(!kbhit()) { rita_spelare1(); rita_spelare2(); rita_mal(); rita_boll(); setcolor(WHITE); if(poang1 == 10) outtextxy(getmaxx()/2,getmaxy()/2-20,"You Won!"); else if(poang2 == 10) outtextxy(getmaxx()/2,getmaxy()/2-20,"Computerov Won!"); else if(poang2 > poang1) outtextxy(getmaxx()/2,getmaxy()/2-20,"Computerov Almost Won..."); else if(poang2 < poang1) outtextxy(getmaxx()/2,getmaxy()/2-20,"You Almost Won..."); else outtextxy(getmaxx()/2,getmaxy()/2-20,"No Winner..."); outtextxy(getmaxx()/2,getmaxy()/2+20,"Play Again? (Y/N)"); setcolor(random(14)+1); if(level==2) outtextxy(getmaxx()/2,getmaxy()/2,"Level 1 - VERY EASY"); else if(level==3) outtextxy(getmaxx()/2,getmaxy()/2,"Level 2 - EASY"); else if(level==4) outtextxy(getmaxx()/2,getmaxy()/2,"Level 3 - MEDIUM"); else if(level==5) outtextxy(getmaxx()/2,getmaxy()/2,"Level 4 - HARD"); else if(level==6) outtextxy(getmaxx()/2,getmaxy()/2,"Level 5 - VERY HARD"); // vsync(); delay(20); } c = getch(); if(c == '0' || c == 'n' || c == 'N') ch=48; }while(c != '0' && c != 'Y' && c != 'y' && c != 'N' && c != 'n'); } void rita_spelare1(void) { setfillstyle(1,BLUE); setcolor(LIGHTBLUE); fillellipse(sp1[0][0],sp1[0][1],19,19); if(boll[0][4] != 1) circle(sp1[0][0],sp1[0][1]+random(3),random(3)+3); circle(sp1[0][0]-8,sp1[0][1]-10,4); circle(sp1[0][0]+8,sp1[0][1]-10,4); setcolor(random(2)+14); if(sp1[0][2] == 0 && sp1[0][3] == 0) circle(sp1[0][0]-9,sp1[0][1]-11,1); else if(sp1[0][2] == 0 && sp1[0][3] == 1) circle(sp1[0][0]-9,sp1[0][1]-7,1); else if(sp1[0][2] == 1 && sp1[0][3] == 0) circle(sp1[0][0]-7,sp1[0][1]-11,1); else if(sp1[0][2] == 1 && sp1[0][3] == 1) circle(sp1[0][0]-7,sp1[0][1]-7,1); if(sp1[0][2] == 0 && sp1[0][3] == 0) circle(sp1[0][0]+7,sp1[0][1]-11,1); else if(sp1[0][2] == 0 && sp1[0][3] == 1) circle(sp1[0][0]+7,sp1[0][1]-7,1); else if(sp1[0][2] == 1 && sp1[0][3] == 0) circle(sp1[0][0]+9,sp1[0][1]-11,1); else if(sp1[0][2] == 1 && sp1[0][3] == 1) circle(sp1[0][0]+9,sp1[0][1]-7,1); } void rita_spelare2(void) { setfillstyle(1,RED); setcolor(LIGHTRED); fillellipse(sp2[0][0],sp2[0][1],19,19); if(boll[0][4] != 2) circle(sp2[0][0],sp2[0][1]+random(3),random(3)+3); circle(sp2[0][0]-8,sp2[0][1]-10,4); circle(sp2[0][0]+8,sp2[0][1]-10,4); setcolor(random(2)+14); if(sp2[0][2] == 0 && sp2[0][3] == 0) circle(sp2[0][0]-9,sp2[0][1]-11,1); else if(sp2[0][2] == 0 && sp2[0][3] == 1) circle(sp2[0][0]-9,sp2[0][1]-7,1); else if(sp2[0][2] == 1 && sp2[0][3] == 0) circle(sp2[0][0]-7,sp2[0][1]-11,1); else if(sp2[0][2] == 1 && sp2[0][3] == 1) circle(sp2[0][0]-7,sp2[0][1]-7,1); if(sp2[0][2] == 0 && sp2[0][3] == 0) circle(sp2[0][0]+7,sp2[0][1]-11,1); else if(sp2[0][2] == 0 && sp2[0][3] == 1) circle(sp2[0][0]+7,sp2[0][1]-7,1); else if(sp2[0][2] == 1 && sp2[0][3] == 0) circle(sp2[0][0]+9,sp2[0][1]-11,1); else if(sp2[0][2] == 1 && sp2[0][3] == 1) circle(sp2[0][0]+9,sp2[0][1]-7,1); } void rita_mal(void) { setfillstyle(1,DARKGRAY); setcolor(LIGHTGRAY); fillellipse(mal[0][0],mal[0][1],10,10); circle(mal[0][0],mal[0][1],random(5)+2); } void rita_boll(void) { boll_stor+=0.1; if(boll_stor > 5) boll_stor=5; if(boll[0][5]==0) setfillstyle(1,LIGHTGRAY); else if(boll[0][5]==1) setfillstyle(1,LIGHTBLUE); else if(boll[0][5]==2) setfillstyle(1,LIGHTRED); setcolor(BLACK); fillellipse(boll[0][0],boll[0][1],boll_stor,boll_stor); putpixel(boll[0][0],boll[0][1]-1,WHITE); putpixel(boll[0][0]+1,boll[0][1],WHITE); putpixel(boll[0][0],boll[0][1]+1,WHITE); putpixel(boll[0][0]-1,boll[0][1],WHITE); putpixel(boll[0][0],boll[0][1],WHITE); } void sudda_spelare1(void) { setfillstyle(1,BLACK); setcolor(BLACK); fillellipse(sp1[0][0],sp1[0][1],19,19); } void sudda_spelare2(void) { setfillstyle(1,BLACK); setcolor(BLACK); fillellipse(sp2[0][0],sp2[0][1],19,19); } void sudda_mal(void) { setfillstyle(1,BLACK); setcolor(BLACK); fillellipse(mal[0][0],mal[0][1],10,10); } void sudda_boll(void) { setfillstyle(1,BLACK); setcolor(BLACK); fillellipse(boll[0][0],boll[0][1],5,5); } void rita_bana(void) { cls(BLACK); setcolor(DARKGRAY); setfillstyle(7,DARKGRAY); rectangle(20,20,getmaxx()-20,getmaxy()-20); floodfill(0,0,DARKGRAY); setcolor(LIGHTGRAY); rectangle(20,20,getmaxx()-20,getmaxy()-20); } void rita_poang(void) { gotoxy(1,1); printf(" Your Score: %2d Computerov's Score: %2d ***SHADER*** H. Tingstr”m (c)1997 ",poang1,poang2); } void cls(int farg) { // rensar sk„rmen till valfri f„rg union REGS reg; reg.x.ax = 0x0600; reg.x.cx = 0; reg.x.dx = 0x1e4f; reg.h.bh = farg; int86(0x10, ®, ®); } void vsync(void) { // V„ntar p† att str†len som uppdaterar sk„rmen skall befinna sig // l„ngst upp p† sk„rmen. asmloop: asm { mov dx,0x3da in al,dx and al,8 cmp al,8 jne asmloop } } void grafik(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; /* register a driver that was added into graphics.lib */ errorcode = registerbgidriver(EGAVGA_driver); /* report any registration errors */ if (errorcode < 0) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } }