main.lua 3.7 KB

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