A pong clone, but with a twist!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mainMenu.lua 12 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. elseif location == "android" then
  52. locationx = (VIRTUAL_WIDTH * 0.5)
  53. locationy = (10)
  54. end
  55. local ev_button_width = VIRTUAL_WIDTH * (1/3)
  56. local ev_BUTTON_HEIGHT = 50
  57. if location == "android" then
  58. ev_button_width = 30
  59. ev_BUTTON_HEIGHT = 30
  60. end
  61. local margin = 16
  62. local hot = false
  63. local cursor_y = 0
  64. local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
  65. local ev_bx, ev_by
  66. for i, button in ipairs(buttons) do
  67. button.last = button.now
  68. if (location == 'control') then
  69. if string.sub(button.text, 1, 1) == '2' then
  70. ev_bx = (VIRTUAL_WIDTH*0.2) - (ev_button_width * 0.5)
  71. ev_by = locationy - (total_height * 0.5) + cursor_y
  72. elseif string.sub(button.text, 1, 1) == '1' then
  73. ev_bx = (VIRTUAL_WIDTH*0.8) - (ev_button_width * 0.5)
  74. ev_by = locationy - (total_height * 0.5) + cursor_y
  75. else
  76. ev_bx = (VIRTUAL_WIDTH*0.5) - (ev_button_width * 0.5)
  77. ev_by = locationy - (total_height * 0.5) + cursor_y
  78. end
  79. elseif button.text == 'NUCLEAR MODE' and easternum < 11 then
  80. ev_bx = -400
  81. ev_by = -400
  82. else
  83. ev_bx = locationx - (ev_button_width * 0.5)
  84. ev_by = locationy - (total_height * 0.5) + cursor_y
  85. end
  86. if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255} else
  87. color = {10, 10, 0, 255}
  88. end
  89. local color = {255, 255, 255, 255}
  90. if (button.text == 'NUCLEAR MODE' and easternum > 10) then
  91. color = {0,0,0,1}
  92. else
  93. color = {1,1,1,1}
  94. end
  95. local mx, my = love.mouse.getPosition()
  96. local mx = mx * DIFFERENCE_X
  97. local my = my * DIFFERENCE_Y
  98. 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
  99. if (hot == i) then
  100. color = {10, 10, 0, 255}
  101. end
  102. button.now = love.keyboard.mouseWasReleased()
  103. if button.now and not button.last and hot == i then
  104. love.graphics.setColor(0,0,0,1)
  105. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  106. sounds['wallhit']:play()
  107. button.fn()
  108. end
  109. love.graphics.setColor(unpack(color))
  110. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  111. love.graphics.setColor(0, 0, 0, 255)
  112. local textW = smallfont:getWidth(button.text)
  113. local textH = smallfont:getHeight(button.text)
  114. if (location == 'control') then
  115. if danger == button.text or danger2 == button.text then
  116. love.graphics.setColor(1,0,0,1)
  117. else
  118. love.graphics.setColor(0,0,0,1)
  119. end
  120. if (button.text == "1up") then
  121. love.graphics.print("P1 UP: " .. string.upper(p1control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  122. elseif button.text == '2up' then
  123. love.graphics.print("P2 UP: " .. string.upper(p2control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  124. elseif button.text == '1down' then
  125. love.graphics.print("P1 DOWN: " .. string.upper(p1control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  126. elseif button.text == '2down' then
  127. love.graphics.print("P2 DOWN: " .. string.upper(p2control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  128. elseif button.text == '1special' then
  129. love.graphics.print("P1 SPECIAL: " .. string.upper(p1control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  130. elseif button.text == '2special' then
  131. love.graphics.print("P2 SPECIAL: " .. string.upper(p2control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  132. elseif button.text == '1ct' then
  133. love.graphics.print("P1 COUNTER: " .. string.upper(p1control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  134. elseif button.text == '2ct' then
  135. love.graphics.print("P2 COUNTER: " .. string.upper(p2control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  136. else
  137. love.graphics.print(button.text, smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  138. end
  139. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  140. else
  141. if (button.text == '1v1') then
  142. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  143. elseif button.text == 'snc' then
  144. if (nuckemodactive == 1) then
  145. love.graphics.setColor(1,0,0,1)
  146. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.7, ev_by+textH*0.5)
  147. love.graphics.setColor(1,1,1,1)
  148. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.7, ev_by+textH*0.5)
  149. love.graphics.setColor(0,0,0,1)
  150. else
  151. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH*0.45 - textW*0.5, ev_by+textH*0.5)
  152. end
  153. elseif (button.text == 'ballCount') then
  154. love.graphics.print("Ball Count: " .. maxBalls, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.7, ev_by+textH*0.5)
  155. elseif (button.text == "Ball Speed: ") then
  156. if (nuckemodactive == 1) then
  157. love.graphics.setColor(1,0,0,1)
  158. love.graphics.print("shaitan machina", smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  159. love.graphics.setColor(1,1,1,1)
  160. love.graphics.print("shaitan machina", smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, ev_by+textH*0.5)
  161. love.graphics.setColor(0,0,0,1)
  162. else
  163. love.graphics.print(button.text .. ballSet, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.6, ev_by+textH*0.5)
  164. end
  165. elseif button.text == 'ptw' then
  166. love.graphics.print("Points to Win: " .. ptw, smallfont,VIRTUAL_WIDTH*0.5 - textW * 2.8, ev_by+textH*0.5)
  167. elseif (button.text == 'Silverblade') then
  168. love.graphics.print("Difficulty: " .. prtext, smallfont, VIRTUAL_WIDTH*0.5 - textW , ev_by+textH*0.5)
  169. else
  170. love.graphics.print(button.text, smallfont, locationx - textW*0.5, ev_by+textH*0.5)
  171. end
  172. love.graphics.setColor(255, 255, 255, 255)
  173. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  174. end
  175. end
  176. end
  177. end
  178. function mainMenu:addButton(text, fn)
  179. return {
  180. text = text,
  181. fn = fn,
  182. now = false,
  183. last = false
  184. }
  185. end
  186. function menuButtons()
  187. local button_width = VIRTUAL_WIDTH * (1/3)
  188. local BUTTON_HEIGHT = 50
  189. local margin = 16
  190. local hot = false
  191. local cursor_y = 0
  192. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  193. for i, button in ipairs(buttons) do
  194. button.last = button.now
  195. local bx = (VIRTUAL_WIDTH*0.5) - (button_width * 0.5)
  196. local by = (VIRTUAL_HEIGHT * 0.8) - (total_height * 0.5) + cursor_y
  197. local color = {255, 255, 255, 255}
  198. local mx, my = love.mouse.getPosition()
  199. mx = mx * DIFFERENCE_X
  200. my = my * DIFFERENCE_Y
  201. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  202. if (hot == i) then
  203. color = {10, 10, 0, 255}
  204. end
  205. button.now = love.keyboard.mouseWasReleased()
  206. if button.now and not button.last and hot == i then
  207. love.graphics.setColor(0,0,0,1)
  208. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  209. sounds['wallhit']:play()
  210. button.fn()
  211. end
  212. love.graphics.setColor(unpack(color))
  213. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  214. love.graphics.setColor(0, 0, 0, 255)
  215. local textW = smallfont:getWidth(button.text)
  216. local textH = smallfont:getHeight(button.text)
  217. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  218. love.graphics.setColor(255, 255, 255, 255)
  219. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  220. end
  221. end