diff --git a/BUBBLESH.C b/BUBBLESH.C new file mode 100644 index 0000000..2b8b366 --- /dev/null +++ b/BUBBLESH.C @@ -0,0 +1,1013 @@ +/**************************************** + * Title : Bubble Shooter Game * + * Author: Garcia, Noel and Nuevo, Jay Martin * + ***************************************/ + +/* LIBRARIES */ +#include +#include +#include +#include +#include +#include +#include + +/* GAME AREA BORDERS*/ +#define GP1X 240 +#define GP1Y 75 +#define GP2X 630 +#define GP2Y 462 + +/*CONSTANTS*/ +#define RADIUS 19.5 +#define BORDERCOLOR LIGHTCYAN +#define FONTCOLOR YELLOW +#define BTNFONTCOLOR WHITE +#define BUTTONCOLOR LIGHTRED +#define PENALTYDUE 240 + +/* MOUSE FUNCTIONS*/ +union REGS in,out; +int callmouse(void); +int mousehide(void); +void mouseposi(int *xpos, int *ypos, int *click); +void setposi(int *xpos,int *ypos); +void restrictmouseptr(int x1,int y1,int x2,int y2); + +int cursorInRange(int pt1x,int pt1y,int pt2x,int pt2y); + +void gameTime(void); +void newGame(void); +void initialize(void); +void statusCheck(void); +void gamePenalty(void); +void gameLose(void); +void gameWin(void); +void bulletColors(void); +void genBullet(void); +void genBubLine(int num, float cpy); +void showBubbles(void); +void shoot(void); +void bubbleBump(double *movex, double *movey, int *hit); +void bubblePop(double x, double y); +void bubbleEraser(void); +void score(int pop); +void background(void); +void gameTitle(char notif[15]); +void gameGUI(void); +void help(void); +void music(double pitch, int time); + + /* VARIABLES */ +int xpos,ypos,cl; + +int bubctr; +int bulletctr; +int bubline; +int popctr=0; +int pop=0; +int colors[6],numcolors; +char mode[9]; + +double octave[8]={261.62,293.66,329.62,349.22,392,440,493.88,523.24}; + +struct bubble{ + float cpx; + float cpy; + int color; +} bubble[500],bullet[500]; + +struct pop{ + int index; + int bubtype; +} bubpop[20]; + +int status=NULL; + +time_t t; +long int startT,pauseT=0,elapsedT,elapsedPT,gameT,penaltyT; + +int tpop,tscore; + +/*-------------------------------------------------------*/ + +int main(void) +{ + int gd,gm,error; + + /* LAUNCH GRAPHICS MODE */ + detectgraph(&gd,&gm); + initgraph(&gd,&gm,""); + error = graphresult(); + if (error != grOk) + { + printf("Graphics error occurred"); + printf("Press any key to halt:"); + getch(); /* wait for a key */ + exit(1); + } + + /* GAME START-UP */ + gameTitle("Welcome !"); + + while(1) + { + mouseposi(&xpos,&ypos,&cl); + + /* GAME TIME */ + gameTime(); + if ((gameT%PENALTYDUE==0) && gameT!=NULL && status==0) + { + gamePenalty(); + delay(400); + statusCheck(); + } + + if (cl==2 && cursorInRange(GP1X,GP1Y-25,GP2X,GP2Y)) + restrictmouseptr(0,0,639,479); + + /* NEW GAME BUTTON CLICK */ + if (cl==1 && cursorInRange(45,32,195,70)) + { + music(octave[0],50); + music(octave[7],50); + newGame(); + continue; + } + /* EXIT BUTTON CLICK */ + else if (cl==1 && cursorInRange(45,85,195,123)) + { + music(octave[0],50); + music(octave[7],50); + break; + } + /* SHOOT */ + else if (status==NULL && status==0 && cl==1 && cursorInRange(GP1X,GP1Y,GP2X,GP2Y)) + { + restrictmouseptr(GP1X,GP1Y-25,GP2X,GP2Y-RADIUS*2); + shoot(); + } + + /* HELP */ + else if (cl==1 && status!=1 && cursorInRange(GP1X+75,GP1Y-20, GP1X+75+65,GP1Y-5)) + { + music(octave[0],50); + music(octave[7],50); + mousehide(); + help(); + status=1; + pauseT=t; + restrictmouseptr(0,0,639,479); + callmouse(); + } + + /* PAUSE */ + else if (status==NULL && status==0 && cl==1 && cursorInRange(GP1X+160,GP1Y-20, GP1X+160+65,GP1Y-5)) + { + music(octave[0],50); + music(octave[7],50); + status=2; + pauseT=t; + restrictmouseptr(0,0,639,479); + + mousehide(); + setviewport(GP1X+1,GP1Y+1,GP2X-1,GP2Y-1,1); + + setcolor(BORDERCOLOR); + setfillstyle(1,BLACK); + bar(120,190,265,250); + rectangle(120,190,265,250); + + setcolor(FONTCOLOR); + settextjustify(CENTER_TEXT,TOP_TEXT); + settextstyle(SMALL_FONT,HORIZ_DIR,8); + outtextxy(195,207,"PAUSED"); + + callmouse(); + } + + /* RESUME */ + else if(status!=0 && status!=-1 && cl==1 && cursorInRange(GP1X+245,GP1Y-20, GP1X+245+65,GP1Y-5)) + { + music(octave[0],50); + music(octave[7],50); + status=0; + elapsedPT += elapsedT; + restrictmouseptr(GP1X,GP1Y-25,GP2X,GP2Y); + mousehide(); + clearviewport(); + showBubbles(); + callmouse(); + } + elapsedT = t-pauseT; + } + + /* CLOSE GAME */ + mousehide(); + cleardevice(); + gameTitle("Thanks for Playing !"); + + cleardevice(); + closegraph(); + return 0; +} + +int cursorInRange(int pt1x, int pt1y, int pt2x, int pt2y ) +{ + if (xpos>=pt1x && ypos>=pt1y && xpos<=pt2x && ypos<=pt2y) + return 1; + else + return 0; +} + +void gameTime(void) +{ + time(&t); + if(startT!=NULL && status==0) + { + gameT = (t-startT-elapsedPT); + gotoxy(6,21); + printf("Game Time: %02ld",gameT/60); + gotoxy(19,21); + printf(":%02ld ",gameT%60); + } + +} + +void newGame(void) +{ + int i,j=0,numlines; + float cpy=RADIUS; + flushall(); + + /*INITIALIZE*/ + gotoxy(6,21); + printf("Game Time: 00:00 "); + sprintf(mode,"------"); + pop=0,tpop=0; + tscore=0; + bubctr=0,bulletctr=0,bubline=0; + score(0); + bulletctr--; + + setviewport(GP1X+1,GP1Y+1,GP2X-1,GP2Y-1,1); + clearviewport(); + background(); + + /* GAME MODE */ + setcolor(FONTCOLOR); + settextjustify(CENTER_TEXT,TOP_TEXT); + settextstyle(SMALL_FONT,HORIZ_DIR,9); + outtextxy(205,50,"SELECT DIFFICULTY: "); + + setcolor(BORDERCOLOR); + setfillstyle(1,BLACK); + bar(120,120,265,180); /* EASY */ + rectangle(120,120,265,180); + bar(120,190,265,250); /*MEDIUM*/ + rectangle(120,190,265,250); + bar(120,260,265,320); + rectangle(120,260,265,320); /* HARD */ + + setcolor(FONTCOLOR); + settextstyle(SMALL_FONT,HORIZ_DIR,8); + outtextxy(195,137,"EASY"); + outtextxy(195,207,"MEDIUM"); + outtextxy(195,277,"HARD"); + + while(1) + { + mouseposi(&xpos,&ypos,&cl); + if (cursorInRange(GP1X+120,GP1Y+120,GP1X+265,GP1Y+180) && cl==1) + { + numlines=3; + numcolors=4; + sprintf(mode,"EASY"); + break; + } + else if (cursorInRange(GP1X+120,GP1Y+190,GP1X+265,GP1Y+250) && cl==1) + { + numlines=4; + numcolors=5; + sprintf(mode,"MEDIUM"); + break; + } + else if (cursorInRange(GP1X+120,GP1Y+260,GP1X+265,GP1Y+320) && cl==1) + { + numlines=6; + numcolors=7; + sprintf(mode,"HARD"); + break; + } + if (cl==1 && cursorInRange(45,85,195,123)) + return; + } + music(octave[0],50); + music(octave[7],50); + + /*INITIALIZE TIME*/ + srand((unsigned)time(&t)); + elapsedT=1; + elapsedPT=0; + startT=t+1; + status=0; + pauseT=0; + + /*AVAILABLE COLORS */ + for (i=9; i<9+numcolors; i++) + colors[j++]=i; + + /* GEN NUM OF LINES */ + for(i=0; i=3) + score(pop); + else + score(0); +} + +void bubbleBump(double *movex, double *movey, int *hit) +{ + int i; + + if(bullet[bulletctr].cpx-*movex+GP1X<=GP1X+RADIUS || bullet[bulletctr].cpx-*movex+GP1X>=GP2X-RADIUS) + *movex = -*movex; + + for (i=90; i>0;) + { + if(getpixel(bullet[bulletctr].cpx-*movex+(RADIUS*cos(i))+cos(i), bullet[bulletctr].cpy-*movey-(RADIUS*sin(i))+sin(i))) + { + *hit =1; + *movex+=cos(i); + *movey-=sin(i); + } + if(getpixel(bullet[bulletctr].cpx-*movex+RADIUS*cos(180-i)+cos(180-i), bullet[bulletctr].cpy-*movey-RADIUS*sin(180-i)+sin(180-i))) + { + *hit =1; + *movex+=cos(180-i); + *movey-=sin(180-i); + } + if(getpixel(bullet[bulletctr].cpx-*movex+(RADIUS*cos(360-i))+cos(360-i), bullet[bulletctr].cpy-*movey-(RADIUS*sin(360-i))+sin(360-i))) + { + *hit =1; + *movex+=cos(360-i); + *movey-=sin(360-i); + } + if(getpixel(bullet[bulletctr].cpx-*movex+RADIUS*cos(270+i)+cos(270+i), bullet[bulletctr].cpy-*movey-RADIUS*sin(270+i)+sin(270+i))) + { + *hit =1; + *movex+=cos(270+i); + *movey-=sin(270+i); + } + if (getpixel(bullet[bulletctr].cpx-*movex+RADIUS*cos(i) +cos(i), bullet[bulletctr].cpy-*movey-RADIUS*sin(i)+sin(i)) ==0 && + getpixel(bullet[bulletctr].cpx-*movex+RADIUS*cos(180-i)+cos(180-i), bullet[bulletctr].cpy-*movey-RADIUS*sin(180-i)+sin(180-i))==0 && + getpixel(bullet[bulletctr].cpx-*movex+RADIUS*cos(360-i)+cos(360-i), bullet[bulletctr].cpy-*movey-RADIUS*sin(360-i)+sin(360-i))==0 && + getpixel(bullet[bulletctr].cpx-*movex+RADIUS*cos(270+i)+cos(270+i), bullet[bulletctr].cpy-*movey-RADIUS*sin(270+i)+sin(270+i))==0) + i--; + + } +} + +void bubblePop(double x, double y) +{ + int i,j,k,repeat=0; + double posx,posy; + + for (i=0; i<360; i++) + { + posx=x+RADIUS*cos(i)+2*cos(i); + posy=y+RADIUS*sin(i)+2*sin(i); + + if(getpixel(posx,posy) == bullet[bulletctr].color) + { + for(j=0; jbubble[j].cpx - RADIUS && + posxbubble[j].cpy - RADIUS && + posybullet[j].cpx - RADIUS && + posxbullet[j].cpy - RADIUS && + posy