main.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. -- zzzzzzzzzzzzzzzzzzzzzzzz
  2. -- zzzzzzzzzzzzzzzzzzzzzzzz
  3. Dtotal = 0
  4. DtotalFloor = 0
  5. DebugMessage1 = "none"
  6. DebugMessage2 = "none"
  7. print("Haloa!")
  8. -- ==================================================================================
  9. -- ==================================================================================
  10. function love.load()
  11. Lume = require("lume")
  12. loadGame()
  13. require("ui")
  14. require("data")
  15. end
  16. -- ==================================================================================
  17. -- ==================================================================================
  18. function love.update(dt)
  19. Dtotal = Dtotal + dt
  20. if math.floor(Dtotal) > DtotalFloor then
  21. local diff = math.floor(Dtotal) - DtotalFloor
  22. DtotalFloor = DtotalFloor + diff
  23. updateStocks(diff)
  24. end
  25. end
  26. -- ==================================================================================
  27. -- ==================================================================================
  28. function love.draw()
  29. love.graphics.setColor(colorWhite)
  30. love.graphics.print("Hello World! Since "..DtotalFloor.."sec", 400, 300)
  31. love.graphics.print(math.floor(Stones).." Stones", 400, 340)
  32. -- DRAW CRAFTERS
  33. -- ===========================
  34. for i=1, #crafter do
  35. local crft = crafter[i]
  36. if crft.active then
  37. love.graphics.setColor(colorOrange)
  38. love.graphics.rectangle(
  39. "fill", crft.ui.x, crft.ui.y, crft.ui.w, crft.ui.h, 5, 5)
  40. love.graphics.setColor(colorWhite)
  41. love.graphics.print(crft.amount .. crft.title, crft.ui.x+5, crft.ui.y+5, 0, 1, 1)
  42. elseif crft.own then
  43. if crft.own and not crft.active then
  44. local curpos = progressbar(crft.ready, crft.readyTime, crft.ui.h)
  45. end
  46. love.graphics.setColor(colorBlue)
  47. love.graphics.rectangle(
  48. "fill", crft.ui.x, crft.ui.y, crft.ui.w, crft.ui.h, 5, 5)
  49. love.graphics.setColor(colorOrange)
  50. love.graphics.rectangle(
  51. "fill", crft.uiready.x, crft.uiready.y-curpos, crft.uiready.w, curpos, 5, 5)
  52. else
  53. love.graphics.setColor(colorGrey)
  54. love.graphics.rectangle("line", crft.ui.x, crft.ui.y, crft.ui.w, crft.ui.h, 5, 5)
  55. end
  56. end
  57. -- DRAW DEBUG
  58. -- ===========================
  59. love.graphics.setColor(colorWhite)
  60. love.graphics.print(DebugMessage1, 400, 260)
  61. love.graphics.print(DebugMessage2, 400, 280)
  62. end
  63. -- ==================================================================================
  64. -- ==================================================================================
  65. function checkRect(rect)
  66. local x, y = love.mouse.getPosition()
  67. local r_left = rect.x
  68. local r_right = rect.x + rect.w
  69. local r_top = rect.y
  70. local r_bottom = rect.y + rect.h
  71. return x > r_left
  72. and x < r_right
  73. and y > r_top
  74. and y < r_bottom
  75. end
  76. function love.mousereleased(x, y, button)
  77. if button == 1 then
  78. for i=1, #crafter do
  79. if checkRect(crafter[i].ui) then
  80. upgradeCrafter(crafter[i])
  81. end
  82. end
  83. end
  84. end
  85. function progressbar(cursec, maxsec, difpos)
  86. curpos = difpos / maxsec * cursec
  87. return curpos
  88. end
  89. function saveGame()
  90. -- savedata = dig
  91. -- serialized = lume.serialize(savedata)
  92. -- love.filesystem.write("savedata.txt", serialized)
  93. end
  94. function loadGame()
  95. -- if love.filesystem.getInfo("savedata.txt") then
  96. -- file = love.filesystem.read("savedata.txt")
  97. -- dig = lume.deserialize(file)
  98. -- end
  99. end
  100. function love.quit()
  101. saveGame()
  102. return false
  103. end