Переглянути джерело

Buay...i was so happy that Gogs worked that i sent the first commit still borked, i was right in the middle of adding progressbar updates

voltcitron 1 рік тому
батько
коміт
3fd3dde83f
2 змінених файлів з 16 додано та 35 видалено
  1. 9 11
      data.lua
  2. 7 24
      main.lua

+ 9 - 11
data.lua

@@ -1,15 +1,16 @@
 -- COMES AFTER UI.LUA
 
-Stones = 150.0  -- Current Stone Stock
+Stones = 250.0  -- Current Stone Stock
 
 crafter = {}
 
 for i=0, 50 do
   local dig = {}
   dig.title = "D"
-  dig.own = false
+  dig.own = false -- is it bought ?
+  dig.active = false -- is it active yet ?
   dig.readyTime = 10 -- time until active in Sec
-  dig.ready = 10
+  dig.ready = 0 -- current time until readyTime
   dig.speed = 0.5 -- Speed in Sec
   dig.amount = 1 -- Amount by Sec
   dig.upCost = 50 -- Stones req to dig twice more
@@ -25,16 +26,13 @@ function updateStocks(sec)
   for i=1, #crafter do
     local crft = crafter[i]
 
-    if crft.ready == 0 then
+    if crft.active then
       Stones = Stones + (crft.amount * sec * crft.speed)
-    else
-      if crft.own then
-        crft.ready = crft.ready - sec
-        if crft.ready < 1 then
-          crft.ready = 0
-          crft.ui.color = colorOrange
-        end
+    elseif crft.own then
+      if crft.ready >= crft.readyTime then
+        crft.active = true
       end
+        crft.ready = crft.ready + sec
     end
   end
 end

+ 7 - 24
main.lua

@@ -30,13 +30,6 @@ function love.update(dt)
     DtotalFloor = DtotalFloor + diff
     updateStocks(diff)
   end
-  
-  for i=1, #crafter do
-    local crft = crafter[i]
-    local difpos = difpos(crft.ui.y + crft.ui.y, crft.ui.y)
-    local cursec = crft.readyTime - crft.ready
-    local curpos = progressbar(cursec, dt, maxsec, difpos)
-  end
 end
 
 -- ==================================================================================
@@ -59,15 +52,18 @@ function love.draw()
       love.graphics.setColor(colorWhite)
       love.graphics.print(crft.amount .. crft.title, crft.ui.x+5, crft.ui.y+5, 0, 1, 1)
       
-    else if crft.own then
+    elseif crft.own then
+      if crft.own and not crft.active then
+        local curpos = progressbar(crft.ready, crft.readyTime, crft.ui.h)
+      end
+      
       love.graphics.setColor(colorBlue)
       love.graphics.rectangle(
       "fill", crft.ui.x, crft.ui.y, crft.ui.w, crft.ui.h, 5, 5)
       
-      
       love.graphics.setColor(colorOrange)
       love.graphics.rectangle(
-      "fill", crft.ui.x, crft.ui.y, crft.ui.w, crft.ui.y, 5, 5)
+      "fill", crft.uiready.x, crft.uiready.y-curpos, crft.uiready.w, curpos, 5, 5)
       
     else
       love.graphics.setColor(colorGrey)
@@ -111,20 +107,7 @@ function love.mousereleased(x, y, button)
 end
 
 
-function difpos(min, max)
-  return max - min
-end
-
-
-function progressbar(cursec, dt, maxsec, difpos)
-  local cursec = 0 -- de 100 à 150 en 10 sec
-  local maxsec = 10
-  local minpos = 100
-  local maxpos = 150
-  local difpos = maxpos - minpos
-  local curpos = 0
-  
-  cursec = cursec + dt
+function progressbar(cursec, maxsec, difpos)
   curpos = difpos / maxsec * cursec
   
   return curpos