fork download
  1.  
  2. #include<stdio.h>
  3. #include<GL/glut.h>
  4. #include<string.h>
  5. int maxy=600, count=0, maxx=500, n=3, m=3,r,q;
  6. int count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0,count10=0;
  7. int x=25,y=50;
  8. char str[10];
  9. void id1();
  10. void id();
  11. void draw_target();
  12. void redraw();
  13.  
  14. /*to display bitmap char*/
  15. void bitmap_output(int x,int y,char *string,void *font)
  16. {
  17. int len,i;
  18. glRasterPos2f(x,y);
  19. len=(int)strlen(string);
  20. for(i=0;i<len;i++)
  21. {
  22. glutBitmapCharacter(font,string[i]);
  23. }
  24. return;
  25. }
  26.  
  27. /*based on count display no of arrows and result of game*/
  28. void counting()
  29. {
  30. sprintf(str,"No of arrows:%d",count);
  31. bitmap_output(400,40,str,GLUT_BITMAP_HELVETICA_18);
  32. if(count1==1 && count2==1 && count3==1 && count4==1 && count5==1 && count6==1 && count7==1 && count8==1 && count9==1 && count10==1)
  33. {
  34. bitmap_output(5,300,"CONGRATULATIONS YOU WON",GLUT_BITMAP_TIMES_ROMAN_24);
  35. glutIdleFunc(NULL);
  36. }
  37. else if(count>=15)
  38. {
  39. sprintf(str,"NO of arrows:%d,NO OF ARROWS OVER GAME LOST",count);
  40. bitmap_output(5,300,str,GLUT_BITMAP_TIMES_ROMAN_24);
  41. glutIdleFunc(NULL);
  42. }
  43. }
  44.  
  45. //TO CHECK WHETHER ARROW HITS TARGET
  46. void disa()
  47. {
  48. if((x+110==300) && (y>=435 && y<=465) && (!count1))
  49. {
  50. count1=1;
  51. x=25;
  52. y=0;
  53. count++;
  54. glutIdleFunc(id);
  55. }
  56. else if((x+110 == 375)&&(y>=385&&y<=415) && (!count2))
  57. {
  58. count2=1;
  59. x=25;
  60. y=0;
  61. count++;
  62. glutIdleFunc(id);
  63. }
  64. else if((x+110==399)&&(y>=465 &&y<=495)&&(!count3))
  65. {
  66. count3=1;
  67. x=25;
  68. y=0;
  69. count++;
  70. glutIdleFunc(id);
  71. }
  72. else if((x+110==249)&&(y>=355&&y<=385)&&(!count4))
  73.  
  74. {
  75. count4=1;
  76. x=25;
  77. y=0;
  78. count++;
  79. glutIdleFunc(id);
  80. }
  81. else if((x+110==351)&&(y>=315&&y<=345)&&(!count5))
  82. {
  83. count5=1;
  84. x=25;
  85. y=0;
  86. count++;
  87. glutIdleFunc(id);
  88. }
  89. else if((x+110==450)&&(y>=275&&y<=305)&&(!count6))
  90. {
  91. count6=1;
  92. x=25;
  93. y=0;
  94. count++;
  95. glutIdleFunc(id);
  96. }
  97. else if((x+110==330)&&(y>=230&&y<=260)&&(!count7))
  98. {
  99. count7=1;
  100. x=25;
  101. y=0;
  102. count++;
  103. glutIdleFunc(id);
  104. }
  105. else if((x+110==201)&&(y>=185&&y<=215)&&(!count8))
  106. {
  107. count8=1;
  108. x=25;
  109. y=0;
  110. count++;
  111. glutIdleFunc(id);
  112. }
  113. else if((x+110==339)&&(y>=135&&y<=165)&&(!count9))
  114. {
  115. count9=1;
  116. x=25;
  117. y=0;
  118. count++;
  119. glutIdleFunc(id);
  120. }
  121. else if((x+110==300)&&(y>=85&&y<=115)&&(!count10))
  122. {
  123. count10=1;
  124. x=25;
  125. y=0;
  126. count++;
  127. glutIdleFunc(id);
  128. }
  129. }
  130.  
  131. /*to move arrow up*/
  132. void id()
  133. {
  134. y+=n;
  135. disa();
  136. if(y>maxy)
  137. {
  138. y=0;
  139. count++;
  140. }
  141. glutPostRedisplay();
  142. }
  143. //to draw arrow
  144. void disp()
  145. {
  146. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  147. glLoadIdentity();
  148. glColor3f(1,1,0);
  149. bitmap_output(150,450,"BLOCKSHOOTING",GLUT_BITMAP_TIMES_ROMAN_24);
  150. counting();
  151. //Drawing of arrow
  152. glColor3f(0,1,1);
  153. glBegin(GL_LINES);
  154. glVertex2d(x,y);
  155. glVertex2d(x+100,y);
  156. glEnd();
  157. glLineWidth(2);
  158. glBegin(GL_LINES);
  159. glVertex2d(x,y+2);
  160. glVertex2d(x+100,y-2);
  161. glEnd();
  162. glBegin(GL_LINES);
  163. glVertex2d(x,y-2);
  164. glVertex2d(x+100,y-2);
  165. glEnd();
  166. glBegin(GL_TRIANGLES);
  167. glVertex2d (x+100,y+3);
  168. glVertex2d(x+110,y);
  169. glVertex2d(x+100,y-3);
  170. glEnd();
  171. glBegin(GL_QUADS);
  172. glVertex2d(x,y+3);
  173. glVertex2d(x,y-3);
  174. glVertex2d(x-10,y-5);
  175. glVertex2d(x-10,y+5);
  176. glEnd();
  177. draw_target();
  178. glFlush();
  179. glutSwapBuffers();
  180. }
  181.  
  182. void init()
  183. {
  184. glClearColor(0,0,0,1);
  185. glColor3f(1,0,0);
  186. glMatrixMode(GL_PROJECTION);
  187. glLoadIdentity();
  188. gluOrtho2D(0,500,0,500);
  189. glMatrixMode(GL_MODELVIEW);
  190. }
  191.  
  192. //to draw the target inside the loop
  193.  
  194. void draw_target()
  195. {
  196. if(count1==0)
  197. {
  198. glColor3f(1,0,1);
  199. glPointSize(30);
  200. glBegin(GL_POINTS);
  201. glVertex2d(300,450);
  202. glEnd();
  203. glBegin(GL_LINE_LOOP);
  204. glVertex2d(285,465);
  205. glVertex2d(315,465);
  206. glVertex2d(315,435);
  207. glVertex2d(285,435);
  208. glEnd();
  209. }
  210. else
  211. {
  212. glColor3f(1,1,1);
  213. glPointSize(20);
  214. glBegin(GL_POINTS);
  215. glVertex2d(300,450);
  216. glEnd();
  217. }
  218. if(count2==0)
  219. {
  220. glColor3f(1,0,1);
  221. glPointSize(30);
  222. glBegin(GL_POINTS);
  223. glVertex2d(375,400);
  224. glEnd();
  225. glBegin(GL_LINE_LOOP);
  226. glVertex2d(360,415);
  227. glVertex2d(390,415);
  228. glVertex2d(390,385);
  229. glVertex2d(360,385);
  230. glEnd();
  231. }
  232. else
  233. {
  234. glColor3f(1,1,1);
  235. glPointSize(20);
  236. glBegin(GL_POINTS);
  237. glVertex2d(375,400);
  238. glEnd();
  239. }
  240. if(count3==0)
  241. {
  242. glColor3f(1,0,1);
  243. glPointSize(30);
  244. glBegin(GL_POINTS);
  245. glVertex2d(400,480);
  246. glEnd();
  247. glBegin(GL_LINE_LOOP);
  248. glVertex2d(385,495);
  249. glVertex2d(415,495);
  250. glVertex2d(415,465);
  251. glVertex2d(385,465);
  252. glEnd();
  253. }
  254. else
  255. {
  256. glColor3f(1,1,1);
  257. glPointSize(20);
  258. glBegin(GL_POINTS);
  259. glVertex2d(400,480);
  260. glEnd();
  261. }
  262. if(count4==0)
  263. {
  264. glColor3f(1,0,1);
  265. glPointSize(30);
  266. glBegin(GL_POINTS);
  267. glVertex2d(250,370);
  268. glEnd();
  269. glBegin(GL_LINE_LOOP);
  270. glVertex2d(235,385);
  271. glVertex2d(265,385);
  272. glVertex2d(265,355);
  273. glVertex2d(235,355);
  274. glEnd();
  275. }
  276. else
  277. {
  278. glColor3f(1,1,1);
  279. glPointSize(20);
  280. glBegin(GL_POINTS);
  281. glVertex2d(250,370);
  282. glEnd();
  283. }
  284. if(count5==0)
  285. {
  286. glColor3f(1,0,1);
  287. glPointSize(30);
  288. glBegin(GL_POINTS);
  289. glVertex2d(350,330);
  290. glEnd();
  291. glBegin(GL_LINE_LOOP);
  292. glVertex2d(335,345);
  293. glVertex2d(365,345);
  294. glVertex2d(365,315);
  295. glVertex2d(335,315);
  296. glEnd();
  297. }
  298. else
  299. {
  300. glColor3f(1,1,1);
  301. glPointSize(20);
  302. glBegin(GL_POINTS);
  303. glVertex2d(350,330);
  304. glEnd();
  305. }
  306. if(count6==0)
  307. {
  308. glColor3f(1,0,1);
  309. glPointSize(30);
  310. glBegin(GL_POINTS);
  311. glVertex2d(450,290);
  312. glEnd();
  313. glBegin(GL_LINE_LOOP);
  314. glVertex2d(435,305);
  315. glVertex2d(465,305);
  316. glVertex2d(465,275);
  317. glVertex2d(435,275);
  318. glEnd();
  319. }
  320. else
  321. {
  322. glColor3f(1,1,1);
  323. glPointSize(20);
  324. glBegin(GL_POINTS);
  325. glVertex2d(450,290);
  326. glEnd();
  327. }
  328. if(count7==0)
  329. {
  330. glColor3f(1,0,1);
  331. glPointSize(30);
  332. glBegin(GL_POINTS);
  333. glVertex2d(330,245);
  334. glEnd();
  335. glBegin(GL_LINE_LOOP);
  336. glVertex2d(315,260);
  337. glVertex2d(345,260);
  338. glVertex2d(345,230);
  339. glVertex2d(315,230);
  340. glEnd();
  341. }
  342. else
  343. {
  344. glColor3f(1,1,1);
  345. glPointSize(20);
  346. glBegin(GL_POINTS);
  347. glVertex2d(330,245);
  348. glEnd();
  349. }
  350. if(count8==0)
  351. {
  352. glColor3f(1,0,1);
  353. glPointSize(30);
  354. glBegin(GL_POINTS);
  355. glVertex2d(200,200);
  356. glEnd();
  357. glBegin(GL_LINE_LOOP);
  358. glVertex2d(185,215);
  359. glVertex2d(215,215);
  360. glVertex2d(215,185);
  361. glVertex2d(185,185);
  362. glEnd();
  363. }
  364. else
  365. {
  366. glColor3f(1,1,1);
  367. glPointSize(20);
  368. glBegin(GL_POINTS);
  369. glVertex2d(200,200);
  370. glEnd();
  371. }
  372. if(count9==0)
  373. {
  374. glColor3f(1,0,1);
  375. glPointSize(30);
  376. glBegin(GL_POINTS);
  377. glVertex2d(400,150);
  378. glEnd();
  379. glBegin(GL_LINE_LOOP);
  380. glVertex2d(385,165);
  381. glVertex2d(415,165);
  382. glVertex2d(415,135);
  383. glVertex2d(385,135);
  384. glEnd();
  385. }
  386. else
  387. {
  388. glColor3f(1,1,1);
  389. glPointSize(20);
  390. glBegin(GL_POINTS);
  391. glVertex2d(400,150);
  392. glEnd();
  393. }
  394. if(count10==0)
  395. {
  396. glColor3f(1,0,1);
  397. glPointSize(30);
  398. glBegin(GL_POINTS);
  399. glVertex2d(300,100);
  400. glEnd();
  401. glBegin(GL_LINE_LOOP);
  402. glVertex2d(285,115);
  403. glVertex2d(315,115);
  404. glVertex2d(315,85);
  405. glVertex2d(285,85);
  406. glEnd();
  407. }
  408. else
  409. {
  410. glColor3f(1,1,1);
  411. glPointSize(20);
  412. glBegin(GL_POINTS);
  413. glVertex2d(300,100);
  414. glEnd();
  415. }
  416. glFlush();
  417. }
  418.  
  419. //to move the arrow left when ‘r’ pressed
  420. void id1()
  421. {
  422. x+=m;
  423. disa();
  424. if(x+110>maxx)
  425. {
  426. x=25;
  427. y=0;
  428. count++;
  429. glutIdleFunc(id);
  430. }
  431. glutPostRedisplay();
  432. }
  433.  
  434. //set key to perform desired operation
  435. void keys(unsigned char k,int r,int q)
  436. {
  437. if(k=='r')
  438. glutIdleFunc(id1);
  439. if(k=='q')
  440. exit(0);
  441. }
  442.  
  443. //sub menu to display instructions
  444. void demo_menu(int i)
  445. {
  446. switch(i)
  447. {
  448. case 5:
  449. case 6:
  450. case 7:
  451. case 8:break;
  452. }
  453. }
  454.  
  455. //sub menu to display designer names
  456. void demo(int i)
  457. {
  458. switch(i)
  459. {
  460. case 9:
  461. case 10:
  462. case 11:break;
  463. }
  464. }
  465. void game(int id)
  466. {
  467. switch(id);
  468. {
  469. }
  470. }
  471. int main(int argc,char **argv)
  472. {
  473. int sub_menu;
  474. glutInit(&argc,argv);
  475. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  476. glutInitWindowSize(900,900);
  477. glutCreateWindow("BLOCK SHOOTING GAME ARCHERY");
  478. sub_menu=glutCreateMenu(demo_menu);
  479. glutAddMenuEntry(" r to move right",5);
  480. glutAddMenuEntry("A total of i5 arrows and 10 blocks are present",6);
  481. glutAddMenuEntry("You loose the game if the arrow count exceeds the blocks count",7);
  482. glutAddMenuEntry("or else you win",8);
  483. glutCreateMenu(game);
  484. glutAddSubMenu("INSTRUCTIONS",sub_menu);
  485. glutAttachMenu(GLUT_RIGHT_BUTTON);
  486. glutDisplayFunc(disp);
  487. glutIdleFunc(id);
  488. glutKeyboardFunc(keys);
  489. init();
  490. glEnable(GL_DEPTH_TEST);
  491. glutMainLoop();
  492. return 0;
  493. }
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:20: fatal error: GL/glut.h: No such file or directory
 #include<GL/glut.h>
                    ^
compilation terminated.
stdout
Standard output is empty