Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<graphics.h>
- #include<dos.h>
- #include<stdlib.h>
- void MainMenu();
- void SelectMenu(int SelectFrom,int SelectTo);
- void Help();
- void Quit();
- void StartGame();
- void UpdateCross(int Direction);
- void FireRay(int TargetX,int TargetY);
- struct Astroids
- {int X;
- int Y;
- }Astroid[5];
- struct Crossair
- {int X;
- int Y;
- }Cross;
- void FireRay(int TargetX,int TargetY)
- {int i=208;
- setcolor(RED);
- setfillstyle(1,YELLOW);
- fillellipse(135,213,3,20);
- for (i=208;i<=218;i++)
- {line(135,i,TargetX,TargetY);
- }
- delay(500);
- setcolor(0);
- setfillstyle(1,0);
- setcolor(0);
- fillellipse(135,213,3,20);
- for (i=208;i<=218;i++)
- line(135,i,TargetX,TargetY);
- }
- void UpdateCross(int Direction)
- {
- setcolor(0);
- circle(Cross.X,Cross.Y,3);
- line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
- line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
- if (Direction==1)
- Cross.Y=Cross.Y-3;
- else if (Direction==2)
- Cross.X=Cross.X-3;
- else if (Direction==3)
- Cross.Y=Cross.Y+3;
- else if (Direction==4)
- Cross.X=Cross.X+3;
- setcolor(15);
- circle(Cross.X,Cross.Y,3);
- line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
- line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
- }
- void UpdateAstroid(int OldX,int OldY)
- {delay(1000);
- setcolor(0);
- setfillstyle(1,0);
- floodfill(OldX,OldY,0);
- }
- void SelectMenu(int SelectFrom,int SelectTo)
- {
- setcolor(9);
- if (SelectFrom==1)
- {
- circle(280,172,4);
- /* setfillstyle(1,9);
- floodfill(290,164,9); */
- }
- else if (SelectFrom==2)
- {
- circle(280,212,4);
- /* setfillstyle(1,9);
- floodfill(290,204,9); */
- }
- else if (SelectFrom==3)
- {
- circle(280,252,4);
- /* setfillstyle(1,9);
- floodfill(290,244,9); */
- }
- else if (SelectFrom==4)
- {
- circle(280,292,4);
- /* setfillstyle(1,9);
- floodfill(290,164,9);*/
- }
- setcolor(1);
- if (SelectTo==1)
- {
- circle(280,172,4);
- /* setfillstyle(1,1);
- floodfill(290,164,1); */
- }
- else if (SelectTo==2)
- {
- circle(280,212,4);
- /* setfillstyle(1,1);
- floodfill(290,204,1); */
- }
- else if (SelectTo==3)
- {
- circle(280,252,4);
- /* setfillstyle(1,1);
- floodfill(290,244,1); */
- }
- else if (SelectTo==4)
- {
- circle(280,292,4);
- /* setfillstyle(1,1);
- floodfill(290,284,1); */
- }
- }
- void MainMenu()
- {int NewSelect;
- int Option=-1;
- int Select=1;
- char UserPress;
- int i;
- clrscr();
- cleardevice();
- printf("\n\n\n Use W,S to choose and Spacebar to select");
- printf("\n Asteroid Hunter v0.1\n Developers:\n Palash Relan (09102262)\n Mohit Jain(09102267)");
- setcolor(13);
- rectangle(5,5,635,475);
- rectangle(13,13,627,467);
- setfillstyle(9,13);
- floodfill(6,6,13);
- setfillstyle(1,4);
- floodfill(0,0,13);
- settextstyle(1,0,1);
- setbkcolor(9);
- setcolor(1);
- /*setusercharsize(1,1,1,1); */
- outtextxy(290,160,"Start Game");
- outtextxy(290,200,"High Score");
- outtextxy(290,240,"Help");
- outtextxy(290,280,"Exit");
- circle(280,172,4);
- while(Option==-1)
- { UserPress=getch();
- if (UserPress=='w')
- { if (Select==1)
- {
- SelectMenu(1,4);
- Select=4;
- }
- else
- {
- NewSelect=Select-1;
- SelectMenu(Select,NewSelect);
- Select--;
- }
- }
- if (UserPress=='s')
- { if (Select==4)
- {
- SelectMenu(4,1);
- Select=1;
- }
- else
- { NewSelect=Select+1;
- SelectMenu(Select,NewSelect);
- Select++;
- }
- }
- if (UserPress==' ')
- {
- Option=Select;
- }
- }
- if (Option==1)
- {
- StartGame();
- }
- else if (Option==2)
- {
- exit(0);
- }
- else if (Option==3)
- {
- Help();
- }
- else if (Option==4)
- {
- Quit();
- }
- }
- void StartGame()
- {int Africa[12]={340,0,340,25,355,40,366,7,380,0,350,0};
- int Australia[14]={420,60,435,40,450,40,455,50,440,60,425,60,420,60};
- int Spaceship[28]={100,210,100,180,110,210,127,210,132,214,127,218,110,218,100,248,100,218,85,218,75,228,75,200,85,210,100,210};
- int GameOver=0;
- clrscr();
- cleardevice();
- setbkcolor(0);
- setcolor(7);
- outtextxy(280,220,"Loading...");
- setfillstyle(1,7);
- bar(265,250,375,257);
- setfillstyle(1,4);
- delay(600);
- bar(265,250,290,257);
- delay(200);
- bar(265,250,300,257);
- delay(300);
- bar(265,250,325,257);
- delay(1000);
- bar(265,250,340,257);
- delay(2000);
- bar(265,250,375,257);
- delay(1000);
- clrscr();
- cleardevice();
- setbkcolor(0);
- setcolor(1);
- circle(380,-60,140);
- setfillstyle(1,1);
- floodfill(390,0,1);
- setcolor(2);
- setfillstyle(1,2);
- fillpoly(6,Africa);
- fillpoly(7,Australia);
- setfillstyle(1,8);
- setcolor(8);
- fillpoly(14,Spaceship);
- setcolor(14);
- setfillstyle(1,4);
- bar(60,213,75,218);
- setfillstyle(9,14);
- bar(60,213,75,218);
- setcolor(15);
- circle(320,240,3);
- line(320,235,320,245);
- line(315,240,325,240);
- Cross.X=320;
- Cross.Y=240;
- Astroid[1].X=400;
- Astroid[1].Y=400;
- setcolor(6);
- circle(Astroid[1].X,Astroid[1].Y,10);
- setfillstyle(1,6);
- floodfill(Astroid[1].X,Astroid[1].Y,6);
- while(GameOver==0)
- {char UserPress;
- UpdateAstroid(Astroid[1].X,Astroid[1].Y);
- while(kbhit!=0&&Cross.Y>=100&&Cross.X>=150)
- {UserPress=getch();
- if (UserPress=='w')
- UpdateCross(1);
- else if (UserPress=='a')
- UpdateCross(2);
- else if (UserPress=='s')
- UpdateCross(3);
- else if (UserPress=='d')
- UpdateCross(4);
- else if (UserPress==' ')
- FireRay(Cross.X,Cross.Y);
- else if (UserPress=='e')
- MainMenu();
- }
- if (Cross.X<150)
- {
- setcolor(0);
- circle(Cross.X,Cross.Y,3);
- line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
- line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
- Cross.X=150;
- }
- if (Cross.Y<100)
- {
- setcolor(0);
- circle(Cross.X,Cross.Y,3);
- line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
- line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
- Cross.Y=100;
- }
- }
- getch();
- exit(0);
- }
- void Quit()
- {char UserPress;
- int Option=-1;
- int Select=1;
- clrscr();
- setbkcolor(9);
- setfillstyle(0,13);
- floodfill(6,6,1);
- line(0,100,640,100);
- line(0,370,640,370);
- setfillstyle(8,13);
- floodfill(30,30,1);
- floodfill(20,400,1);
- printf("\n\n\n\n\n\n\n\n\n\n\n\n Are you sure you want to exit?");
- printf("\n\n\n Yes, Exit\n\n No, Return to Menu");
- circle(33,247,4);
- while(Option==-1)
- {UserPress=getch();
- if (UserPress=='w')
- {if (Select==1)
- {setcolor(9);
- circle(33,247,4);
- setcolor(1);
- circle(33,270,4);
- Select=2;
- }
- else if (Select==2)
- {setcolor(9);
- circle(33,270,4);
- setcolor(1);
- circle(33,247,4);
- Select=1;
- }
- }
- else if (UserPress=='s')
- {if (Select==1)
- {setcolor(9);
- circle(33,247,4);
- setcolor(1);
- circle(33,270,4);
- Select=2;
- }
- else if (Select==2)
- {setcolor(9);
- circle(33,270,4);
- setcolor(1);
- circle(33,247,4);
- Select=1;
- }
- }
- else if (UserPress==' ');
- Option=Select;
- }
- if (Option==2)
- MainMenu();
- else if (Option==1)
- exit(0);
- }
- void Help()
- {clrscr();
- setbkcolor(9);
- setfillstyle(0,13);
- floodfill(6,6,1);
- line(0,100,640,100);
- line(0,370,640,370);
- setfillstyle(8,13);
- floodfill(30,30,1);
- floodfill(20,400,1);
- outtextxy(310,110,"HELP");
- /*printf("\n\n\n\n\n\n\n HELP "); */
- printf("\n\n\n\n\n\n\n\n\n Welcome To Asteroid Hunter v1.0...\n You are the captain of the Spaceship Asteroid Hunter");
- printf("\n Your Objective is to protect the earth from the incoming Asteroids");
- printf("\n The Spaceship is equipped by a H-14 Ray Gun, which locks on a target and fires an Energy Pulse");
- printf("\n Use the 'W,A,S,D' keys to move your Target Lock Crosshair");
- printf("\n On aiming over an Asteroid, press the Space Key to fire the energy pulse");
- printf("\n To exit the game, presss the 'E' Key");
- printf("\n Destroying each Asteroid gives you 10 points");
- printf("\n Each missed shot will deduct 2 points from your score");
- printf("\n The game is over if an Asteroid reaches the earth");
- printf("\n You can check the 3 Highest scores in the High-Scores Option in the Main Menu");
- printf("\n Enjoy!\n Press any key to return to Main Menu...");
- getch();
- MainMenu();
- }
- void main()
- {int gd=DETECT,gm;
- clrscr();
- initgraph(&gd,&gm,"C:\\TC\\BGI");
- MainMenu();
- }
Add Comment
Please, Sign In to add comment