SpiralRock

Tushar

Nov 14th, 2009
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.84 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<graphics.h>
  4. #include<dos.h>
  5. #include<stdlib.h>
  6.  
  7. void MainMenu();
  8. void SelectMenu(int SelectFrom,int SelectTo);
  9. void Help();
  10. void Quit();
  11. void StartGame();
  12. void UpdateCross(int Direction);
  13. void FireRay(int TargetX,int TargetY);
  14.  
  15. struct Astroids
  16. {int X;
  17. int Y;
  18. }Astroid[5];
  19.  
  20. struct Crossair
  21. {int X;
  22. int Y;
  23. }Cross;
  24.  
  25. void FireRay(int TargetX,int TargetY)
  26. {int i=208;
  27. setcolor(RED);
  28. setfillstyle(1,YELLOW);
  29. fillellipse(135,213,3,20);
  30. for (i=208;i<=218;i++)
  31. {line(135,i,TargetX,TargetY);
  32. }
  33. delay(500);
  34. setcolor(0);
  35. setfillstyle(1,0);
  36. setcolor(0);
  37. fillellipse(135,213,3,20);
  38. for (i=208;i<=218;i++)
  39. line(135,i,TargetX,TargetY);
  40. }
  41.  
  42.  
  43. void UpdateCross(int Direction)
  44. {
  45. setcolor(0);
  46. circle(Cross.X,Cross.Y,3);
  47. line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
  48. line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
  49. if (Direction==1)
  50. Cross.Y=Cross.Y-3;
  51. else if (Direction==2)
  52. Cross.X=Cross.X-3;
  53. else if (Direction==3)
  54. Cross.Y=Cross.Y+3;
  55. else if (Direction==4)
  56. Cross.X=Cross.X+3;
  57.  
  58. setcolor(15);
  59. circle(Cross.X,Cross.Y,3);
  60. line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
  61. line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
  62. }
  63.  
  64. void UpdateAstroid(int OldX,int OldY)
  65. {delay(1000);
  66. setcolor(0);
  67. setfillstyle(1,0);
  68. floodfill(OldX,OldY,0);
  69. }
  70.  
  71. void SelectMenu(int SelectFrom,int SelectTo)
  72. {
  73. setcolor(9);
  74.  
  75. if (SelectFrom==1)
  76. {
  77. circle(280,172,4);
  78. /* setfillstyle(1,9);
  79. floodfill(290,164,9); */
  80. }
  81.  
  82. else if (SelectFrom==2)
  83. {
  84. circle(280,212,4);
  85. /* setfillstyle(1,9);
  86. floodfill(290,204,9); */
  87. }
  88.  
  89. else if (SelectFrom==3)
  90. {
  91. circle(280,252,4);
  92. /* setfillstyle(1,9);
  93. floodfill(290,244,9); */
  94. }
  95.  
  96. else if (SelectFrom==4)
  97. {
  98. circle(280,292,4);
  99. /* setfillstyle(1,9);
  100. floodfill(290,164,9);*/
  101. }
  102.  
  103. setcolor(1);
  104.  
  105. if (SelectTo==1)
  106. {
  107. circle(280,172,4);
  108. /* setfillstyle(1,1);
  109. floodfill(290,164,1); */
  110. }
  111.  
  112. else if (SelectTo==2)
  113. {
  114. circle(280,212,4);
  115. /* setfillstyle(1,1);
  116. floodfill(290,204,1); */
  117. }
  118.  
  119. else if (SelectTo==3)
  120. {
  121. circle(280,252,4);
  122. /* setfillstyle(1,1);
  123. floodfill(290,244,1); */
  124. }
  125.  
  126. else if (SelectTo==4)
  127. {
  128. circle(280,292,4);
  129. /* setfillstyle(1,1);
  130. floodfill(290,284,1); */
  131. }
  132. }
  133.  
  134.  
  135. void MainMenu()
  136. {int NewSelect;
  137. int Option=-1;
  138. int Select=1;
  139. char UserPress;
  140. int i;
  141. clrscr();
  142. cleardevice();
  143. printf("\n\n\n Use W,S to choose and Spacebar to select");
  144. printf("\n Asteroid Hunter v0.1\n Developers:\n Palash Relan (09102262)\n Mohit Jain(09102267)");
  145. setcolor(13);
  146. rectangle(5,5,635,475);
  147. rectangle(13,13,627,467);
  148. setfillstyle(9,13);
  149. floodfill(6,6,13);
  150. setfillstyle(1,4);
  151. floodfill(0,0,13);
  152. settextstyle(1,0,1);
  153. setbkcolor(9);
  154. setcolor(1);
  155. /*setusercharsize(1,1,1,1); */
  156. outtextxy(290,160,"Start Game");
  157. outtextxy(290,200,"High Score");
  158. outtextxy(290,240,"Help");
  159. outtextxy(290,280,"Exit");
  160. circle(280,172,4);
  161.  
  162.  
  163. while(Option==-1)
  164. { UserPress=getch();
  165.  
  166. if (UserPress=='w')
  167. { if (Select==1)
  168. {
  169. SelectMenu(1,4);
  170. Select=4;
  171. }
  172. else
  173. {
  174. NewSelect=Select-1;
  175. SelectMenu(Select,NewSelect);
  176. Select--;
  177.  
  178. }
  179. }
  180.  
  181. if (UserPress=='s')
  182. { if (Select==4)
  183. {
  184. SelectMenu(4,1);
  185. Select=1;
  186. }
  187. else
  188. { NewSelect=Select+1;
  189. SelectMenu(Select,NewSelect);
  190. Select++;
  191.  
  192. }
  193. }
  194.  
  195. if (UserPress==' ')
  196. {
  197. Option=Select;
  198. }
  199. }
  200.  
  201.  
  202.  
  203. if (Option==1)
  204. {
  205. StartGame();
  206. }
  207.  
  208. else if (Option==2)
  209. {
  210. exit(0);
  211. }
  212.  
  213. else if (Option==3)
  214. {
  215. Help();
  216. }
  217.  
  218. else if (Option==4)
  219. {
  220. Quit();
  221. }
  222.  
  223. }
  224.  
  225. void StartGame()
  226. {int Africa[12]={340,0,340,25,355,40,366,7,380,0,350,0};
  227. int Australia[14]={420,60,435,40,450,40,455,50,440,60,425,60,420,60};
  228. 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};
  229. int GameOver=0;
  230. clrscr();
  231. cleardevice();
  232. setbkcolor(0);
  233. setcolor(7);
  234. outtextxy(280,220,"Loading...");
  235. setfillstyle(1,7);
  236. bar(265,250,375,257);
  237. setfillstyle(1,4);
  238. delay(600);
  239. bar(265,250,290,257);
  240. delay(200);
  241. bar(265,250,300,257);
  242. delay(300);
  243. bar(265,250,325,257);
  244. delay(1000);
  245. bar(265,250,340,257);
  246. delay(2000);
  247. bar(265,250,375,257);
  248. delay(1000);
  249. clrscr();
  250. cleardevice();
  251. setbkcolor(0);
  252. setcolor(1);
  253. circle(380,-60,140);
  254. setfillstyle(1,1);
  255. floodfill(390,0,1);
  256. setcolor(2);
  257. setfillstyle(1,2);
  258. fillpoly(6,Africa);
  259. fillpoly(7,Australia);
  260. setfillstyle(1,8);
  261. setcolor(8);
  262. fillpoly(14,Spaceship);
  263. setcolor(14);
  264. setfillstyle(1,4);
  265. bar(60,213,75,218);
  266. setfillstyle(9,14);
  267. bar(60,213,75,218);
  268. setcolor(15);
  269. circle(320,240,3);
  270. line(320,235,320,245);
  271. line(315,240,325,240);
  272. Cross.X=320;
  273. Cross.Y=240;
  274.  
  275. Astroid[1].X=400;
  276. Astroid[1].Y=400;
  277. setcolor(6);
  278. circle(Astroid[1].X,Astroid[1].Y,10);
  279. setfillstyle(1,6);
  280. floodfill(Astroid[1].X,Astroid[1].Y,6);
  281.  
  282. while(GameOver==0)
  283. {char UserPress;
  284. UpdateAstroid(Astroid[1].X,Astroid[1].Y);
  285. while(kbhit!=0&&Cross.Y>=100&&Cross.X>=150)
  286. {UserPress=getch();
  287. if (UserPress=='w')
  288. UpdateCross(1);
  289. else if (UserPress=='a')
  290. UpdateCross(2);
  291. else if (UserPress=='s')
  292. UpdateCross(3);
  293. else if (UserPress=='d')
  294. UpdateCross(4);
  295. else if (UserPress==' ')
  296. FireRay(Cross.X,Cross.Y);
  297. else if (UserPress=='e')
  298. MainMenu();
  299. }
  300. if (Cross.X<150)
  301. {
  302. setcolor(0);
  303. circle(Cross.X,Cross.Y,3);
  304. line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
  305. line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
  306. Cross.X=150;
  307. }
  308. if (Cross.Y<100)
  309. {
  310. setcolor(0);
  311. circle(Cross.X,Cross.Y,3);
  312. line(Cross.X,Cross.Y-5,Cross.X,Cross.Y+5);
  313. line(Cross.X-5,Cross.Y,Cross.X+5,Cross.Y);
  314. Cross.Y=100;
  315. }
  316. }
  317.  
  318. getch();
  319. exit(0);
  320. }
  321.  
  322. void Quit()
  323. {char UserPress;
  324. int Option=-1;
  325. int Select=1;
  326. clrscr();
  327. setbkcolor(9);
  328. setfillstyle(0,13);
  329. floodfill(6,6,1);
  330. line(0,100,640,100);
  331. line(0,370,640,370);
  332. setfillstyle(8,13);
  333. floodfill(30,30,1);
  334. floodfill(20,400,1);
  335. printf("\n\n\n\n\n\n\n\n\n\n\n\n Are you sure you want to exit?");
  336. printf("\n\n\n Yes, Exit\n\n No, Return to Menu");
  337. circle(33,247,4);
  338. while(Option==-1)
  339. {UserPress=getch();
  340. if (UserPress=='w')
  341. {if (Select==1)
  342. {setcolor(9);
  343. circle(33,247,4);
  344. setcolor(1);
  345. circle(33,270,4);
  346. Select=2;
  347. }
  348. else if (Select==2)
  349. {setcolor(9);
  350. circle(33,270,4);
  351. setcolor(1);
  352. circle(33,247,4);
  353. Select=1;
  354. }
  355. }
  356. else if (UserPress=='s')
  357. {if (Select==1)
  358. {setcolor(9);
  359. circle(33,247,4);
  360. setcolor(1);
  361. circle(33,270,4);
  362. Select=2;
  363. }
  364. else if (Select==2)
  365. {setcolor(9);
  366. circle(33,270,4);
  367. setcolor(1);
  368. circle(33,247,4);
  369. Select=1;
  370. }
  371. }
  372. else if (UserPress==' ');
  373. Option=Select;
  374. }
  375. if (Option==2)
  376. MainMenu();
  377.  
  378. else if (Option==1)
  379. exit(0);
  380. }
  381.  
  382. void Help()
  383. {clrscr();
  384. setbkcolor(9);
  385. setfillstyle(0,13);
  386. floodfill(6,6,1);
  387. line(0,100,640,100);
  388. line(0,370,640,370);
  389. setfillstyle(8,13);
  390. floodfill(30,30,1);
  391. floodfill(20,400,1);
  392. outtextxy(310,110,"HELP");
  393. /*printf("\n\n\n\n\n\n\n HELP "); */
  394. 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");
  395. printf("\n Your Objective is to protect the earth from the incoming Asteroids");
  396. printf("\n The Spaceship is equipped by a H-14 Ray Gun, which locks on a target and fires an Energy Pulse");
  397. printf("\n Use the 'W,A,S,D' keys to move your Target Lock Crosshair");
  398. printf("\n On aiming over an Asteroid, press the Space Key to fire the energy pulse");
  399. printf("\n To exit the game, presss the 'E' Key");
  400. printf("\n Destroying each Asteroid gives you 10 points");
  401. printf("\n Each missed shot will deduct 2 points from your score");
  402. printf("\n The game is over if an Asteroid reaches the earth");
  403. printf("\n You can check the 3 Highest scores in the High-Scores Option in the Main Menu");
  404. printf("\n Enjoy!\n Press any key to return to Main Menu...");
  405.  
  406. getch();
  407. MainMenu();
  408. }
  409.  
  410.  
  411. void main()
  412. {int gd=DETECT,gm;
  413. clrscr();
  414. initgraph(&gd,&gm,"C:\\TC\\BGI");
  415. MainMenu();
  416. }
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
Add Comment
Please, Sign In to add comment