level_select.dd 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. # Level select
  2. #
  3. # Displays buttons for each level.
  4. # Has two next/previous page buttons, each moving to the
  5. # next/previous page of levels.
  6. # Each page has different visuals.
  7. # There's also a back button, that goes back to the title screen
  8. #
  9. (class dd_world_level_select dd_world
  10. (group
  11. # buttons
  12. (def dd_meshTexture mesh)
  13. (def (array dd_meshColour 9) buttonMesh)
  14. (def (array dd_matrix 9) matrix)
  15. # constants
  16. (def int BUTTON_STAGE_START)
  17. (def int BUTTON_STAGE_END)
  18. (def int BUTTON_PAGE_NEXT)
  19. (def int BUTTON_PAGE_PREVIOUS)
  20. (def int BUTTON_BACK)
  21. # selection is one of the buttons
  22. (def int selection)
  23. # pages and visuals
  24. (def int page)
  25. (def int previousPage)
  26. (def (array float 9) pageColour)
  27. # animations
  28. (def float selectionAnimation)
  29. (def float transitionAnimation)
  30. (def int transitionAnimationType)
  31. (def int nextWorld)
  32. # scale to fit all screen sizes
  33. (def float scale)
  34. # create
  35. (function create (group)
  36. (group
  37. # constants
  38. (= this.BUTTON_STAGE_START 0)
  39. (= this.BUTTON_STAGE_END 5)
  40. (= this.BUTTON_PAGE_NEXT 6)
  41. (= this.BUTTON_BACK 7)
  42. (= this.BUTTON_PAGE_PREVIOUS 8)
  43. (dd_meshTexture_create this.mesh)
  44. (this.mesh.set_primitive DD_PRIMITIVE_RECTANGLE)
  45. (this.mesh.set_colour 0.5 0.5 0.7)
  46. (for (def int i this.BUTTON_STAGE_START) (<= i this.BUTTON_STAGE_END) (= i (+ i 1))
  47. (group
  48. (dd_matrix_identity this.matrix[i])
  49. (dd_matrix_translates this.matrix[i] (+ -1.5 (* (% i 3) 1.5)) (+ (/ 1.5 2) (* (/ i 3) -1.5)) 0)
  50. (dd_meshColour_create this.buttonMesh[i])
  51. )
  52. )
  53. (this.buttonMesh[(+ this.BUTTON_STAGE_START 0)].load "number_1.ply")
  54. (this.buttonMesh[(+ this.BUTTON_STAGE_START 1)].load "number_2.ply")
  55. (this.buttonMesh[(+ this.BUTTON_STAGE_START 2)].load "number_3.ply")
  56. (this.buttonMesh[(+ this.BUTTON_STAGE_START 3)].load "number_4.ply")
  57. (this.buttonMesh[(+ this.BUTTON_STAGE_START 4)].load "number_5.ply")
  58. (this.buttonMesh[(+ this.BUTTON_STAGE_START 5)].load "number_6.ply")
  59. # next page button
  60. (dd_matrix_identity this.matrix[this.BUTTON_PAGE_NEXT])
  61. (dd_matrix_rotate_y this.matrix[this.BUTTON_PAGE_NEXT] (dd_math_dec2rad 180))
  62. (dd_matrix_translates this.matrix[this.BUTTON_PAGE_NEXT] 3 0 0)
  63. (dd_meshColour_create this.buttonMesh[this.BUTTON_PAGE_NEXT])
  64. (this.buttonMesh[this.BUTTON_PAGE_NEXT].load "arrow.ply")
  65. # back button
  66. (dd_matrix_identity this.matrix[this.BUTTON_BACK])
  67. (dd_matrix_translates this.matrix[this.BUTTON_BACK] -3 -1.5 0)
  68. (dd_meshColour_create this.buttonMesh[this.BUTTON_BACK])
  69. (this.buttonMesh[this.BUTTON_BACK].load "arrow_back.ply")
  70. # previous page button
  71. (dd_matrix_identity this.matrix[this.BUTTON_PAGE_PREVIOUS])
  72. (dd_matrix_translates this.matrix[this.BUTTON_PAGE_PREVIOUS] -3 0 0)
  73. (dd_meshColour_create this.buttonMesh[this.BUTTON_PAGE_PREVIOUS])
  74. (this.buttonMesh[this.BUTTON_PAGE_PREVIOUS].load "arrow.ply")
  75. (= this.selection 0)
  76. (= this.selectionAnimation 0)
  77. (= this.transitionAnimation 0)
  78. (= this.transitionAnimationType 0)
  79. (= this.page 0)
  80. (= this.previousPage 0)
  81. (= this.pageColour[0] 0.1)
  82. (= this.pageColour[1] 0.1)
  83. (= this.pageColour[2] 0.1)
  84. (= this.pageColour[3] 0.6)
  85. (= this.pageColour[4] 0.2)
  86. (= this.pageColour[5] 0.2)
  87. (= this.pageColour[6] 0.2)
  88. (= this.pageColour[7] 0.8)
  89. (= this.pageColour[8] 0.2)
  90. (dd_clearColour this.pageColour[0] this.pageColour[1] this.pageColour[2] 1)
  91. (= this.scale 1)
  92. )
  93. )
  94. (function resize (group)
  95. (group
  96. (def float height)
  97. (= height (/ (dd_screen_height_get 10) 10))
  98. (def float width)
  99. (= width (/ (dd_screen_width_get 10) 16))
  100. (if (< width height)
  101. (= this.scale width)
  102. # else
  103. (= this.scale height)
  104. )
  105. )
  106. )
  107. (function update (group)
  108. (group
  109. (= this.selectionAnimation (+ this.selectionAnimation 1))
  110. (if (< this.transitionAnimation 1)
  111. (group
  112. # world open animation
  113. (if (== this.transitionAnimationType 0)
  114. (group
  115. (= this.transitionAnimation (+ this.transitionAnimation 0.1))
  116. )
  117. # world close animation
  118. (== this.transitionAnimationType 1)
  119. (group
  120. (= this.transitionAnimation (+ this.transitionAnimation 0.1))
  121. (if (>= this.transitionAnimation 1)
  122. (if (== this.nextWorld 0)
  123. (dd_world_set dd_world_menu)
  124. # else
  125. (group
  126. (def int stageIndex (+ (* this.page 6) this.selection))
  127. (dd_world_set dd_world_game)
  128. (def (ref dd_world_game) w cworld)
  129. (w.initStage stageIndex)
  130. )
  131. )
  132. )
  133. )
  134. # page transition
  135. (== this.transitionAnimationType 2)
  136. (group
  137. (= this.transitionAnimation (+ this.transitionAnimation 0.1))
  138. # linearly transform background colour
  139. (dd_clearColour
  140. (+ this.pageColour[(+ (* this.previousPage 3) 0)] (* this.transitionAnimation (- this.pageColour[(+ (* this.page 3) 0)] this.pageColour[(+ (* this.previousPage 3) 0)])))
  141. (+ this.pageColour[(+ (* this.previousPage 3) 1)] (* this.transitionAnimation (- this.pageColour[(+ (* this.page 3) 1)] this.pageColour[(+ (* this.previousPage 3) 1)])))
  142. (+ this.pageColour[(+ (* this.previousPage 3) 2)] (* this.transitionAnimation (- this.pageColour[(+ (* this.page 3) 2)] this.pageColour[(+ (* this.previousPage 3) 2)])))
  143. 1)
  144. )
  145. )
  146. )
  147. )
  148. )
  149. )
  150. (function draw (group)
  151. (group
  152. (glTranslatef 0 0 -5)
  153. (for (def int i 0) (< i 9) (= i (+ i 1))
  154. (group
  155. (glPushMatrix)
  156. (glScalef this.scale this.scale this.scale)
  157. (glMultMatrixf this.matrix[i])
  158. (if (== this.selection i) (glRotatef this.selectionAnimation 0 1 0))
  159. # opening world
  160. (if (== this.transitionAnimationType 0)
  161. (glScalef this.transitionAnimation this.transitionAnimation this.transitionAnimation)
  162. # closing world
  163. (== this.transitionAnimationType 1)
  164. (glScalef (- 1 this.transitionAnimation) (- 1 this.transitionAnimation) (- 1 this.transitionAnimation))
  165. (== this.transitionAnimationType 2)
  166. (group
  167. (if (&& (>= i this.BUTTON_STAGE_START) (<= i this.BUTTON_STAGE_END))
  168. (group
  169. (if (< this.transitionAnimation 0.5)
  170. (glScalef (+ (* this.transitionAnimation -2) 1)(+ (* this.transitionAnimation -2) 1)(+ (* this.transitionAnimation -2) 1))
  171. # else
  172. (glScalef (* (- this.transitionAnimation 0.5) 2)(* (- this.transitionAnimation 0.5) 2)(* (- this.transitionAnimation 0.5) 2))
  173. )
  174. )
  175. )
  176. )
  177. )
  178. (this.buttonMesh[i].draw)
  179. (glPopMatrix)
  180. )
  181. )
  182. )
  183. )
  184. (function key_input (group char key)
  185. (group
  186. # next selection
  187. (if (== key 'd')
  188. (group
  189. (= this.selection (+ this.selection 1))
  190. )
  191. # previous selection
  192. (== key 'a')
  193. (group
  194. (= this.selection (- this.selection 1))
  195. )
  196. # confirm
  197. (== key ' ')
  198. (group
  199. # next page
  200. (if (== this.selection this.BUTTON_PAGE_NEXT)
  201. (group
  202. (if (< this.page 2)
  203. (group
  204. (= this.previousPage this.page)
  205. (= this.page (+ this.page 1))
  206. (= this.transitionAnimation 0)
  207. (= this.transitionAnimationType 2)
  208. )
  209. )
  210. )
  211. # previous page
  212. (== this.selection this.BUTTON_PAGE_PREVIOUS)
  213. (group
  214. (if (> this.page 0)
  215. (group
  216. (= this.previousPage this.page)
  217. (= this.page (- this.page 1))
  218. (= this.transitionAnimation 0)
  219. (= this.transitionAnimationType 2)
  220. )
  221. )
  222. )
  223. # back button
  224. (== this.selection this.BUTTON_BACK)
  225. (group
  226. (= this.transitionAnimation 0)
  227. (= this.transitionAnimationType 1)
  228. (= this.nextWorld 0)
  229. )
  230. # stage button
  231. (&& (>= this.selection this.BUTTON_STAGE_START) (<= this.selection this.BUTTON_STAGE_END))
  232. (group
  233. (= this.transitionAnimation 0)
  234. (= this.transitionAnimationType 1)
  235. (= this.nextWorld 1)
  236. )
  237. )
  238. )
  239. )
  240. (if (< this.selection 0) (= this.selection (+ this.selection 9)))
  241. (if (>= this.selection 9) (= this.selection (- this.selection 9)))
  242. )
  243. )
  244. )
  245. ) ## level_select