menu.dd 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. # main menu
  2. (class dd_world_menu dd_world
  3. (group
  4. # 3 buttons
  5. (def (array dd_meshTexture 3) obj)
  6. (def int tileCount)
  7. (def (array dd_matrix 3) tile)
  8. (def int selection)
  9. # open/close animation
  10. (def float shrinkAnimation)
  11. (def int opening)
  12. (def int fromIntro)
  13. # scale to fit all screen sizes
  14. (def float scale)
  15. (def dd_meshColour selectionMesh)
  16. (def dd_matrix selectionMatrix)
  17. (def dd_matrix unselectedMatrix)
  18. # game's title
  19. (def dd_meshColour title)
  20. (def float titleAnimation)
  21. (function create (group)
  22. (group
  23. (dd_clearColour 0.1 0.1 0.1 1)
  24. (for (def int i 0) (< i 3) (= i (+ i 1))
  25. (group
  26. (dd_meshTexture_create this.obj[i])
  27. )
  28. )
  29. (this.obj[0].load "menu_game.ply")
  30. (this.obj[1].load "menu_cog.ply")
  31. (this.obj[1].loadTexture "menu_cog.bmp")
  32. (this.obj[2].load "menu_exit.ply")
  33. (= this.tileCount 3)
  34. (for (def int i 0) (< i this.tileCount) (= i (+ i 1))
  35. (group
  36. (dd_matrix_identity this.tile[i])
  37. (dd_matrix_translates this.tile[i] 0 (- 2 (* 2 i)) 0)
  38. )
  39. )
  40. #(dd_matrix_translates this.tile[0] 0 (/ (dd_screen_height_get 10) 2) 0)
  41. #(dd_matrix_translates this.tile[0] (/ (dd_screen_width_get 10) 2) 0 0)
  42. (= this.selection 0)
  43. (= this.shrinkAnimation 0)
  44. (= this.opening 1)
  45. (= this.fromIntro 0)
  46. (= this.scale 1)
  47. (dd_meshColour_create this.selectionMesh)
  48. (this.selectionMesh.load "selection.ply")
  49. (dd_matrix_identity this.selectionMatrix)
  50. (dd_matrix_identity this.unselectedMatrix)
  51. # game's title
  52. (dd_meshColour_create this.title)
  53. (this.title.load "title.ply")
  54. (= this.titleAnimation 0)
  55. )
  56. )
  57. (function resize (group)
  58. (group
  59. #(dd_matrix_translates this.tile[0] 0 (/ (dd_screen_height_get 10) 2) 0)
  60. #(dd_matrix_translates this.tile[1] (/ (dd_screen_width_get 10) 2) 0 0)
  61. (def float height)
  62. (= height (/ (dd_screen_height_get 10) 10)) # last number is the height of the object
  63. (def float width)
  64. (= width (/ (dd_screen_width_get 10) 4)) # last number is the width of the object
  65. (if (< width height)
  66. (= this.scale width)
  67. # else
  68. (= this.scale height)
  69. )
  70. )
  71. )
  72. # update - add rotation
  73. (function update (group)
  74. (group
  75. (for (def int i 0) (< i 3) (= i (+ i 1))
  76. (group
  77. (if (== i this.selection)
  78. (group
  79. (dd_matrix_rotate_y this.tile[i] (dd_math_dec2rad 1))
  80. )
  81. (group
  82. (dd_matrix_approach_rs this.tile[i] this.unselectedMatrix 0.3)
  83. )
  84. )
  85. )
  86. )
  87. # selection is rotating constantly
  88. (dd_matrix_rotate_y this.selectionMatrix (dd_math_dec2rad 5))
  89. (dd_matrix_translates this.selectionMatrix
  90. 0
  91. (+ (dd_matrix_y this.selectionMatrix) (* (- (dd_matrix_y this.tile[this.selection]) (dd_matrix_y this.selectionMatrix)) 0.3))
  92. 0
  93. )
  94. # opening animation
  95. (if (&& (< this.shrinkAnimation 1) this.opening)
  96. (group
  97. (= this.shrinkAnimation (+ this.shrinkAnimation (dd_math_maxf (* (- 1 this.shrinkAnimation) 0.3) 0.05)))
  98. (if (> this.shrinkAnimation 1) (= this.shrinkAnimation 1))
  99. (if this.fromIntro
  100. (dd_clearColour (* this.shrinkAnimation 0.1) (* this.shrinkAnimation 0.1) (* this.shrinkAnimation 0.1) 1)
  101. (dd_clearColour 0.1 0.1 0.1 1)
  102. )
  103. )
  104. # closing animation
  105. (&& (> this.shrinkAnimation 0) (== this.opening 0))
  106. (group
  107. (= this.shrinkAnimation (- this.shrinkAnimation (dd_math_maxf (* (- 1 this.shrinkAnimation) 0.3) 0.05)))
  108. # make selection
  109. (if (<= this.shrinkAnimation 0)
  110. (group
  111. (if (== this.selection 0)
  112. (dd_world_set dd_world_level_select)
  113. (== this.selection 2)
  114. (= dd_flag_exit 1) # exit game
  115. )
  116. )
  117. )
  118. )
  119. ) # opening/closing animation
  120. (= this.titleAnimation (+ this.titleAnimation 0.001))
  121. (if (> this.titleAnimation 1) (= this.titleAnimation (- this.titleAnimation 1)))
  122. )
  123. )
  124. # draw
  125. # zoom-out so the world is visible
  126. # rotate the world
  127. # draw the cube
  128. (function draw (group)
  129. (group
  130. (glTranslatef 0 0 -10)
  131. (for (def int i 0) (< i this.tileCount) (= i (+ i 1))
  132. (group
  133. (glPushMatrix)
  134. (glScalef this.scale this.scale this.scale)
  135. (if (== this.selection i)
  136. (group
  137. #(glTranslatef 0 0 0.5)
  138. (glPushMatrix)
  139. (glMultMatrixf this.selectionMatrix)
  140. (this.selectionMesh.draw)
  141. (glPopMatrix)
  142. #(glScalef 1.1 1.1 1.1)
  143. )
  144. )
  145. (glMultMatrixf this.tile[i])
  146. (glScalef this.shrinkAnimation this.shrinkAnimation this.shrinkAnimation)
  147. (this.obj[i].draw)
  148. (glPopMatrix)
  149. )
  150. )
  151. (glTranslatef 0 0 -10)
  152. (glScalef 5 5 5)
  153. (if (< this.titleAnimation 0.5)
  154. (glScalef (+ 1 this.titleAnimation) (+ 1 this.titleAnimation) (+ 1 this.titleAnimation))
  155. # else
  156. (glScalef (- 2 this.titleAnimation) (- 2 this.titleAnimation) (- 2 this.titleAnimation))
  157. )
  158. (this.title.draw)
  159. )
  160. )
  161. (function key_input (group char key)
  162. (group
  163. (if (== key 's')
  164. (group
  165. (= this.selection (+ this.selection 1))
  166. (if (>= this.selection this.tileCount) (= this.selection 0))
  167. )
  168. (== key 'w')
  169. (group
  170. (= this.selection (- this.selection 1))
  171. (if (< this.selection 0) (= this.selection (- this.tileCount 1)))
  172. )
  173. (== key ' ')
  174. (group
  175. (= this.opening 0)
  176. )
  177. )
  178. )
  179. )
  180. (function clean (group)
  181. (group
  182. (this.obj[0].clean)
  183. (this.obj[1].clean)
  184. (this.obj[2].clean)
  185. (dd_world_clean this)
  186. )
  187. )
  188. )
  189. ) # main world