cardMenu.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "cardMenu.h"
  4. #include "GL/glut.h"
  5. #include "cardCharSelect.h"
  6. #include "string3d.h"
  7. CardMenu::CardMenu()
  8. {
  9. /* Meshes */
  10. brick1.load("obj/brick_00.ply", 0);
  11. brick2.load("obj/brick_01.ply", 1);
  12. ball .load("obj/ball.ply" , 0);
  13. stage .load("obj/stage_01.ply", 0);
  14. //Translations
  15. brick1.translateSet(-3.0f, -1.5f, 0.0f);
  16. brick2.translateSet( 3.0f, -1.5f, 0.0f);
  17. ball .translateSet( 0.0f, brick1.y() +brick1.pbound.y +ball.pbound.y, 0.0f);
  18. stage .translateSet( 0.0f, brick1.y() +brick1.nbound.y -1.0f, 0.0f);
  19. stage.scaleSet(1.5f, 1.5f, 1.5f);
  20. //Logo
  21. logoStyle.setColorFront(0.133f, 0.133f, 0.133f);
  22. logoStyle.setColorBack (0.188f, 0.292f, 0.530f);
  23. logoStyle.setAlign(1);
  24. matLogo.translateSet(0.0f, 2.5f, 4.0f);
  25. matLogo.scaleSet(1.3f, 1.3f, 1.3f);
  26. logo = (char*) "dargite3d";
  27. //Text choices
  28. matText[0].translateSet(0.0f, 1.5f -(1.0f *0.9f), 4.0f);
  29. matText[1].translateSet(0.0f, 1.5f -(2.0f *0.9f), 4.0f);
  30. // matText[2].translateSet(0.0f, 1.0f -(2.0f *0.9f), 4.0f);
  31. text[0] = (char*) "start";
  32. //text[1] = (char*) "survival";
  33. text[1] = (char*) "exit";
  34. /* Initial Rotation (rotates the background meshes) */
  35. rotation = 20.0f;
  36. //Init selection
  37. selection = 0;
  38. //Selection font
  39. font.setColorFront(0.9f, 0.327f, 0.689f);
  40. font.setColorBack (0.26f, 0.121f, 0.256f);
  41. font.setAlign(1);
  42. }
  43. void CardMenu::input(unsigned char key, bool pressed)
  44. {
  45. //Accept input only if animation is not running
  46. if (!anim.isRunning())
  47. //Act according to key
  48. switch (key)
  49. {
  50. //Next selection (if no more selections, select first one)
  51. case 's':
  52. if (pressed && ++selection > 1)
  53. selection = 0;
  54. break;
  55. //Previous selection (if no previous selection, select last one)
  56. case 'w':
  57. if (pressed && --selection < 0)
  58. selection = 1;
  59. break;
  60. //Space key
  61. case '\040':
  62. //Key released
  63. if (!pressed)
  64. //Start animation
  65. anim.startFromStart();
  66. }
  67. }
  68. void CardMenu::update()
  69. {
  70. //Animation changed
  71. if (anim.update())
  72. //Animation reached end
  73. if (anim.isAtEnd())
  74. //Act accoring to current selection
  75. switch (selection)
  76. {
  77. //Start normal mode
  78. case 0:
  79. //Delete menu
  80. delete card;
  81. //Start character select screen
  82. card = new CardCharSelect(0);
  83. return;
  84. //Start survival
  85. /*case 1:
  86. //Delete menu
  87. delete card;
  88. //Start character select screen
  89. card = new CardCharSelect(1);
  90. return;*/
  91. //Exit
  92. case 1: exit(0);
  93. }
  94. //Keep rotating
  95. rotation += 0.2f;
  96. if (rotation > 360.0f)
  97. rotation -= 360.0f;
  98. }
  99. void CardMenu::draw()
  100. {
  101. //Card's animation
  102. Card::draw();
  103. //Camera translation data
  104. glTranslatef(0.0f, -1.0f, -10.0f);
  105. //Draw text choices
  106. int i;
  107. for (i = 0; i < 2; i++)
  108. {
  109. //Selected text
  110. if (selection == i)
  111. {
  112. //Create quake effect
  113. //Seperate X and Y
  114. float tempX = ((rand() +1) %100) /1000.0f;
  115. float tempY = ((rand() +1) %100) /1000.0f;
  116. //Add effect to matrix
  117. matText[i].translateAdd(tempX, tempY, 0.0f);
  118. //Draw choice
  119. matText[i].push_apply();
  120. font.draw(text[i]);
  121. glPopMatrix();
  122. //Remove effect from matrix
  123. matText[i].translateAdd(-tempX, -tempY, 0.0f);
  124. }
  125. //Other text choices
  126. else
  127. {
  128. //Simply draw them
  129. matText[i].push_apply();
  130. font.draw(text[i]);
  131. glPopMatrix();
  132. }
  133. }
  134. //Draw logo
  135. matLogo.push_apply();
  136. logoStyle.draw(logo);
  137. glPopMatrix();
  138. //Rotate camera
  139. glRotatef(rotation, 0.0f, 1.0f, 0.0f);
  140. glRotatef(20.0f, 1.0f, 0.0f, 0.0f);
  141. //Draw bricks, ball and stage
  142. stage.draw();
  143. brick1.draw();
  144. brick2.draw();
  145. ball.draw();
  146. }