// Don't be a lamer please! // (C)1997 Henrik Tingström // E-mail:henrik_tingstrom@hotmail.com #include #include #include #include #include #define antal 10 #define antalkill 20 #define antstars 50 void cls(int); void nollstall(int); void nollstall_star(int); void nollstall_star_init(int); void nollstall_blow(int); void vsync(void); void ball(void); void kill_ship(void); void grafik(void); void stars(void); void game_on(void); void shoots(void); void rita_skepp(void); void meteorer(void); void starta(void); void kill_meteor(int); void blow_meteor(int); void ledtext(void); void rita_kill(void); int ch, shipx, shipy, skott, skottx, skotty, farg[antal], poang, liv, kill; int meteor[antal][2], stor[antal], blow[antal][6][2]; int ballx, bally, ballxv, ballyv,kill2, svart; int start, level, star[antstars][3]; float vink, levelrakn, hast; char c; void main(void) { grafik(); randomize(); system("mode con rate = 32 delay 1"); do{ c = 'q'; ch = 77; ballx = 30; bally = getmaxy()/2; ballxv = random(2); ballyv = random(2); shipx = 30; shipy = bally; skott = 0; start = 1; level = 1; svart = 10; liv = 5; kill2 = 0; poang = 0; kill = 0; hast = -62.0; for(int i=0;i 20) { hast+=0.5; level++; svart--; if(svart < 0) svart = 1; levelrakn=0; // cls(BLACK); ledtext(); } if(hast > -3) levelrakn+=0.2; stars(); if(start != 0) starta(); if(kill != 0) rita_kill(); ball(); meteorer(); if(poang == 0) { gotoxy(1,1); printf(" Anv„nd PILTANGENTERNA OCH SPACE! Skydda det GR™NA skeppet! "); setcolor(random(getmaxcolor())); rectangle(0,0,getmaxx(),15); } vsync(); delay(40); } for(i=0;i getmaxy()-10) ch = 72; else if(shipx < 10) ch = 77; else if(shipx > getmaxx()/2) ch = 75; setcolor(BLUE); setfillstyle(1,BLUE); rita_skepp(); } void starta(void) { setcolor(BLACK); setfillstyle(1,BLACK); rita_skepp(); start++; shipy = bally; gotoxy(37,10); printf("Var redo"); if(shipx < 60) { shipx++; } if(start > antalkill-1) { hast = hast+60; cls(BLACK); ledtext(); start = 0; } setcolor(BLUE); setfillstyle(1,BLUE); rita_skepp(); } void ball(void) { setcolor(BLACK); setfillstyle(1,BLACK); fillellipse(ballx,bally,4,40); if(bally < 100) ballyv = 1; if(bally > getmaxy()-100) ballyv = 0; if(ballyv == 1) bally+=2; if(ballyv == 0) bally-=2; if(ballx < 15) ballxv = 1; if(ballx > 40) ballxv = 0; if(ballxv == 1) ballx++; if(ballxv == 0) ballx--; setcolor(GREEN); setfillstyle(1,GREEN); fillellipse(ballx,bally,4,40); setfillstyle(5,LIGHTGREEN); fillellipse(ballx,bally,2,20); } void meteorer(void) { int i = 0; int j,k; while(i < antal) { if(kill == 0 && kill2 == 0 && start == 0) game_on(); setcolor(BLACK); setfillstyle(1,BLACK); ellipse(meteor[i][0],meteor[i][1],0,360,stor[i]+5,2); fillellipse(meteor[i][0],meteor[i][1],stor[i]+2,2); if(blow[i][5][1] != 0) blow_meteor(i); if(stor[i]+hast > 0 && blow[i][5][1] == 0) { meteor[i][0]-=stor[i]+hast; if(farg[i] == LIGHTGRAY) meteor[i][0]--; } else { meteor[i][0]--; } if(skott == 1 && (i == 0 || i > antal/2)) shoots(); int slump = random(2); if(slump == 0 && stor[i] > 6) meteor[i][1]-=random(2); else if(slump == 1 && stor[i] > 6) meteor[i][1]-=random(6); if(bally < meteor[i][1] && kill == 0 && start == 0 && stor[i] < 6) meteor[i][1]-=1; else if(bally > meteor[i][1] && kill == 0 && start == 0 && stor[i] < 6) meteor[i][1]+=1; if(bally < meteor[i][1] && kill == 0 && start == 0 && stor[i] > 5) meteor[i][1]-=2; else if(bally > meteor[i][1] && kill == 0 && start == 0 && stor[i] > 5) meteor[i][1]+=2; if(bally < meteor[i][1] && (kill != 0 || start != 0)) meteor[i][1]+=2; else if(bally > meteor[i][1] && (kill != 0 || start != 0)) meteor[i][1]-=2; if(meteor[i][0] < 0 || meteor[i][1] > getmaxy() || meteor[i][1] < 30) nollstall(i); j=meteor[i][1]-stor[i]-11; k=meteor[i][1]+stor[i]+11; while(j<=k) { if(WHITE == getpixel(meteor[i][0]+8,j) || WHITE == getpixel(meteor[i][0]+10,j)) { kill_meteor(i); //j=k+1; } if(BLUE == getpixel(meteor[i][0]-4,j) && kill == 0) { kill_meteor(i); kill_ship(); j=k+1; } if(GREEN == getpixel(meteor[i][0]-4,j) && kill == 0) { liv = 0; kill2 = 1; kill_meteor(i); kill_ship(); j=k+1; } j++; } if(farg[i] != LIGHTGRAY) { setcolor(farg[i]-8); setfillstyle(1,farg[i]-8); } else { setcolor(farg[i]+1); setfillstyle(1,farg[i]+1); } ellipse(meteor[i][0],meteor[i][1],0,360,stor[i]+5,2); setcolor(farg[i]); setfillstyle(7,farg[i]); fillellipse(meteor[i][0],meteor[i][1],stor[i]+2,2); i++; } } void blow_meteor(int i) { setcolor(BLACK); setfillstyle(1,BLACK); fillellipse(blow[i][0][0],blow[i][0][1],2,1); fillellipse(blow[i][1][0],blow[i][1][1],2,1); fillellipse(blow[i][2][0],blow[i][2][1],2,1); fillellipse(blow[i][3][0],blow[i][3][1],2,1); fillellipse(blow[i][4][0],blow[i][4][1],2,1); blow[i][0][0]-=random(4); blow[i][0][1]-=random(2); blow[i][1][0]-=random(4); blow[i][1][1]+=random(2); blow[i][2][0]-=2; blow[i][2][1]+=1; blow[i][3][0]-=random(4); blow[i][3][1]-=random(2); blow[i][4][0]-=random(2); blow[i][4][1]+=random(4); if(blow[i][2][1] > blow[i][5][0]+(3*stor[i]*2)) { nollstall_blow(i); } else { int col = random(4); col+=10; setcolor(col); setfillstyle(1,WHITE); fillellipse(blow[i][0][0],blow[i][0][1],2,1); fillellipse(blow[i][1][0],blow[i][1][1],2,1); fillellipse(blow[i][2][0],blow[i][2][1],2,1); fillellipse(blow[i][3][0],blow[i][3][1],2,1); fillellipse(blow[i][4][0],blow[i][4][1],2,1); } } void rita_kill(void) { int slump = random(antal-1); slump++; setcolor(WHITE); circle(shipx+5,shipy,slump+10); setcolor(BLACK); circle(shipx+5,shipy,slump+9); kill++; if(kill2 == 1) { setcolor(WHITE); int slump = random(antal-1); slump++; circle(ballx,bally,slump+10); setcolor(BLACK); circle(ballx,bally,slump+9); } if(kill > antalkill-1) { setcolor(BLACK); setfillstyle(1,BLACK); fillellipse(shipx+5,shipy,20,20); start = 1; shipy = bally; kill = 0; } } void nollstall_blow(int i) { blow[i][5][1] = 0; } void nollstall(int i) { meteor[i][0] = getmaxx()-1; meteor[i][1] = random(getmaxy()); meteor[i][1]+=20; stor[i] = random(svart); stor[i]++; if(stor[i] > 10) stor[i] = 7; if(stor[i] < 2) farg[i] = YELLOW; else if(stor[i] == 2) farg[i] = LIGHTCYAN; else if(stor[i] == 3) farg[i] = LIGHTMAGENTA; else if(stor[i] == 4) farg[i] = LIGHTRED; else if(stor[i] == 5) farg[i] = LIGHTRED; else farg[i] = LIGHTGRAY; } void kill_meteor(int i) { if(farg[i] == LIGHTGRAY) { blow[i][0][0] = meteor[i][0]-2; blow[i][0][1] = meteor[i][1]-2; blow[i][1][0] = meteor[i][0]-2; blow[i][1][1] = meteor[i][1]+2; blow[i][2][0] = meteor[i][0]; blow[i][2][1] = meteor[i][1]; blow[i][3][0] = meteor[i][0]+2; blow[i][3][1] = meteor[i][1]+2; blow[i][4][0] = meteor[i][0]+2; blow[i][4][1] = meteor[i][1]-2; blow[i][5][0] = meteor[i][1]; blow[i][5][1] = 1; poang+=farg[i]; nollstall(i); if(kill == 0 && start == 0) ledtext(); } if(farg[i] == LIGHTRED) farg[i] = LIGHTGRAY; else if(farg[i] == LIGHTCYAN) farg[i] = LIGHTMAGENTA; else if(farg[i] == LIGHTMAGENTA) farg[i] = LIGHTRED; else if(farg[i] == YELLOW) farg[i] = LIGHTCYAN; setcolor(BLACK); line(skottx,skotty-vink,skottx+200,skotty-vink); line(skottx,skotty,skottx+200,skotty); line(skottx,skotty+vink,skottx+200,skotty+vink); skott = 0; } void shoots(void) { setcolor(BLACK); line(skottx,skotty-vink,skottx+200,skotty-vink); line(skottx,skotty,skottx+200,skotty); line(skottx,skotty+vink,skottx+200,skotty+vink); if(vink > 0) vink-=2.5; skottx+=15; if(skottx > shipx+70) skott = 0; else { setcolor(WHITE); line(skottx,skotty-vink,skottx+200,skotty-vink); line(skottx,skotty,skottx+200,skotty); line(skottx,skotty+vink,skottx+200,skotty+vink); } } void kill_ship(void) { ch = 77; liv--; kill = 2; if(liv > -1) hast = hast-60; } void rita_skepp(void) { bar(shipx+5,shipy-20,shipx+10,shipy+20); bar(shipx+10,shipy-15,shipx+16,shipy-13); bar(shipx+10,shipy+15,shipx+16,shipy+13); bar(shipx+10,shipy-1,shipx+16,shipy+1); if(start == 0) { setfillstyle(5,LIGHTBLUE); setcolor(LIGHTBLUE); bar(shipx+7,shipy-10,shipx+8,shipy+10); line(shipx+8,shipy-14,shipx+7,shipy-10); line(shipx+8,shipy+14,shipx+7,shipy+10); } } void stars(void) { int q; int i = 0; while(i < antstars) { for(q=0;q<5;q++) { if(star[i][2] == q) { putpixel(star[i][0],star[i][1],BLACK); if(bally > getmaxy()/2+50) star[i][1]-=q+1; else if(bally < getmaxy()/2-50) star[i][1]+=q+1; star[i][0]-=q+1*2; if(star[i][2] == 0) putpixel(star[i][0],star[i][1],LIGHTBLUE); else if(star[i][2] == 1) putpixel(star[i][0],star[i][1],LIGHTRED); else if(star[i][2] == 2) putpixel(star[i][0],star[i][1],LIGHTGRAY); else if(star[i][2] == 3) putpixel(star[i][0],star[i][1],LIGHTCYAN); else if(star[i][2] == 4) putpixel(star[i][0],star[i][1],YELLOW); if(star[i][0] < 0) nollstall_star(i); if(star[i][1] < 22) { putpixel(star[i][0],star[i][1],BLACK); star[i][1] = getmaxy()+20; } if(star[i][1] > getmaxx()) star[i][1] = 23; } } i++; } } void nollstall_star_init(int i) { star[i][0] = random(getmaxx()); star[i][1] = random(getmaxy()); star[i][1]+=40; star[i][2] = random(5); } void nollstall_star(int i) { star[i][1] = random(getmaxx()); star[i][1]+=20; star[i][0] = getmaxx(); star[i][2] = random(5); } void ledtext(void) { setbkcolor(0); // skriver ut ledtext gotoxy(1, 1); printf(" Antal liv: %d ",liv); gotoxy(18,1); printf("Po„ng: %6d ",poang); gotoxy(37,1); printf("Level: %2d **SHOOT2** H. Tingstr”m (C)1996",level); setcolor(DARKGRAY); rectangle(0,0,getmaxx(),15); } 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 */ } }