A pong clone, but with a twist!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 rivejä
14 KiB

  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
  19. my = my
  20. mx = mx * DIFFERENCE_X
  21. my = my * DIFFERENCE_Y
  22. hot = (mx > ev_bx and mx < ev_bx + ev_button_width and my > ev_by and my < ev_by + ev_BUTTON_HEIGHT) and i
  23. if (hot == i) then
  24. blockinput = blockinput or true
  25. color = {10, 10, 0, 255}
  26. end
  27. button.now = love.keyboard.mouseWasReleased()
  28. if button.now and not button.last and hot == i then
  29. love.keyboard.mouseisReleased = false
  30. love.graphics.setColor(0,0,0,1)
  31. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  32. sounds['wallhit']:play()
  33. button.fn()
  34. end
  35. love.graphics.setColor(unpack(color))
  36. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  37. love.graphics.setColor(0, 0, 0, 255)
  38. local textW = smallfont:getWidth(button.text)
  39. local textH = smallfont:getHeight(button.text)
  40. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.05 - textW*0.5, ev_by*0.9+textH*0.01)
  41. love.graphics.setColor(255, 255, 255, 255)
  42. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  43. end
  44. else
  45. if location == 'middle' then
  46. locationx = (VIRTUAL_WIDTH * 0.5)
  47. locationy = (VIRTUAL_HEIGHT* 0.5)
  48. elseif location == 'right' then
  49. locationx = (VIRTUAL_WIDTH * 0.8)
  50. locationy = (VIRTUAL_HEIGHT* 0.5)
  51. elseif location == 'control' then
  52. locationx = (VIRTUAL_WIDTH * 0.2)
  53. locationy = (VIRTUAL_HEIGHT* 0.5)
  54. elseif location == "android" then
  55. locationx = (VIRTUAL_WIDTH * 0.5)
  56. locationy = (10)
  57. end
  58. local ev_button_width = VIRTUAL_WIDTH * (1/3)
  59. local ev_BUTTON_HEIGHT = 50
  60. if location == "android" then
  61. ev_button_width = 30
  62. ev_BUTTON_HEIGHT = 30
  63. end
  64. local margin = 16
  65. local hot = false
  66. local cursor_y = 0
  67. local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
  68. local ev_bx, ev_by
  69. for i, button in ipairs(buttons) do
  70. --print("Button")
  71. button.last = button.now
  72. if button.x ~= -1 then
  73. ev_bx = button.x
  74. else
  75. ev_bx = locationx - (ev_button_width * 0.5)
  76. end
  77. if (location == 'control') then
  78. if string.sub(button.text, 1, 1) == '2' then
  79. ev_bx = (VIRTUAL_WIDTH*0.2) - (ev_button_width * 0.5)
  80. ev_by = locationy - (total_height * 0.5) + cursor_y
  81. elseif string.sub(button.text, 1, 1) == '1' then
  82. ev_bx = (VIRTUAL_WIDTH*0.8) - (ev_button_width * 0.5)
  83. ev_by = locationy - (total_height * 0.5) + cursor_y
  84. else
  85. ev_bx = (VIRTUAL_WIDTH*0.5) - (ev_button_width * 0.5)
  86. ev_by = locationy - (total_height * 0.5) + cursor_y
  87. end
  88. elseif button.text == 'NUCLEAR MODE' and easternum < 11 then
  89. ev_bx = -400
  90. ev_by = -400
  91. elseif button.x > locationx - (ev_button_width * 0.5) then
  92. --print("moving from" .. button.x)
  93. button.x = button.x - 15
  94. --print("moving!" .. button.x)
  95. ev_by = locationy - (total_height * 0.5) + cursor_y
  96. else
  97. ev_by = locationy - (total_height * 0.5) + cursor_y
  98. end
  99. if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255} else
  100. color = {10, 10, 0, 255}
  101. end
  102. local color = {255, 255, 255, 255}
  103. if (button.text == 'NUCLEAR MODE' and easternum > 10) then
  104. color = {0,0,0,1}
  105. else
  106. color = {1,1,1,1}
  107. end
  108. local mx, my = love.mouse.getPosition()
  109. mx = mx
  110. my = my
  111. local mx = mx * DIFFERENCE_X
  112. local my = my * DIFFERENCE_Y
  113. 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
  114. if (hot == i) then
  115. color = {10, 10, 0, 255}
  116. end
  117. --print(love.keyboard.mouseisReleased)
  118. button.now = love.keyboard.mouseisReleased
  119. if location == "android" then
  120. button.now = love.mouse.isDown(1)
  121. end
  122. if button.now and hot == i then
  123. love.keyboard.mouseisReleased = false
  124. love.graphics.setColor(0,0,0,1)
  125. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  126. sounds['wallhit']:play()
  127. if button.skipAnim then
  128. print("skipped anim")
  129. else
  130. for j, buttons in ipairs(buttons) do
  131. buttons.x = 1300
  132. print("making" .. j)
  133. end
  134. end
  135. button.fn()
  136. break
  137. end
  138. love.graphics.setColor(unpack(color))
  139. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  140. print(ev_bx .. " " .. i)
  141. love.graphics.setColor(0, 0, 0, 255)
  142. local textW = smallfont:getWidth(button.text)
  143. local textH = smallfont:getHeight(button.text)
  144. if (location == 'control') then
  145. if danger == button.text or danger2 == button.text then
  146. love.graphics.setColor(1,0,0,1)
  147. else
  148. love.graphics.setColor(0,0,0,1)
  149. end
  150. if (button.text == "1up") then
  151. love.graphics.print("P1 UP: " .. string.upper(p1control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  152. elseif button.text == '2up' then
  153. love.graphics.print("P2 UP: " .. string.upper(p2control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  154. elseif button.text == '1down' then
  155. love.graphics.print("P1 DOWN: " .. string.upper(p1control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  156. elseif button.text == '2down' then
  157. love.graphics.print("P2 DOWN: " .. string.upper(p2control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  158. elseif button.text == '1special' then
  159. love.graphics.print("P1 SPECIAL: " .. string.upper(p1control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  160. elseif button.text == '2special' then
  161. love.graphics.print("P2 SPECIAL: " .. string.upper(p2control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  162. elseif button.text == '1ct' then
  163. love.graphics.print("P1 COUNTER: " .. string.upper(p1control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  164. elseif button.text == '2ct' then
  165. love.graphics.print("P2 COUNTER: " .. string.upper(p2control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  166. else
  167. love.graphics.print(button.text, smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  168. end
  169. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  170. else
  171. if (button.text == '1v1') then
  172. love.graphics.print(playertext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, by+textH*0.5)
  173. elseif button.text == 'snc' then
  174. if (nuckemodactive == 1) then
  175. textW = smallfont:getWidth(synctext)
  176. love.graphics.setColor(1,0,0,1)
  177. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  178. love.graphics.setColor(1,1,1,1)
  179. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  180. love.graphics.setColor(0,0,0,1)
  181. else
  182. textW = smallfont:getWidth(synctext)
  183. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  184. end
  185. elseif (button.text == 'ballCount') then
  186. local tempstr = "Ball Count: " .. maxBalls
  187. textW = smallfont:getWidth(tempstr)
  188. love.graphics.print("Ball Count: " .. maxBalls, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  189. elseif (button.text == "Ball Speed: ") then
  190. if (nuckemodactive == 1) then
  191. love.graphics.setColor(1,0,0,1)
  192. love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  193. love.graphics.setColor(1,1,1,1)
  194. love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  195. love.graphics.setColor(0,0,0,1)
  196. else
  197. textW = smallfont:getWidth(button.text .. ballSet)
  198. love.graphics.print(button.text .. ballSet, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  199. end
  200. elseif button.text == 'ptw' then
  201. local tempstr = "Points to Win: " .. ptw
  202. textW = smallfont:getWidth(tempstr)
  203. love.graphics.print("Points to Win: " .. ptw, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  204. elseif (button.text == 'Silverblade') then
  205. local tempstr = "Difficulty: " .. prtext
  206. textW = smallfont:getWidth(tempstr)
  207. love.graphics.print("Difficulty: " .. prtext, smallfont,ev_bx + ev_button_width*0.5 - textW*0.5 , ev_by+textH*0.5)
  208. else
  209. love.graphics.print(button.text, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  210. end
  211. love.graphics.setColor(255, 255, 255, 255)
  212. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  213. end
  214. end
  215. end
  216. end
  217. function mainMenu:addButton(text, fn)
  218. if isButtonAnimated == true then
  219. print("Button shall be animated!")
  220. newButtonXVariable = 1290
  221. else
  222. print("Button shall NOT be animated!")
  223. newButtonXVariable = -1
  224. end
  225. return {
  226. x = newButtonXVariable,
  227. text = text,
  228. fn = fn,
  229. now = false,
  230. last = false
  231. }
  232. end
  233. function menuButtons()
  234. local button_width = VIRTUAL_WIDTH * (1/3)
  235. local BUTTON_HEIGHT = 50
  236. local margin = 16
  237. local hot = false
  238. local cursor_y = 0
  239. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  240. for i, button in ipairs(buttons) do
  241. button.last = button.now
  242. local bx = (VIRTUAL_WIDTH*0.5) - (button_width * 0.5)
  243. local by = (VIRTUAL_HEIGHT * 0.8) - (total_height * 0.5) + cursor_y
  244. local color = {255, 255, 255, 255}
  245. local mx, my = love.mouse.getPosition()
  246. mx = mx
  247. my = my
  248. mx = mx * DIFFERENCE_X
  249. my = my * DIFFERENCE_Y
  250. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  251. if (hot == i) then
  252. color = {10, 10, 0, 255}
  253. end
  254. button.now = love.keyboard.mouseWasReleased()
  255. if button.now and not button.last and hot == i then
  256. love.keyboard.mouseisReleased = false
  257. love.graphics.setColor(0,0,0,1)
  258. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  259. sounds['wallhit']:play()
  260. button.fn()
  261. end
  262. love.graphics.setColor(unpack(color))
  263. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  264. love.graphics.setColor(0, 0, 0, 255)
  265. local textW = smallfont:getWidth(button.text)
  266. local textH = smallfont:getHeight(button.text)
  267. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  268. love.graphics.setColor(255, 255, 255, 255)
  269. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  270. end
  271. end