custom_game_menu.dd 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. (include "custom_game_menu.ddh")
  2. (include "game.ddh")
  3. (include "menu.ddh")
  4. (def int numberOfPlayers)
  5. (def int startingPlayer)
  6. (def int guide)
  7. (class_function world_custom_game_menu void create (group)
  8. (group
  9. (= this.isMovingToNewWorld 0)
  10. # background
  11. (= this.bg_rotation 0)
  12. (this.bg.load (asset "assets/stage_2.asset" DD_PLY))
  13. # font
  14. (this.font.setAlign DD_STRING3D_ALIGN_CENTER)
  15. (this.font.setColorFront 0.8 0.8 0.8)
  16. (this.font.setColorBack 0.3 0.3 0.3)
  17. # buttons
  18. (= this.buttonTotal 7)
  19. (this.button[0].mesh.load (asset "assets/button_minus.asset" DD_PLY))
  20. (this.button[0].setSize 1 1)
  21. (this.button[0].setProportionalPosition 0.50 0.8)
  22. (this.button[0].setProportionalWidth 0.2)
  23. (this.button[0].setProportionalSize 0.7)
  24. (this.button[1].mesh.load (asset "assets/button_plus.asset" DD_PLY))
  25. (this.button[1].setSize 1 1)
  26. (this.button[1].setProportionalPosition 0.8 0.8)
  27. (this.button[1].setProportionalWidth 0.2)
  28. (this.button[1].setProportionalSize 0.7)
  29. (this.button[2].mesh.load (asset "assets/button_minus.asset" DD_PLY))
  30. (this.button[2].setSize 1 1)
  31. (this.button[2].setProportionalPosition 0.5 0.575)
  32. (this.button[2].setProportionalWidth 0.2)
  33. (this.button[2].setProportionalSize 0.7)
  34. (this.button[3].mesh.load (asset "assets/button_plus.asset" DD_PLY))
  35. (this.button[3].setSize 1 1)
  36. (this.button[3].setProportionalPosition 0.8 0.575)
  37. (this.button[3].setProportionalWidth 0.2)
  38. (this.button[3].setProportionalSize 0.7)
  39. (this.button[4].mesh.load (asset "assets/button_toggle.asset" DD_PLY))
  40. (this.button[4].setSize 1 1)
  41. (this.button[4].setProportionalPosition 0.5 0.35)
  42. (this.button[4].setProportionalWidth 0.2)
  43. (this.button[4].setProportionalSize 0.7)
  44. (this.button[5].mesh.load (asset "assets/button.asset" DD_PLY))
  45. (this.button[5].setSize 1 1)
  46. (this.button[5].setProportionalPosition 0.12 0.15)
  47. (this.button[5].setProportionalWidth 0.2)
  48. (this.button[6].mesh.load (asset "assets/button.asset" DD_PLY))
  49. (this.button[6].setSize 1 1)
  50. (this.button[6].setProportionalPosition 0.88 0.15)
  51. (this.button[6].setProportionalWidth 0.2)
  52. # number of players
  53. (this.buttonPlayerNumber.setSize 1 1)
  54. (this.buttonPlayerNumber.setProportionalPosition 0.25 0.8)
  55. (this.buttonPlayerNumber.setProportionalWidth 0.2)
  56. (this.buttonPlayerNumber.setProportionalSize 1.0)
  57. (this.buttonPlayerNumberValue.setSize 1 1)
  58. (this.buttonPlayerNumberValue.setProportionalPosition 0.65 0.8)
  59. (this.buttonPlayerNumberValue.setProportionalWidth 0.2)
  60. (this.buttonPlayerNumberValue.setProportionalSize 1.0)
  61. # starting player
  62. (this.buttonStartingPlayer.setSize 1 1)
  63. (this.buttonStartingPlayer.setProportionalPosition 0.25 0.575)
  64. (this.buttonStartingPlayer.setProportionalWidth 0.2)
  65. (this.buttonStartingPlayer.setProportionalSize 1.0)
  66. (this.buttonStartingPlayerValue.setSize 1 1)
  67. (this.buttonStartingPlayerValue.setProportionalPosition 0.65 0.575)
  68. (this.buttonStartingPlayerValue.setProportionalWidth 0.2)
  69. (this.buttonStartingPlayerValue.setProportionalSize 1.0)
  70. # text display
  71. (this.textButton.setSize 1 1)
  72. (this.textButton.setProportionalPosition 0.5 0.15)
  73. (this.textButton.setProportionalWidth 0.15)
  74. (= this.selection 0)
  75. (= this.selectionClick -1)
  76. (= this.isMovingToNewWorld 0)
  77. (= numberOfPlayers 3)
  78. (= startingPlayer -1)
  79. (= guide 0)
  80. # shader for buttons
  81. (this.buttonProgram.setVertexShader
  82. (multistring
  83. "AVDL_IN vec4 position;\n"
  84. "AVDL_IN vec3 colour;\n"
  85. "uniform mat4 matrix;\n"
  86. "uniform vec3 tint;\n"
  87. "AVDL_OUT vec4 outColour;\n"
  88. "void main() {\n"
  89. " vec4 pos = matrix *position;\n"
  90. " gl_Position = pos;\n"
  91. " outColour = vec4(colour.rgb *tint.rgb, 1.0);\n"
  92. "}\n"
  93. )
  94. )
  95. (this.buttonProgram.setFragmentShader
  96. (multistring
  97. "AVDL_IN vec4 outColour;\n"
  98. "void main() {\n"
  99. " avdl_frag_color = outColour;\n"
  100. "}\n"
  101. )
  102. )
  103. # button colours
  104. (= this.buttonClickCol[0] 0.389)
  105. (= this.buttonClickCol[1] 0.055)
  106. (= this.buttonClickCol[2] 0.682)
  107. (= this.buttonActiveCol[0] 0.916)
  108. (= this.buttonActiveCol[1] 0.516)
  109. (= this.buttonActiveCol[2] 0.074)
  110. (= this.buttonInactiveCol[0] 0.694)
  111. (= this.buttonInactiveCol[1] 0.137)
  112. (= this.buttonInactiveCol[2] 0.137)
  113. )
  114. )
  115. (class_function world_custom_game_menu void onload (group)
  116. (group
  117. )
  118. )
  119. (class_function world_custom_game_menu void resize (group)
  120. (group
  121. (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
  122. (this.button[i].resize)
  123. )
  124. (this.buttonPlayerNumber.resize)
  125. (this.buttonPlayerNumberValue.resize)
  126. (this.buttonStartingPlayer.resize)
  127. (this.buttonStartingPlayerValue.resize)
  128. (this.textButton.resize)
  129. )
  130. )
  131. (class_function world_custom_game_menu void update (group)
  132. (group
  133. # constant background rotation
  134. (= this.bg_rotation (+ this.bg_rotation 0.01))
  135. (if (>= this.bg_rotation 360)
  136. (= this.bg_rotation (- this.bg_rotation 360))
  137. )
  138. # check if mouse is hovering over a button
  139. (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
  140. (group
  141. (if (this.button[i].hasMouseCollided)
  142. (group
  143. (= this.selection i)
  144. )
  145. )
  146. (this.button[i].update (== this.selection i) (== this.selectionClick i))
  147. )
  148. )
  149. )
  150. ) # update
  151. (class_function world_custom_game_menu void draw (group)
  152. (group
  153. # draw background
  154. (dd_matrix_push)
  155. (dd_translatef 0 -2 -3)
  156. (dd_rotatef (+ -80 this.bg_rotation) 0 1 0)
  157. (dd_rotatef 25 -1 0 0)
  158. (this.bg.draw)
  159. (dd_matrix_pop)
  160. # clear depth
  161. (glClear GL_DEPTH_BUFFER_BIT)
  162. # draw number of players
  163. (dd_matrix_push)
  164. (this.buttonPlayerNumber.applyTransform)
  165. (this.buttonPlayerNumber.applyMatrixTransform)
  166. (dd_translatef 0 0 0.1)
  167. (dd_scalef 0.2 0.2 0.2)
  168. (this.font.draw "number of players")
  169. (dd_matrix_pop)
  170. (dd_matrix_push)
  171. (this.buttonPlayerNumberValue.applyTransform)
  172. (this.buttonPlayerNumberValue.applyMatrixTransform)
  173. (dd_translatef 0 0 0.1)
  174. (dd_scalef 0.2 0.2 0.2)
  175. (this.font.drawInt numberOfPlayers)
  176. (dd_matrix_pop)
  177. # draw starting player
  178. (dd_matrix_push)
  179. (this.buttonStartingPlayer.applyTransform)
  180. (this.buttonStartingPlayer.applyMatrixTransform)
  181. (dd_translatef 0 0 0.1)
  182. (dd_scalef 0.2 0.2 0.2)
  183. (this.font.draw "starting player")
  184. (dd_matrix_pop)
  185. (dd_matrix_push)
  186. (this.buttonStartingPlayerValue.applyTransform)
  187. (this.buttonStartingPlayerValue.applyMatrixTransform)
  188. (dd_translatef 0 0 0.1)
  189. (dd_scalef 0.2 0.2 0.2)
  190. (if (== startingPlayer -1)
  191. (this.font.draw "random")
  192. (== startingPlayer 0)
  193. (this.font.draw "you")
  194. (group
  195. (dd_translatef -0.7 0 0)
  196. (this.font.draw "AI")
  197. (dd_translatef 1.4 0 0)
  198. (this.font.drawInt startingPlayer)
  199. )
  200. )
  201. (dd_matrix_pop)
  202. # draw buttons
  203. (this.buttonProgram.useProgram)
  204. (def int colLoc)
  205. (= colLoc (avdl_getUniformLocation this.buttonProgram "tint"))
  206. (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
  207. (group
  208. (dd_matrix_push)
  209. # change the shader colour when clicked
  210. (if (> this.button[i].idleCol 1.0)
  211. (avdl_setUniform3f colLoc
  212. (dd_math_ease_linear
  213. (- this.button[i].idleCol 1.0)
  214. this.buttonActiveCol[0] this.buttonClickCol[0]
  215. )
  216. (dd_math_ease_linear
  217. (- this.button[i].idleCol 1.0)
  218. this.buttonActiveCol[1] this.buttonClickCol[1]
  219. )
  220. (dd_math_ease_linear
  221. (- this.button[i].idleCol 1.0)
  222. this.buttonActiveCol[2] this.buttonClickCol[2]
  223. )
  224. )
  225. # change colour when selected
  226. (avdl_setUniform3f colLoc
  227. (dd_math_ease_linear this.button[i].idleCol this.buttonInactiveCol[0] this.buttonActiveCol[0])
  228. (dd_math_ease_linear this.button[i].idleCol this.buttonInactiveCol[1] this.buttonActiveCol[1])
  229. (dd_math_ease_linear this.button[i].idleCol this.buttonInactiveCol[2] this.buttonActiveCol[2])
  230. )
  231. )
  232. (this.button[i].applyTransform)
  233. (this.button[i].applyMatrixTransform)
  234. (this.button[i].drawRaw)
  235. (dd_translatef 0 0 0.15)
  236. (dd_scalef 0.2 0.2 0.2)
  237. (if (== i 0)
  238. (group)
  239. (== i 1)
  240. (group)
  241. (== i 2)
  242. (group)
  243. (== i 3)
  244. (group)
  245. (== i 4)
  246. (if (== guide 0)
  247. (this.font.draw "include guide")
  248. (this.font.draw "no guide")
  249. )
  250. (== i 5)
  251. (this.font.draw "back")
  252. (== i 6)
  253. (this.font.draw "start")
  254. )
  255. (dd_matrix_pop)
  256. )
  257. )
  258. (avdl_useProgram 0)
  259. # draw button description
  260. (if (>= this.selection 0)
  261. (group
  262. (dd_matrix_push)
  263. (this.textButton.applyTransform)
  264. (this.textButton.applyMatrixTransform)
  265. (dd_translatef 0 0 0.1)
  266. (dd_scalef 0.2 0.2 0.2)
  267. (def float limit (* (dd_screen_width_get this.textButton.z) 1.8))
  268. (if this.isMovingToNewWorld
  269. (this.font.drawLimit "loading" limit)
  270. (== this.selection 0)
  271. (this.font.drawLimit "decrease number of players" limit)
  272. (== this.selection 1)
  273. (this.font.drawLimit "increase number of players" limit)
  274. (|| (== this.selection 2) (== this.selection 3))
  275. (this.font.drawLimit "change starting player" limit)
  276. (== this.selection 4)
  277. (this.font.drawLimit "toggle guide" limit)
  278. (== this.selection 5)
  279. (this.font.drawLimit "back to main menu" limit)
  280. (== this.selection 6)
  281. (this.font.drawLimit "start the game" limit)
  282. )
  283. (dd_matrix_pop)
  284. )
  285. )
  286. )
  287. )
  288. (class_function world_custom_game_menu void key_input (group char key)
  289. (group
  290. (if (== key 27)
  291. (= dd_flag_exit 1) # exit game
  292. ) # key input
  293. )
  294. )
  295. (class_function world_custom_game_menu void clean (group)
  296. (group
  297. )
  298. )
  299. (class_function world_custom_game_menu void mouse_input (group int button int type)
  300. (group
  301. # re-check selection, this allows the user to directly click on a button
  302. # in a touch screen device
  303. (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
  304. (group
  305. (if (this.button[i].hasMouseCollided)
  306. (group
  307. (= this.selection i)
  308. )
  309. )
  310. )
  311. )
  312. # control the camera look at point when click and dragging
  313. (if (== type DD_INPUT_MOUSE_TYPE_PRESSED)
  314. (group
  315. (if (&& (>= this.selection 0) (this.button[this.selection].hasMouseCollided))
  316. (= this.selectionClick this.selection)
  317. )
  318. )
  319. (== type DD_INPUT_MOUSE_TYPE_RELEASED)
  320. (group
  321. # clicked on a button
  322. (if (&& (== this.selection this.selectionClick) (== this.isMovingToNewWorld 0)
  323. (>= this.selection 0) (this.button[this.selection].hasMouseCollided))
  324. (group
  325. # minus num of players
  326. (if (== this.selectionClick 0)
  327. (group
  328. (= numberOfPlayers (dd_math_max (- numberOfPlayers 1) 3))
  329. (= startingPlayer (dd_math_min startingPlayer (- numberOfPlayers 1)))
  330. )
  331. # plus num of players
  332. (== this.selectionClick 1)
  333. (group
  334. (= numberOfPlayers (dd_math_min (+ numberOfPlayers 1) 5))
  335. )
  336. # minus starting player
  337. (== this.selectionClick 2)
  338. (group
  339. (= startingPlayer (dd_math_max (- startingPlayer 1) -1))
  340. )
  341. # plus starting player
  342. (== this.selectionClick 3)
  343. (group
  344. (= startingPlayer (dd_math_min (+ startingPlayer 1) (- numberOfPlayers 1)))
  345. )
  346. # toggle guide
  347. (== this.selectionClick 4)
  348. (group
  349. (if (== guide 0)
  350. (= guide -1)
  351. (= guide 0)
  352. )
  353. )
  354. # back to main menu
  355. (== this.selectionClick 5)
  356. (group
  357. (dd_world_prepare world_menu 1.0)
  358. (dd_world_ready)
  359. (= this.isMovingToNewWorld 1)
  360. )
  361. # start game !
  362. (== this.selectionClick 6)
  363. (group
  364. (dd_world_prepare world_game 1.0)
  365. (dd_world_ready)
  366. (= this.isMovingToNewWorld 1)
  367. )
  368. )
  369. )
  370. )
  371. (= this.selectionClick -1)
  372. )
  373. ) # mouse button released
  374. )
  375. ) # mouse input