123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- (include "custom_game_menu.ddh")
- (include "game.ddh")
- (include "menu.ddh")
- (def int numberOfPlayers)
- (def int startingPlayer)
- (def int guide)
- (class_function world_custom_game_menu void create (group)
- (group
- (= this.isMovingToNewWorld 0)
- # background
- (= this.bg_rotation 0)
- (this.bg.load (asset "assets/stage_2.asset" DD_PLY))
- # font
- (this.font.setAlign DD_STRING3D_ALIGN_CENTER)
- (this.font.setColorFront 0.8 0.8 0.8)
- (this.font.setColorBack 0.3 0.3 0.3)
- # buttons
- (= this.buttonTotal 7)
- (this.button[0].mesh.load (asset "assets/button_minus.asset" DD_PLY))
- (this.button[0].setSize 1 1)
- (this.button[0].setProportionalPosition 0.50 0.8)
- (this.button[0].setProportionalWidth 0.2)
- (this.button[0].setProportionalSize 0.7)
- (this.button[1].mesh.load (asset "assets/button_plus.asset" DD_PLY))
- (this.button[1].setSize 1 1)
- (this.button[1].setProportionalPosition 0.8 0.8)
- (this.button[1].setProportionalWidth 0.2)
- (this.button[1].setProportionalSize 0.7)
- (this.button[2].mesh.load (asset "assets/button_minus.asset" DD_PLY))
- (this.button[2].setSize 1 1)
- (this.button[2].setProportionalPosition 0.5 0.575)
- (this.button[2].setProportionalWidth 0.2)
- (this.button[2].setProportionalSize 0.7)
- (this.button[3].mesh.load (asset "assets/button_plus.asset" DD_PLY))
- (this.button[3].setSize 1 1)
- (this.button[3].setProportionalPosition 0.8 0.575)
- (this.button[3].setProportionalWidth 0.2)
- (this.button[3].setProportionalSize 0.7)
- (this.button[4].mesh.load (asset "assets/button_toggle.asset" DD_PLY))
- (this.button[4].setSize 1 1)
- (this.button[4].setProportionalPosition 0.5 0.35)
- (this.button[4].setProportionalWidth 0.2)
- (this.button[4].setProportionalSize 0.7)
- (this.button[5].mesh.load (asset "assets/button.asset" DD_PLY))
- (this.button[5].setSize 1 1)
- (this.button[5].setProportionalPosition 0.12 0.15)
- (this.button[5].setProportionalWidth 0.2)
- (this.button[6].mesh.load (asset "assets/button.asset" DD_PLY))
- (this.button[6].setSize 1 1)
- (this.button[6].setProportionalPosition 0.88 0.15)
- (this.button[6].setProportionalWidth 0.2)
- # number of players
- (this.buttonPlayerNumber.setSize 1 1)
- (this.buttonPlayerNumber.setProportionalPosition 0.25 0.8)
- (this.buttonPlayerNumber.setProportionalWidth 0.2)
- (this.buttonPlayerNumber.setProportionalSize 1.0)
- (this.buttonPlayerNumberValue.setSize 1 1)
- (this.buttonPlayerNumberValue.setProportionalPosition 0.65 0.8)
- (this.buttonPlayerNumberValue.setProportionalWidth 0.2)
- (this.buttonPlayerNumberValue.setProportionalSize 1.0)
- # starting player
- (this.buttonStartingPlayer.setSize 1 1)
- (this.buttonStartingPlayer.setProportionalPosition 0.25 0.575)
- (this.buttonStartingPlayer.setProportionalWidth 0.2)
- (this.buttonStartingPlayer.setProportionalSize 1.0)
- (this.buttonStartingPlayerValue.setSize 1 1)
- (this.buttonStartingPlayerValue.setProportionalPosition 0.65 0.575)
- (this.buttonStartingPlayerValue.setProportionalWidth 0.2)
- (this.buttonStartingPlayerValue.setProportionalSize 1.0)
- # text display
- (this.textButton.setSize 1 1)
- (this.textButton.setProportionalPosition 0.5 0.15)
- (this.textButton.setProportionalWidth 0.15)
- (= this.selection 0)
- (= this.selectionClick -1)
- (= this.isMovingToNewWorld 0)
- (= numberOfPlayers 3)
- (= startingPlayer -1)
- (= guide 0)
- # shader for buttons
- (this.buttonProgram.setVertexShader
- (multistring
- "AVDL_IN vec4 position;\n"
- "AVDL_IN vec3 colour;\n"
- "uniform mat4 matrix;\n"
- "uniform vec3 tint;\n"
- "AVDL_OUT vec4 outColour;\n"
- "void main() {\n"
- " vec4 pos = matrix *position;\n"
- " gl_Position = pos;\n"
- " outColour = vec4(colour.rgb *tint.rgb, 1.0);\n"
- "}\n"
- )
- )
- (this.buttonProgram.setFragmentShader
- (multistring
- "AVDL_IN vec4 outColour;\n"
- "void main() {\n"
- " avdl_frag_color = outColour;\n"
- "}\n"
- )
- )
- # button colours
- (= this.buttonClickCol[0] 0.389)
- (= this.buttonClickCol[1] 0.055)
- (= this.buttonClickCol[2] 0.682)
- (= this.buttonActiveCol[0] 0.916)
- (= this.buttonActiveCol[1] 0.516)
- (= this.buttonActiveCol[2] 0.074)
- (= this.buttonInactiveCol[0] 0.694)
- (= this.buttonInactiveCol[1] 0.137)
- (= this.buttonInactiveCol[2] 0.137)
- )
- )
- (class_function world_custom_game_menu void onload (group)
- (group
- )
- )
- (class_function world_custom_game_menu void resize (group)
- (group
- (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
- (this.button[i].resize)
- )
- (this.buttonPlayerNumber.resize)
- (this.buttonPlayerNumberValue.resize)
- (this.buttonStartingPlayer.resize)
- (this.buttonStartingPlayerValue.resize)
- (this.textButton.resize)
- )
- )
- (class_function world_custom_game_menu void update (group)
- (group
- # constant background rotation
- (= this.bg_rotation (+ this.bg_rotation 0.01))
- (if (>= this.bg_rotation 360)
- (= this.bg_rotation (- this.bg_rotation 360))
- )
- # check if mouse is hovering over a button
- (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
- (group
- (if (this.button[i].hasMouseCollided)
- (group
- (= this.selection i)
- )
- )
- (this.button[i].update (== this.selection i) (== this.selectionClick i))
- )
- )
- )
- ) # update
- (class_function world_custom_game_menu void draw (group)
- (group
- # draw background
- (dd_matrix_push)
- (dd_translatef 0 -2 -3)
- (dd_rotatef (+ -80 this.bg_rotation) 0 1 0)
- (dd_rotatef 25 -1 0 0)
- (this.bg.draw)
- (dd_matrix_pop)
- # clear depth
- (glClear GL_DEPTH_BUFFER_BIT)
- # draw number of players
- (dd_matrix_push)
- (this.buttonPlayerNumber.applyTransform)
- (this.buttonPlayerNumber.applyMatrixTransform)
- (dd_translatef 0 0 0.1)
- (dd_scalef 0.2 0.2 0.2)
- (this.font.draw "number of players")
- (dd_matrix_pop)
- (dd_matrix_push)
- (this.buttonPlayerNumberValue.applyTransform)
- (this.buttonPlayerNumberValue.applyMatrixTransform)
- (dd_translatef 0 0 0.1)
- (dd_scalef 0.2 0.2 0.2)
- (this.font.drawInt numberOfPlayers)
- (dd_matrix_pop)
- # draw starting player
- (dd_matrix_push)
- (this.buttonStartingPlayer.applyTransform)
- (this.buttonStartingPlayer.applyMatrixTransform)
- (dd_translatef 0 0 0.1)
- (dd_scalef 0.2 0.2 0.2)
- (this.font.draw "starting player")
- (dd_matrix_pop)
- (dd_matrix_push)
- (this.buttonStartingPlayerValue.applyTransform)
- (this.buttonStartingPlayerValue.applyMatrixTransform)
- (dd_translatef 0 0 0.1)
- (dd_scalef 0.2 0.2 0.2)
- (if (== startingPlayer -1)
- (this.font.draw "random")
- (== startingPlayer 0)
- (this.font.draw "you")
- (group
- (dd_translatef -0.7 0 0)
- (this.font.draw "AI")
- (dd_translatef 1.4 0 0)
- (this.font.drawInt startingPlayer)
- )
- )
- (dd_matrix_pop)
- # draw buttons
- (this.buttonProgram.useProgram)
- (def int colLoc)
- (= colLoc (avdl_getUniformLocation this.buttonProgram "tint"))
- (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
- (group
- (dd_matrix_push)
- # change the shader colour when clicked
- (if (> this.button[i].idleCol 1.0)
- (avdl_setUniform3f colLoc
- (dd_math_ease_linear
- (- this.button[i].idleCol 1.0)
- this.buttonActiveCol[0] this.buttonClickCol[0]
- )
- (dd_math_ease_linear
- (- this.button[i].idleCol 1.0)
- this.buttonActiveCol[1] this.buttonClickCol[1]
- )
- (dd_math_ease_linear
- (- this.button[i].idleCol 1.0)
- this.buttonActiveCol[2] this.buttonClickCol[2]
- )
- )
- # change colour when selected
- (avdl_setUniform3f colLoc
- (dd_math_ease_linear this.button[i].idleCol this.buttonInactiveCol[0] this.buttonActiveCol[0])
- (dd_math_ease_linear this.button[i].idleCol this.buttonInactiveCol[1] this.buttonActiveCol[1])
- (dd_math_ease_linear this.button[i].idleCol this.buttonInactiveCol[2] this.buttonActiveCol[2])
- )
- )
- (this.button[i].applyTransform)
- (this.button[i].applyMatrixTransform)
- (this.button[i].drawRaw)
- (dd_translatef 0 0 0.15)
- (dd_scalef 0.2 0.2 0.2)
- (if (== i 0)
- (group)
- (== i 1)
- (group)
- (== i 2)
- (group)
- (== i 3)
- (group)
- (== i 4)
- (if (== guide 0)
- (this.font.draw "include guide")
- (this.font.draw "no guide")
- )
- (== i 5)
- (this.font.draw "back")
- (== i 6)
- (this.font.draw "start")
- )
- (dd_matrix_pop)
- )
- )
- (avdl_useProgram 0)
- # draw button description
- (if (>= this.selection 0)
- (group
- (dd_matrix_push)
- (this.textButton.applyTransform)
- (this.textButton.applyMatrixTransform)
- (dd_translatef 0 0 0.1)
- (dd_scalef 0.2 0.2 0.2)
- (def float limit (* (dd_screen_width_get this.textButton.z) 1.8))
- (if this.isMovingToNewWorld
- (this.font.drawLimit "loading" limit)
- (== this.selection 0)
- (this.font.drawLimit "decrease number of players" limit)
- (== this.selection 1)
- (this.font.drawLimit "increase number of players" limit)
- (|| (== this.selection 2) (== this.selection 3))
- (this.font.drawLimit "change starting player" limit)
- (== this.selection 4)
- (this.font.drawLimit "toggle guide" limit)
- (== this.selection 5)
- (this.font.drawLimit "back to main menu" limit)
- (== this.selection 6)
- (this.font.drawLimit "start the game" limit)
- )
- (dd_matrix_pop)
- )
- )
- )
- )
- (class_function world_custom_game_menu void key_input (group char key)
- (group
- (if (== key 27)
- (= dd_flag_exit 1) # exit game
- ) # key input
- )
- )
- (class_function world_custom_game_menu void clean (group)
- (group
- )
- )
- (class_function world_custom_game_menu void mouse_input (group int button int type)
- (group
- # re-check selection, this allows the user to directly click on a button
- # in a touch screen device
- (for (def int i 0) (< i this.buttonTotal) (= i (+ i 1))
- (group
- (if (this.button[i].hasMouseCollided)
- (group
- (= this.selection i)
- )
- )
- )
- )
- # control the camera look at point when click and dragging
- (if (== type DD_INPUT_MOUSE_TYPE_PRESSED)
- (group
- (if (&& (>= this.selection 0) (this.button[this.selection].hasMouseCollided))
- (= this.selectionClick this.selection)
- )
- )
- (== type DD_INPUT_MOUSE_TYPE_RELEASED)
- (group
- # clicked on a button
- (if (&& (== this.selection this.selectionClick) (== this.isMovingToNewWorld 0)
- (>= this.selection 0) (this.button[this.selection].hasMouseCollided))
- (group
- # minus num of players
- (if (== this.selectionClick 0)
- (group
- (= numberOfPlayers (dd_math_max (- numberOfPlayers 1) 3))
- (= startingPlayer (dd_math_min startingPlayer (- numberOfPlayers 1)))
- )
- # plus num of players
- (== this.selectionClick 1)
- (group
- (= numberOfPlayers (dd_math_min (+ numberOfPlayers 1) 5))
- )
- # minus starting player
- (== this.selectionClick 2)
- (group
- (= startingPlayer (dd_math_max (- startingPlayer 1) -1))
- )
- # plus starting player
- (== this.selectionClick 3)
- (group
- (= startingPlayer (dd_math_min (+ startingPlayer 1) (- numberOfPlayers 1)))
- )
- # toggle guide
- (== this.selectionClick 4)
- (group
- (if (== guide 0)
- (= guide -1)
- (= guide 0)
- )
- )
- # back to main menu
- (== this.selectionClick 5)
- (group
- (dd_world_prepare world_menu 1.0)
- (dd_world_ready)
- (= this.isMovingToNewWorld 1)
- )
- # start game !
- (== this.selectionClick 6)
- (group
- (dd_world_prepare world_game 1.0)
- (dd_world_ready)
- (= this.isMovingToNewWorld 1)
- )
- )
- )
- )
- (= this.selectionClick -1)
- )
- ) # mouse button released
- )
- ) # mouse input
|