Browse Source

it's a thing now (have to unmess it still...)

voltcitron 1 năm trước cách đây
mục cha
commit
f5da138104
3 tập tin đã thay đổi với 42 bổ sung22 xóa
  1. 30 12
      data.lua
  2. 0 4
      draw.lua
  3. 12 6
      main.lua

+ 30 - 12
data.lua

@@ -1,6 +1,7 @@
 -- COMES AFTER UI.LUA
 
-Stones = 250.0  -- Current Stone Stock
+Stones = 30.0  -- Current Stone Stock
+StonesSec = 0
 
 crafter = {}
 
@@ -11,9 +12,9 @@ for i=0, 50 do
   dig.active = false -- is it active yet ?
   dig.readyTime = 10 -- time until active in Sec
   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
+  dig.speed = 0.3 -- Speed in Sec
+  dig.amount = 0.1 -- Amount by Sec
+  dig.cost = 10
   local xg = (i%20)*50
   local yg = 50 + math.floor(i/20)*50
   dig.ui = {color = colorBlue, x = xg, y = yg, w = 50, h = 50}
@@ -22,33 +23,50 @@ for i=0, 50 do
 end
 
 
-function updateStocks(sec)
+function updateCraft(sec)
   for i=1, #crafter do
     local crft = crafter[i]
 
-    if crft.active then
-      Stones = Stones + (crft.amount * sec * crft.speed)
-    elseif crft.own then
+    if not crft.active and crft.own then
       if crft.ready >= crft.readyTime then
         crft.active = true
+        recalcStonesSec()
       end
-        crft.ready = crft.ready + sec
+      crft.ready = crft.ready + sec
+    end
+  end
+end
+
+
+function recalcStonesSec()
+  local stsec = 0
+  
+  for i=1, #crafter do
+    local crft = crafter[i]
+    
+    if crft.active then
+      stsec = stsec + crft.amount * crft.speed
     end
   end
+
+  StonesSec = stsec
 end
 
+
 function upgradeCrafter(crft)
   -- BUY CRAFTER
   if not crft.own then
-    if pay(50) then
+    if pay(crft.cost) then
       crft.own = true
     end
   -- UPGRADE CRAFTER
-  elseif crft.ready == 0 and pay(50) then
-    crft.amount = crft.amount + 1
+  elseif crft.active and pay(crft.cost) then
+    crft.amount = crft.amount + 0.05
+    crft.cost = math.floor(crft.cost * 1.5)
   end
 end
 
+
 function pay(cost)
   if Stones >= cost then
     Stones = Stones - cost

+ 0 - 4
draw.lua

@@ -1,4 +0,0 @@
-
-  love.graphics.print(" CRAFTER NB", 400, 380)
-
-

+ 12 - 6
main.lua

@@ -17,6 +17,8 @@ function love.load()
   loadGame()
   require("ui")
   require("data")
+
+  local stoneShow = Stones
 end
 
 -- ==================================================================================
@@ -24,12 +26,14 @@ end
 
 function love.update(dt)
   Dtotal = Dtotal + dt
-  
-  if math.floor(Dtotal) > DtotalFloor then
-    local diff = math.floor(Dtotal) - DtotalFloor
-    DtotalFloor = DtotalFloor + diff
-    updateStocks(diff)
+
+  if math.floor(Dtotal*10) > DtotalFloor*10 then
+    updateCraft(dt)
+    DtotalFloor = math.floor(Dtotal)
   end
+  
+  Stones = Stones + StonesSec * dt
+  stoneShow = math.floor(Stones*100 + StonesSec*100) / 100
 end
 
 -- ==================================================================================
@@ -38,7 +42,8 @@ end
 function love.draw()
   love.graphics.setColor(colorWhite)
   love.graphics.print("Hello World! Since "..DtotalFloor.."sec", 400, 300)
-  love.graphics.print(math.floor(Stones).." Stones", 400, 340)
+  love.graphics.print(stoneShow, 400, 340)
+  love.graphics.print("Stones", 450, 340)
 
   -- DRAW CRAFTERS
   -- ===========================
@@ -51,6 +56,7 @@ function love.draw()
         "fill", crft.ui.x, crft.ui.y, crft.ui.w, crft.ui.h, 5, 5)
       love.graphics.setColor(colorWhite)
       love.graphics.print(crft.amount .. crft.title, crft.ui.x+5, crft.ui.y+5, 0, 1, 1)
+      love.graphics.print(crft.cost, crft.ui.x+5, crft.ui.y+20, 0, 1, 1)
       
     elseif crft.own then
       if crft.own and not crft.active then