main.lua 3.6 KB

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