A pong clone, but with a twist!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

mainMenu.lua 11 KiB

4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. mainMenu = Class{}
  2. function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds, location)
  3. if (gameState == 'editor')
  4. then
  5. ev_button_width = VIRTUAL_WIDTH * (1/72)
  6. ev_BUTTON_HEIGHT = VIRTUAL_WIDTH * (1/72)
  7. local margin = 16
  8. local hot = false
  9. local cursor_y = 0
  10. blockinput = false
  11. local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
  12. for i, button in ipairs(buttons) do
  13. button.last = button.now
  14. ev_bx = (VIRTUAL_WIDTH*0.05) - (ev_button_width * 0.5)
  15. ev_by = (VIRTUAL_HEIGHT * 0.1) - (total_height * 0.5) + cursor_y
  16. local color = {255, 255, 255, 255}
  17. local mx, my = love.mouse.getPosition()
  18. mx = mx * DIFFERENCE_X
  19. my = my * DIFFERENCE_Y
  20. hot = (mx > ev_bx and mx < ev_bx + ev_button_width and my > ev_by and my < ev_by + ev_BUTTON_HEIGHT) and i
  21. if (hot == i) then
  22. blockinput = blockinput or true
  23. color = {10, 10, 0, 255}
  24. end
  25. button.now = love.keyboard.mouseWasReleased()
  26. if button.now and not button.last and hot == i then
  27. love.graphics.setColor(0,0,0,1)
  28. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  29. sounds['wallhit']:play()
  30. button.fn()
  31. end
  32. love.graphics.setColor(unpack(color))
  33. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  34. love.graphics.setColor(0, 0, 0, 255)
  35. local textW = smallfont:getWidth(button.text)
  36. local textH = smallfont:getHeight(button.text)
  37. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.05 - textW*0.5, ev_by*0.9+textH*0.01)
  38. love.graphics.setColor(255, 255, 255, 255)
  39. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  40. end
  41. else
  42. if location == 'middle' then
  43. locationx = (VIRTUAL_WIDTH * 0.5)
  44. locationy = (VIRTUAL_HEIGHT* 0.5)
  45. elseif location == 'right' then
  46. locationx = (VIRTUAL_WIDTH * 0.8)
  47. locationy = (VIRTUAL_HEIGHT* 0.5)
  48. elseif location == 'control' then
  49. locationx = (VIRTUAL_WIDTH * 0.2)
  50. locationy = (VIRTUAL_HEIGHT* 0.5)
  51. end
  52. local ev_button_width = VIRTUAL_WIDTH * (1/3)
  53. local ev_BUTTON_HEIGHT = 50
  54. local margin = 16
  55. local hot = false
  56. local cursor_y = 0
  57. local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
  58. local ev_bx, ev_by
  59. for i, button in ipairs(buttons) do
  60. button.last = button.now
  61. if (location == 'control') then
  62. if string.sub(button.text, 1, 1) == '2' then
  63. ev_bx = (VIRTUAL_WIDTH*0.2) - (ev_button_width * 0.5)
  64. ev_by = locationy - (total_height * 0.5) + cursor_y
  65. elseif string.sub(button.text, 1, 1) == '1' then
  66. ev_bx = (VIRTUAL_WIDTH*0.8) - (ev_button_width * 0.5)
  67. ev_by = locationy - (total_height * 0.5) + cursor_y
  68. else
  69. ev_bx = (VIRTUAL_WIDTH*0.5) - (ev_button_width * 0.5)
  70. ev_by = locationy - (total_height * 0.5) + cursor_y
  71. end
  72. elseif button.text == 'NUCLEAR MODE' and easternum < 11 then
  73. ev_bx = -400
  74. ev_by = -400
  75. else
  76. ev_bx = locationx - (ev_button_width * 0.5)
  77. ev_by = locationy - (total_height * 0.5) + cursor_y
  78. end
  79. if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255} else
  80. color = {10, 10, 0, 255}
  81. end
  82. local color = {255, 255, 255, 255}
  83. if (button.text == 'NUCLEAR MODE' and easternum > 10) then
  84. color = {0,0,0,1}
  85. else
  86. color = {1,1,1,1}
  87. end
  88. local mx, my = love.mouse.getPosition()
  89. local mx = mx * DIFFERENCE_X
  90. local my = my * DIFFERENCE_Y
  91. local hot = (mx > ev_bx and mx < ev_bx + ev_button_width and my > ev_by and my < ev_by + ev_BUTTON_HEIGHT) and i
  92. if (hot == i) then
  93. color = {10, 10, 0, 255}
  94. end
  95. button.now = love.keyboard.mouseWasReleased()
  96. if button.now and not button.last and hot == i then
  97. love.graphics.setColor(0,0,0,1)
  98. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  99. sounds['wallhit']:play()
  100. button.fn()
  101. end
  102. love.graphics.setColor(unpack(color))
  103. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  104. love.graphics.setColor(0, 0, 0, 255)
  105. local textW = smallfont:getWidth(button.text)
  106. local textH = smallfont:getHeight(button.text)
  107. if (location == 'control') then
  108. if (button.text == "1up") then
  109. love.graphics.print("Player 1 UP: " .. string.upper(p1control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  110. elseif button.text == '2up' then
  111. love.graphics.print("Player 2 UP: " .. string.upper(p2control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  112. elseif button.text == '1down' then
  113. love.graphics.print("Player 1 DOWN: " .. string.upper(p1control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  114. elseif button.text == '2down' then
  115. love.graphics.print("Player 2 DOWN: " .. string.upper(p2control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  116. elseif button.text == '1special' then
  117. love.graphics.print("Player 1 SPECIAL: " .. string.upper(p1control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  118. elseif button.text == '2special' then
  119. love.graphics.print("Player 2 SPECIAL: " .. string.upper(p2control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  120. elseif button.text == '1ct' then
  121. love.graphics.print("Player 1 COUNTER: " .. string.upper(p1control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  122. elseif button.text == '2ct' then
  123. love.graphics.print("Player 2 COUNTER: " .. string.upper(p2control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  124. else
  125. love.graphics.print(button.text, smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  126. end
  127. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  128. else
  129. if (button.text == '1v1') then
  130. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  131. elseif button.text == 'snc' then
  132. if (nuckemodactive == 1) then
  133. love.graphics.setColor(1,0,0,1)
  134. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  135. love.graphics.setColor(1,1,1,1)
  136. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  137. love.graphics.setColor(0,0,0,1)
  138. else
  139. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.45 - textW*0.5, ev_by+textH*0.5)
  140. end
  141. elseif (button.text == 'ballCount') then
  142. love.graphics.print("Ball Count: " .. maxBalls, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  143. elseif (button.text == "Ball Speed: ") then
  144. if (nuckemodactive == 1) then
  145. love.graphics.setColor(1,0,0,1)
  146. love.graphics.print("shaitan machina", smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  147. love.graphics.setColor(1,1,1,1)
  148. love.graphics.print("shaitan machina", smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  149. love.graphics.setColor(0,0,0,1)
  150. else
  151. love.graphics.print(button.text .. ballSet, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  152. end
  153. elseif button.text == 'ptw' then
  154. love.graphics.print("Points to Win: " .. ptw, smallfont,VIRTUAL_WIDTH*0.5 - textW * 1.5, ev_by+textH*0.5)
  155. elseif (button.text == 'Silverblade') then
  156. love.graphics.print("Difficulty: " .. prtext, smallfont, VIRTUAL_WIDTH*0.5 - textW , ev_by+textH*0.5)
  157. else
  158. love.graphics.print(button.text, smallfont, locationx - textW*0.5, ev_by+textH*0.5)
  159. end
  160. love.graphics.setColor(255, 255, 255, 255)
  161. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  162. end
  163. end
  164. end
  165. end
  166. function mainMenu:addButton(text, fn)
  167. return {
  168. text = text,
  169. fn = fn,
  170. now = false,
  171. last = false
  172. }
  173. end
  174. function menuButtons()
  175. local button_width = VIRTUAL_WIDTH * (1/3)
  176. local BUTTON_HEIGHT = 50
  177. local margin = 16
  178. local hot = false
  179. local cursor_y = 0
  180. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  181. for i, button in ipairs(buttons) do
  182. button.last = button.now
  183. local bx = (VIRTUAL_WIDTH*0.5) - (button_width * 0.5)
  184. local by = (VIRTUAL_HEIGHT * 0.8) - (total_height * 0.5) + cursor_y
  185. local color = {255, 255, 255, 255}
  186. local mx, my = love.mouse.getPosition()
  187. mx = mx * DIFFERENCE_X
  188. my = my * DIFFERENCE_Y
  189. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  190. if (hot == i) then
  191. color = {10, 10, 0, 255}
  192. end
  193. button.now = love.keyboard.mouseWasReleased()
  194. if button.now and not button.last and hot == i then
  195. love.graphics.setColor(0,0,0,1)
  196. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  197. sounds['wallhit']:play()
  198. button.fn()
  199. end
  200. love.graphics.setColor(unpack(color))
  201. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  202. love.graphics.setColor(0, 0, 0, 255)
  203. local textW = smallfont:getWidth(button.text)
  204. local textH = smallfont:getHeight(button.text)
  205. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  206. love.graphics.setColor(255, 255, 255, 255)
  207. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  208. end
  209. end