Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. function love.load()
  2. love.resize(love.graphics.getDimensions())
  3.  
  4. gGuesses, gCurrentGuess = {}, 1
  5. for i = 1, 10 do
  6. gGuesses[i] = { digits = {} }
  7. end
  8. end
  9.  
  10. function love.resize(w, h)
  11. gWidth, gHeight = w, h
  12. end
  13.  
  14. function drawDigit(digit, x, y)
  15. love.graphics.line(x, y, x + 10, y)
  16. if digit then
  17. love.graphics.print(digit, x + 1, y - 15)
  18. end
  19. end
  20.  
  21. function drawSingleGuess(guess, x, y)
  22. for i = 0, 3 do
  23. drawDigit(guess.digits[i + 1], x + i * (10 + 6), y)
  24. end
  25. if guess.dots then
  26. for i = 1, 4 do
  27. if guess.dots[i] == 0 then
  28. love.graphics.circle("fill", x + 70 + i * 14, y - 4, 4)
  29. elseif guess.dots[i] == 1 then
  30. love.graphics.circle("line", x + 70 + i * 14, y - 4, 6)
  31. else
  32. love.graphics.circle("fill", x + 70 + i * 14, y - 4, 6)
  33. end
  34. end
  35. end
  36. end
  37.  
  38. function love.draw()
  39. for i = 0, 9 do
  40. drawSingleGuess(
  41. gGuesses[gCurrentGuess],
  42. (gWidth - (10 * 4 + 6 * 3)) / 2,
  43. (gHeight - (10 * 20)) / 2 + i * 20
  44. )
  45. end
  46. end
  47.  
  48. function love.keypressed(key)
  49. if key == "escape" then
  50. love.event.quit()
  51. elseif key == "backspace" then
  52. gGuesses[gCurrentGuess].digits = {}
  53. elseif key == "return" then
  54. if #gCurrentDigits ~= 4 then
  55. return
  56. end
  57.  
  58. gCurrentGuess = gCurrentGuess + 1
  59. elseif string.match("123456789", key) then
  60. if #gCurrentDigits == 4 then
  61. return
  62. end
  63.  
  64. for i = 1, #gCurrentDigits do
  65. if gCurrentDigits[i] == key then
  66. return
  67. end
  68. end
  69.  
  70. table.insert(gCurrentDigits, key)
  71. end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement