Guest User

Untitled

a guest
May 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.57 KB | None | 0 0
  1. #include "LUtil.h"
  2. #include <IL/il.h>
  3. #include <IL/ilu.h>
  4. #include "LSpriteSheet.h"
  5. #include "LTexture.h"
  6.  
  7. int add = 0;
  8. int zoom = 0;
  9. double leftzoom = -SCREEN_WIDTH;
  10. double topzoom = -SCREEN_HEIGHT;
  11. double rightzoom = SCREEN_WIDTH;
  12. double bottomzoom = SCREEN_HEIGHT;
  13. int frame = 0;
  14. int frame2 = 0;
  15. int frame3 = 0;
  16. GLfloat gCameraX = 0.f, gCameraY = 0.f, gCameraZ = 0.f;
  17. //Sprite texture
  18.  
  19. LSpriteSheet gArrowSprites;
  20. LSpriteSheet gSamusSprites;
  21. LSpriteSheet jSamusSprites;
  22. LSpriteSheet gSamusSprites1;
  23. LSpriteSheet gSamusSprites2;
  24. LSpriteSheet gSamusSprites3;
  25.  
  26. bool initGL()
  27. {
  28. //Initialize GLEW
  29. GLenum glewError = glewInit();
  30. if( glewError != GLEW_OK )
  31. {
  32. printf( "Error initializing GLEW! %sn", glewGetErrorString( glewError ) );
  33. return false;
  34. }
  35.  
  36. //Make sure OpenGL 2.1 is supported
  37. if( !GLEW_VERSION_2_1 )
  38. {
  39. printf( "OpenGL 2.1 not supported!n" );
  40. return false;
  41. }
  42.  
  43. //Set the viewport
  44. glViewport( 0.f, -0.f, SCREEN_WIDTH, SCREEN_HEIGHT );
  45.  
  46. //Initialize Projection Matrix
  47. glMatrixMode( GL_PROJECTION );
  48. glLoadIdentity();
  49. glOrtho( leftzoom, rightzoom, bottomzoom, topzoom, 1.0, -1.0 );
  50.  
  51. //Initialize Modelview Matrix
  52. glMatrixMode( GL_MODELVIEW );
  53. glLoadIdentity();
  54.  
  55. glPushMatrix();
  56.  
  57. //Initialize clear color
  58. glClearColor( 0.f, 0.f, 0.f, 1.f );
  59.  
  60. //Enable texturing
  61. glEnable( GL_TEXTURE_2D );
  62.  
  63. glEnable( GL_BLEND );
  64. glDisable( GL_DEPTH_TEST );
  65. glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
  66.  
  67. //Check for error
  68. GLenum error = glGetError();
  69. if( error != GL_NO_ERROR )
  70. {
  71. printf( "Error initializing OpenGL! %sn", gluErrorString(error));
  72. return false;
  73. }
  74.  
  75. //Initialize DevIL
  76. ilInit();
  77. ilClearColour( 255, 255, 255, 000 );
  78.  
  79. //Check for error
  80. ILenum ilError = ilGetError();
  81. if( ilError != IL_NO_ERROR )
  82. {
  83. printf( "Error initializing DevIL! %sn", iluErrorString(ilError) );
  84. return false;
  85. }
  86.  
  87. return true;
  88. }
  89.  
  90. LFRect clip;
  91. bool textureLoaded2 = false;
  92. bool textureLoaded3 = false;
  93. bool loadMedia()
  94. {
  95.  
  96. //Load texture
  97. if(textureLoaded2 == false){
  98. if( !gArrowSprites.loadTextureFromFile( "Textures/SamusM.png" ) )
  99. {
  100. printf( "Unable to load texture!n" );
  101. return false;
  102. }
  103. bool textureLoaded2 = true;
  104. }
  105. clip = { 0.f, 0.f, 330.f, 355.f };
  106.  
  107. //Top left
  108. clip.x = 0.f;
  109. clip.y = 0.f;
  110. gArrowSprites.addClipSprite( clip );
  111.  
  112. //Top right
  113. clip = {0.f, 0.f, 310.f, 480.f};
  114.  
  115. clip.x = 331.f;
  116. clip.y = 0.f;
  117. gArrowSprites.addClipSprite( clip );
  118.  
  119. clip = {0.f, 0.f, 330.f, 125.f};
  120. //Bottom left
  121. clip.x = 0.f;
  122. clip.y = 355.f;
  123.  
  124. gArrowSprites.addClipSprite( clip );
  125.  
  126. clip = { 0.f, 0.f, 330.f, 355.f };
  127.  
  128. //Top left
  129. clip.x = 0.f;
  130. clip.y = 480.f;
  131. gArrowSprites.addClipSprite( clip );
  132.  
  133. //Top right
  134. clip = {0.f, 0.f, 310.f, 480.f};
  135.  
  136. clip.x = 331.f;
  137. clip.y = 480.f;
  138. gArrowSprites.addClipSprite( clip );
  139.  
  140. clip = {0.f, 0.f, 330.f, 125.f};
  141. //Bottom left
  142. clip.x = 0.f;
  143. clip.y = 835.f;
  144.  
  145. gArrowSprites.addClipSprite( clip );
  146.  
  147. //Generate VBO
  148. if( !gArrowSprites.generateDataBuffer() )
  149. {
  150. printf( "Unable to clip sprite sheet!n" );
  151. return false;
  152. }
  153. if(textureLoaded3 == false){
  154. if( !jSamusSprites.loadTextureFromFile( "Textures/SamusAran.png" ) )
  155. {
  156. printf( "Unable to load texture!n" );
  157. return false;
  158. }
  159. textureLoaded3 = true;
  160. }
  161. clip = { 0.f, 0.f, 375.f, 562.f };
  162.  
  163. clip.x = 0.f;
  164. clip.y = 0.f;
  165. jSamusSprites.addClipSprite( clip );
  166.  
  167. if( !jSamusSprites.generateDataBuffer() )
  168. {
  169. printf( "Unable to clip sprite sheet!n" );
  170. return false;
  171. }
  172. return true;
  173. }
  174. bool textureLoaded = false;
  175. bool textureLoaded4 = false;
  176. bool clipsLoaded = false;
  177. bool clipsLoaded2 = false;
  178. bool loadGif(){
  179. if(textureLoaded == false){
  180. if(!gSamusSprites.loadTextureFromFile( "Textures/SamusG.png" ) )
  181. {
  182. printf( "Unable to load texture!n" );
  183. return false;
  184. }
  185. textureLoaded = true;
  186. }
  187. if(clipsLoaded == false){
  188. clip = {0.f, 0.f, 213.f, 214.f};
  189.  
  190. clip.x = 0.f;
  191. clip.y = 0.f;
  192.  
  193. gSamusSprites.addClipSprite( clip );
  194.  
  195. clip = {0.f, 0.f, 213.f, 214.f};
  196.  
  197. clip.x = 0.f;
  198. clip.y = 214.f;
  199.  
  200. gSamusSprites.addClipSprite( clip );
  201.  
  202. clip = {0.f, 0.f, 213.f, 214.f};
  203.  
  204. clip.x = 0.f;
  205. clip.y = 428.f;
  206.  
  207. gSamusSprites.addClipSprite( clip );
  208.  
  209. clip = {0.f, 0.f, 213.f, 214.f};
  210.  
  211. clip.x = 0.f;
  212. clip.y = 642.f;
  213.  
  214. gSamusSprites.addClipSprite( clip );
  215.  
  216. clip = {0.f, 0.f, 213.f, 214.f};
  217.  
  218. clip.x = 0.f;
  219. clip.y = 856.f;
  220.  
  221. gSamusSprites.addClipSprite( clip );
  222.  
  223. clip = {0.f, 0.f, 213.f, 214.f};
  224.  
  225. clip.x = 0.f;
  226. clip.y = 1070.f;
  227.  
  228. gSamusSprites.addClipSprite( clip );
  229.  
  230. clip = {0.f, 0.f, 213.f, 214.f};
  231.  
  232. clip.x = 0.f;
  233. clip.y = 1284.f;
  234.  
  235. gSamusSprites.addClipSprite( clip );
  236.  
  237. clip = {0.f, 0.f, 213.f, 214.f};
  238.  
  239. clip.x = 0.f;
  240. clip.y = 1498.f;
  241.  
  242. gSamusSprites.addClipSprite( clip );
  243.  
  244. clip = {0.f, 0.f, 213.f, 214.f};
  245.  
  246. clip.x = 0.f;
  247. clip.y = 1712.f;
  248.  
  249. gSamusSprites.addClipSprite( clip );
  250.  
  251. clip = {0.f, 0.f, 213.f, 214.f};
  252.  
  253. clip.x = 0.f;
  254. clip.y = 1926.f;
  255.  
  256. gSamusSprites.addClipSprite( clip );
  257.  
  258. clip = {0.f, 0.f, 213.f, 214.f};
  259.  
  260. clip.x = 0.f;
  261. clip.y = 2140.f;
  262.  
  263. gSamusSprites.addClipSprite( clip );
  264.  
  265. clip = {0.f, 0.f, 213.f, 214.f};
  266.  
  267. clip.x = 0.f;
  268. clip.y = 2354.f;
  269.  
  270. gSamusSprites.addClipSprite( clip );
  271.  
  272. clip = {0.f, 0.f, 213.f, 214.f};
  273.  
  274. clip.x = 0.f;
  275. clip.y = 2568.f;
  276.  
  277. gSamusSprites.addClipSprite( clip );
  278.  
  279. clip = {0.f, 0.f, 213.f, 214.f};
  280.  
  281. clip.x = 0.f;
  282. clip.y = 2782.f;
  283.  
  284. gSamusSprites.addClipSprite( clip );
  285.  
  286. clip = {0.f, 0.f, 213.f, 214.f};
  287.  
  288. clip.x = 0.f;
  289. clip.y = 2996.f;
  290.  
  291. gSamusSprites.addClipSprite( clip );
  292.  
  293. clip = {0.f, 0.f, 213.f, 214.f};
  294.  
  295. clip.x = 0.f;
  296. clip.y = 3210.f;
  297.  
  298. gSamusSprites.addClipSprite( clip );
  299.  
  300. clip = {0.f, 0.f, 213.f, 214.f};
  301.  
  302. clip.x = 0.f;
  303. clip.y = 3424.f;
  304.  
  305. gSamusSprites.addClipSprite( clip );
  306.  
  307. clip = {0.f, 0.f, 213.f, 214.f};
  308.  
  309. clip.x = 0.f;
  310. clip.y = 3638.f;
  311.  
  312. gSamusSprites.addClipSprite( clip );
  313.  
  314. clip = {0.f, 0.f, 213.f, 214.f};
  315.  
  316. clip.x = 0.f;
  317. clip.y = 3852.f;
  318.  
  319. gSamusSprites.addClipSprite( clip );
  320.  
  321. clip = {0.f, 0.f, 213.f, 214.f};
  322.  
  323. clip.x = 0.f;
  324. clip.y = 4066.f;
  325.  
  326. gSamusSprites.addClipSprite( clip );
  327.  
  328. clip = {0.f, 0.f, 213.f, 214.f};
  329.  
  330. clip.x = 0.f;
  331. clip.y = 4280.f;
  332.  
  333. gSamusSprites.addClipSprite( clip );
  334.  
  335. clip = {0.f, 0.f, 213.f, 214.f};
  336.  
  337. clip.x = 0.f;
  338. clip.y = 4494.f;
  339.  
  340. gSamusSprites.addClipSprite( clip );
  341.  
  342. clip = {0.f, 0.f, 213.f, 214.f};
  343.  
  344. clip.x = 0.f;
  345. clip.y = 4708.f;
  346.  
  347. gSamusSprites.addClipSprite( clip );
  348.  
  349. clip = {0.f, 0.f, 213.f, 214.f};
  350.  
  351. clip.x = 0.f;
  352. clip.y = 4922.f;
  353.  
  354. gSamusSprites.addClipSprite( clip );
  355.  
  356. clip = {0.f, 0.f, 213.f, 214.f};
  357.  
  358. clip.x = 0.f;
  359. clip.y = 5136.f;
  360.  
  361. gSamusSprites.addClipSprite( clip );
  362.  
  363. clip = {0.f, 0.f, 213.f, 214.f};
  364.  
  365. clip.x = 0.f;
  366. clip.y = 5350.f;
  367.  
  368. gSamusSprites.addClipSprite( clip );
  369.  
  370. clip = {0.f, 0.f, 213.f, 214.f};
  371.  
  372. clip.x = 0.f;
  373. clip.y = 5564.f;
  374.  
  375. gSamusSprites.addClipSprite( clip );
  376.  
  377. clip = {0.f, 0.f, 213.f, 214.f};
  378.  
  379. clip.x = 0.f;
  380. clip.y = 5778.f;
  381.  
  382. gSamusSprites.addClipSprite( clip );
  383.  
  384. clip = {0.f, 0.f, 213.f, 214.f};
  385.  
  386. clip.x = 0.f;
  387. clip.y = 5992.f;
  388.  
  389. gSamusSprites.addClipSprite( clip );
  390.  
  391. clip = {0.f, 0.f, 213.f, 214.f};
  392.  
  393. clip.x = 0.f;
  394. clip.y = 6206.f;
  395.  
  396. gSamusSprites.addClipSprite( clip );
  397.  
  398. clip = {0.f, 0.f, 213.f, 214.f};
  399.  
  400. clip.x = 0.f;
  401. clip.y = 6420.f;
  402.  
  403. gSamusSprites.addClipSprite( clip );
  404.  
  405. clip = {0.f, 0.f, 213.f, 214.f};
  406.  
  407. clip.x = 0.f;
  408. clip.y = 6634.f;
  409.  
  410. gSamusSprites.addClipSprite( clip );
  411.  
  412. clip = {0.f, 0.f, 213.f, 214.f};
  413.  
  414. clip.x = 0.f;
  415. clip.y = 6848.f;
  416.  
  417. gSamusSprites.addClipSprite( clip );
  418.  
  419. clip = {0.f, 0.f, 213.f, 214.f};
  420.  
  421. clip.x = 0.f;
  422. clip.y = 7062.f;
  423.  
  424. gSamusSprites.addClipSprite( clip );
  425.  
  426. clip = {0.f, 0.f, 213.f, 214.f};
  427.  
  428. clip.x = 0.f;
  429. clip.y = 7276.f;
  430.  
  431. gSamusSprites.addClipSprite( clip );
  432.  
  433. clip = {0.f, 0.f, 213.f, 214.f};
  434.  
  435. clip.x = 0.f;
  436. clip.y = 7490.f;
  437.  
  438. gSamusSprites.addClipSprite( clip );
  439.  
  440. clip = {0.f, 0.f, 213.f, 214.f};
  441.  
  442. clip.x = 0.f;
  443. clip.y = 7704.f;
  444.  
  445. gSamusSprites.addClipSprite( clip );
  446.  
  447. clip = {0.f, 0.f, 213.f, 214.f};
  448.  
  449. clip.x = 0.f;
  450. clip.y = 7918.f;
  451.  
  452. gSamusSprites.addClipSprite( clip );
  453.  
  454. clip = {0.f, 0.f, 213.f, 214.f};
  455.  
  456. clip.x = 0.f;
  457. clip.y = 8132.f;
  458.  
  459. gSamusSprites.addClipSprite( clip );
  460.  
  461. clip = {0.f, 0.f, 213.f, 214.f};
  462.  
  463. clip.x = 0.f;
  464. clip.y = 8346.f;
  465.  
  466. gSamusSprites.addClipSprite( clip );
  467.  
  468. clip = {0.f, 0.f, 213.f, 214.f};
  469.  
  470. clip.x = 0.f;
  471. clip.y = 8560.f;
  472.  
  473. gSamusSprites.addClipSprite( clip );
  474.  
  475. clipsLoaded = true;
  476. }
  477.  
  478. if(frame > 41){
  479. frame = 1;
  480. }
  481.  
  482. frame++;
  483.  
  484. if( !gSamusSprites.generateDataBuffer() )
  485. {
  486. printf( "Unable to clip sprite sheet!n" );
  487. return false;
  488. }
  489. return true;
  490. }
  491. bool loadGif1(){
  492. if(textureLoaded4 == false){
  493. if(!gSamusSprites1.loadTextureFromFile( "Textures/SamusGIF1.png" ) )
  494. {
  495. printf( "Unable to load texture!n" );
  496. return false;
  497. }
  498. textureLoaded4 = true;
  499. }
  500. if(clipsLoaded2 == false){
  501. clip = {0.f, 0.f, 384.f, 496.f};
  502.  
  503. clip.x = 0.f;
  504. clip.y = 0.f;
  505.  
  506. gSamusSprites1.addClipSprite( clip );
  507.  
  508. clip = {0.f, 0.f, 384.f, 496.f};
  509.  
  510. clip.x = 0.f;
  511. clip.y = 496.f;
  512.  
  513. gSamusSprites1.addClipSprite( clip );
  514.  
  515. clip = {0.f, 0.f, 384.f, 496.f};
  516.  
  517. clip.x = 0.f;
  518. clip.y = 992.f;
  519.  
  520. gSamusSprites1.addClipSprite( clip );
  521.  
  522. clip = {0.f, 0.f, 384.f, 496.f};
  523.  
  524. clip.x = 0.f;
  525. clip.y = 1488.f;
  526.  
  527. gSamusSprites1.addClipSprite( clip );
  528.  
  529. clip = {0.f, 0.f, 384.f, 496.f};
  530.  
  531. clip.x = 0.f;
  532. clip.y = 1984.f;
  533.  
  534. gSamusSprites1.addClipSprite( clip );
  535.  
  536. clip = {0.f, 0.f, 384.f, 496.f};
  537.  
  538. clip.x = 0.f;
  539. clip.y = 2480.f;
  540.  
  541. gSamusSprites1.addClipSprite( clip );
  542.  
  543. clip = {0.f, 0.f, 384.f, 496.f};
  544.  
  545. clip.x = 0.f;
  546. clip.y = 2976.f;
  547.  
  548. gSamusSprites1.addClipSprite( clip );
  549.  
  550. clip = {0.f, 0.f, 384.f, 496.f};
  551.  
  552. clip.x = 0.f;
  553. clip.y = 3472.f;
  554.  
  555. gSamusSprites1.addClipSprite( clip );
  556.  
  557. clip = {0.f, 0.f, 384.f, 496.f};
  558.  
  559. clip.x = 0.f;
  560. clip.y = 3968.f;
  561.  
  562. gSamusSprites1.addClipSprite( clip );
  563.  
  564. clip = {0.f, 0.f, 384.f, 496.f};
  565.  
  566. clip.x = 0.f;
  567. clip.y = 4960.f;
  568.  
  569. gSamusSprites1.addClipSprite( clip );
  570.  
  571. clip = {0.f, 0.f, 384.f, 496.f};
  572.  
  573. clip.x = 0.f;
  574. clip.y = 5456.f;
  575.  
  576. gSamusSprites1.addClipSprite( clip );
  577.  
  578. clipsLoaded2 = true;
  579. }
  580.  
  581. if(frame2 > 11){
  582. frame2 = 1;
  583. }
  584.  
  585. frame2++;
  586.  
  587. if( !gSamusSprites1.generateDataBuffer() )
  588. {
  589. printf( "Unable to clip sprite sheet!n" );
  590. return false;
  591. }
  592.  
  593. return true;
  594. }
  595. bool textureLoaded5 = false;
  596. bool clipsLoaded3 = false;
  597. bool textureLoaded6 = false;
  598. bool clipsLoaded4 = false;
  599. bool loadGif2(){
  600. if(textureLoaded5 == false){
  601. if(!gSamusSprites2.loadTextureFromFile( "Textures/SamusGIF2.png" ) )
  602. {
  603. printf( "Unable to load texture!n" );
  604. return false;
  605. }
  606. textureLoaded5 = true;
  607. }
  608. if(clipsLoaded3 == false){
  609. clip = {0.f, 0.f, 852.f, 474.f};
  610.  
  611. clip.x = 0.f;
  612. clip.y = 0.f;
  613.  
  614. gSamusSprites2.addClipSprite( clip );
  615.  
  616. clip = {0.f, 0.f, 852.f, 474.f};
  617.  
  618. clip.x = 0.f;
  619. clip.y = 474.f;
  620.  
  621. gSamusSprites2.addClipSprite( clip );
  622.  
  623. clip = {0.f, 0.f, 852.f, 474.f};
  624.  
  625. clip.x = 0.f;
  626. clip.y = 948.f;
  627.  
  628. gSamusSprites2.addClipSprite( clip );
  629.  
  630. clip = {0.f, 0.f, 852.f, 474.f};
  631.  
  632. clip.x = 0.f;
  633. clip.y = 1422.f;
  634.  
  635. gSamusSprites2.addClipSprite( clip );
  636.  
  637. clip = {0.f, 0.f, 852.f, 474.f};
  638.  
  639. clip.x = 0.f;
  640. clip.y = 1896.f;
  641.  
  642. gSamusSprites2.addClipSprite( clip );
  643.  
  644. clip = {0.f, 0.f, 852.f, 474.f};
  645.  
  646. clip.x = 0.f;
  647. clip.y = 2370.f;
  648.  
  649. gSamusSprites2.addClipSprite( clip );
  650.  
  651. clip = {0.f, 0.f, 852.f, 474.f};
  652.  
  653. clip.x = 0.f;
  654. clip.y = 2844.f;
  655.  
  656. gSamusSprites2.addClipSprite( clip );
  657.  
  658. clip = {0.f, 0.f, 852.f, 474.f};
  659.  
  660. clip.x = 0.f;
  661. clip.y = 3318.f;
  662.  
  663. gSamusSprites2.addClipSprite( clip );
  664.  
  665. clipsLoaded3 = true;
  666. }
  667. if( !gSamusSprites2.generateDataBuffer() )
  668. {
  669. printf( "Unable to clip sprite sheet!n" );
  670. return false;
  671. }
  672. if(textureLoaded6 == false){
  673. if(!gSamusSprites3.loadTextureFromFile( "Textures/SamusGIF3.png" ) )
  674. {
  675. printf( "Unable to load texture!n" );
  676. return false;
  677. }
  678. textureLoaded6 = true;
  679. }
  680. if(clipsLoaded4 == false){
  681. clip = {0.f, 0.f, 852.f, 474.f};
  682.  
  683. clip.x = 0.f;
  684. clip.y = 0.f;
  685.  
  686. gSamusSprites3.addClipSprite( clip );
  687.  
  688. clip = {0.f, 0.f, 852.f, 474.f};
  689.  
  690. clip.x = 0.f;
  691. clip.y = 474.f;
  692.  
  693. gSamusSprites3.addClipSprite( clip );
  694.  
  695. clip = {0.f, 0.f, 852.f, 474.f};
  696.  
  697. clip.x = 0.f;
  698. clip.y = 948.f;
  699.  
  700. gSamusSprites3.addClipSprite( clip );
  701.  
  702. clip = {0.f, 0.f, 852.f, 474.f};
  703.  
  704. clip.x = 0.f;
  705. clip.y = 1422.f;
  706.  
  707. gSamusSprites3.addClipSprite( clip );
  708.  
  709. clip = {0.f, 0.f, 852.f, 474.f};
  710.  
  711. clip.x = 0.f;
  712. clip.y = 1896.f;
  713.  
  714. gSamusSprites3.addClipSprite( clip );
  715.  
  716. clip = {0.f, 0.f, 852.f, 474.f};
  717.  
  718. clip.x = 0.f;
  719. clip.y = 2370.f;
  720.  
  721. gSamusSprites3.addClipSprite( clip );
  722.  
  723. clip = {0.f, 0.f, 852.f, 474.f};
  724.  
  725. clip.x = 0.f;
  726. clip.y = 2844.f;
  727.  
  728. gSamusSprites3.addClipSprite( clip );
  729.  
  730. clip = {0.f, 0.f, 852.f, 474.f};
  731.  
  732. clip.x = 0.f;
  733. clip.y = 3318.f;
  734.  
  735. gSamusSprites3.addClipSprite( clip );
  736.  
  737. clipsLoaded4 = true;
  738. }
  739.  
  740. if(frame3 > 9){
  741. frame3 = 1;
  742. }
  743.  
  744. frame3++;
  745.  
  746. if( !gSamusSprites3.generateDataBuffer() )
  747. {
  748. printf( "Unable to clip sprite sheet!n" );
  749. return false;
  750. }
  751.  
  752. return true;
  753. }
  754.  
  755. void update()
  756. {
  757.  
  758. }
  759.  
  760. void render()
  761. {
  762. //Clear color buffer
  763.  
  764. glClear( GL_COLOR_BUFFER_BIT );
  765.  
  766. glMatrixMode(GL_MODELVIEW);
  767. glPopMatrix();
  768.  
  769. glPushMatrix();
  770.  
  771. if(add == 0){
  772. if(zoom < 100){
  773. double const f_zoom = 1.0 - 0.01 * zoom;
  774. glMatrixMode(GL_PROJECTION);
  775. glLoadIdentity();
  776. glOrtho(leftzoom * f_zoom, rightzoom * f_zoom, bottomzoom * f_zoom, topzoom * f_zoom, -1.0, 1.0);
  777. glMatrixMode(GL_MODELVIEW);
  778. }
  779. if(zoom < -102){
  780. double const f_zoom = 1.0 + 0.01 * zoom;
  781. glMatrixMode(GL_PROJECTION);
  782. glLoadIdentity();
  783. glOrtho(leftzoom * f_zoom, rightzoom * f_zoom, bottomzoom * f_zoom, topzoom * f_zoom, -1.0, 1.0);
  784. glMatrixMode(GL_MODELVIEW);
  785. }
  786.  
  787. glTranslatef( -1080.f, -782.f, 0.f );
  788. gArrowSprites.renderSprite( 0 );
  789.  
  790. //Render top right arrow
  791. glTranslatef( +1080.f, +782.f, 0.f );
  792. glTranslatef( 1085.f, -120.f, 0.f );
  793. gArrowSprites.renderSprite( 1 );
  794.  
  795. //Render bottom left arrow
  796. glTranslatef( -1085.f, +120.f, 0.f );
  797. glTranslatef( 0.f, 885.f ,0.f );
  798. gArrowSprites.renderSprite( 2 );
  799.  
  800. glTranslatef(0.f, -885.f, 0.f);
  801. jSamusSprites.renderSprite( 0 );
  802.  
  803. glTranslatef( -620.f, -855.f, 0.f );
  804. glTranslatef( 620.f, 0.f , 0.f );
  805. gSamusSprites.renderSprite( frame );
  806.  
  807.  
  808. glTranslatef( +620.f, 0.f, 0.f );
  809. glTranslatef( -1500.f, 830.f , 0.f );
  810. gSamusSprites1.renderSprite( frame2 );
  811.  
  812. glTranslatef( +1500.f, -830.f, 0.f );
  813. glTranslatef( 200.f, 1570.f , 0.f );
  814. gSamusSprites3.renderSprite( frame3 );
  815. }
  816. if(add == 1){
  817. if(zoom < 100){
  818. double const f_zoom = 1.0 - 0.01 * zoom;
  819. glMatrixMode(GL_PROJECTION);
  820. glLoadIdentity();
  821. glOrtho(leftzoom * f_zoom, rightzoom * f_zoom, bottomzoom * f_zoom, topzoom * f_zoom, -1.0, 1.0);
  822. glMatrixMode(GL_MODELVIEW);
  823. }
  824. if(zoom < -102){
  825. double const f_zoom = 1.0 + 0.01 * zoom;
  826. glMatrixMode(GL_PROJECTION);
  827. glLoadIdentity();
  828. glOrtho(leftzoom * f_zoom, rightzoom * f_zoom, bottomzoom * f_zoom, topzoom * f_zoom, -1.0, 1.0);
  829. glMatrixMode(GL_MODELVIEW);
  830. }
  831.  
  832. glTranslatef( -1080.f, -782.f, 0.f );
  833. gArrowSprites.renderSprite( 3 );
  834.  
  835. glTranslatef( +1080.f, +782.f, 0.f );
  836. glTranslatef( 1085.f, -120.f, 0.f );
  837. gArrowSprites.renderSprite( 4 );
  838.  
  839. glTranslatef( -1085.f, +120.f, 0.f );
  840. glTranslatef( 0.f, 885.f ,0.f );
  841. gArrowSprites.renderSprite( 5 );
  842.  
  843. glTranslatef(0.f, -885.f, 0.f);
  844. jSamusSprites.renderSprite( 0 );
  845.  
  846. glTranslatef( -620.f, -855.f, 0.f );
  847. glTranslatef( 620.f, 0.f , 0.f );
  848. gSamusSprites.renderSprite( frame );
  849.  
  850. glTranslatef( +620.f, 0.f, 0.f );
  851. glTranslatef( -1500.f, 830.f , 0.f );
  852. gSamusSprites1.renderSprite( frame2 );
  853.  
  854. glTranslatef( +1500.f, -830.f, 0.f );
  855. glTranslatef( 200.f, 1570.f , 0.f );
  856. gSamusSprites2.renderSprite( frame3 );
  857.  
  858. }
  859.  
  860. glLoadIdentity();
  861.  
  862.  
  863. glutSwapBuffers();
  864.  
  865. }
  866. void handleKeys( unsigned char key, int x, int y )
  867. {
  868. //If the user presses q
  869. if( key == 'q' && add == 0 )
  870. {
  871. add++;
  872. }
  873. else if( key == 'q' && add == 1)
  874. {
  875. add--;
  876. }
  877. //Update the sprite rectangles so the texture change takes effect
  878. if( key == 27 ) {
  879. exit(0);
  880. }
  881. if(key == 'a') {
  882. gCameraX += 8.f;
  883. }
  884. else if (key == 'd') {
  885. gCameraX -= 8.f;
  886. }
  887. else if (key == 'w') {
  888. gCameraY += 8.f;
  889. }
  890. else if (key == 's') {
  891. gCameraY -= 8.f;
  892. }
  893. else if (key == '+' && zoom != 99) {
  894. zoom += 1;
  895. }
  896. else if (key == '-' && zoom != -101) {
  897. zoom -= 1;
  898. }
  899. //Take saved matrix off the stack and reset it
  900. glMatrixMode( GL_MODELVIEW );
  901. glPopMatrix();
  902. glLoadIdentity();
  903.  
  904. //Move camera to position
  905. glTranslatef( gCameraX, gCameraY, gCameraZ );
  906.  
  907. //Save default matrix again with camera translation
  908. glPushMatrix();
  909. }
  910.  
  911. #include "LUtil.h"
  912.  
  913. void runMainLoop( int val );
  914.  
  915. void runGifLoop( int val2 );
  916.  
  917. void runGifLoop2( int val3 );
  918.  
  919. int main( int argc, char* args[] )
  920. {
  921.  
  922. glutInit( &argc, args );
  923.  
  924. glutInitContextVersion( 2, 1 );
  925.  
  926. glutInitDisplayMode( GLUT_DOUBLE );
  927. glutInitWindowSize( SCREEN_WIDTH, SCREEN_HEIGHT );
  928. glutCreateWindow( "Samus" );
  929.  
  930. if( !initGL() )
  931. {
  932. printf( "Unable to initialize graphics library!n" );
  933. return 1;
  934. }
  935.  
  936. if( !loadMedia() )
  937. {
  938. printf( "Unable to load media!n" );
  939. return 2;
  940. }
  941.  
  942. glutKeyboardFunc( handleKeys );
  943. glutDisplayFunc( render );
  944.  
  945. glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, 0 );
  946. glutTimerFunc( 1000 / SCREEN_FPS, runGifLoop, 0 );
  947. glutTimerFunc( 1000 / SCREEN_FPS, runGifLoop2, 0);
  948. glutMainLoop();
  949.  
  950. return 0;
  951. }
  952.  
  953. void runMainLoop( int val )
  954. {
  955. update();
  956. render();
  957.  
  958. glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, val );
  959. }
  960.  
  961. void runGifLoop( int val2 )
  962. {
  963.  
  964. loadGif();
  965. glutTimerFunc( 5500 / SCREEN_FPS, runGifLoop, val2 );
  966.  
  967. }
  968.  
  969. void runGifLoop2( int val3 )
  970. {
  971.  
  972. loadGif1();
  973. loadGif2();
  974.  
  975. glutTimerFunc( 8000 / SCREEN_FPS, runGifLoop2, val3 );
  976.  
  977. }
Add Comment
Please, Sign In to add comment