diff --git a/screenshots/Resources.png b/screenshots/Resources.png new file mode 100644 index 0000000..a46a1af Binary files /dev/null and b/screenshots/Resources.png differ diff --git a/screenshots/The Clock.png b/screenshots/The Clock.png new file mode 100644 index 0000000..26e7942 Binary files /dev/null and b/screenshots/The Clock.png differ diff --git a/src/hud.lua b/src/hud.lua new file mode 100644 index 0000000..3d629ac --- /dev/null +++ b/src/hud.lua @@ -0,0 +1,106 @@ +local r = 75 +local edge = 5 + +local x = -480 + r + edge +local y = 270 - r - edge + +local x2 = 480 - r - edge +local y2 = 270 - r - edge + +local verticalOffset = math.pi/2 + +local timeSegments = 60 +local timeSegmentRadius = math.pi*2 / timeSegments +local timeDividerRadius = timeSegmentRadius / 2 + +local lg = love.graphics + +return function(stats) + lg.setColor(255, 102, 0) + if stats.time > 0 then + for i=1,stats.time do + lg.arc("fill", x, y, r, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + else + for i=0,stats.time+1,-1 do + lg.arc("fill", x, y, r, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x, y, r*4/5 + edge/2) + + lg.setColor(255, 0, 0) + for i=1,stats.ammo do + lg.arc("fill", x, y, r*4/5 - edge/2, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x, y, r*3/5 + edge/2) + + lg.setColor(255, 255, 0) + for i=1,stats.fuel do + lg.arc("fill", x, y, r*3/5 - edge/2, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x, y, r*2/5 + edge/2) + + lg.setColor(0, 0, 255) + for i=1,stats.supplies do + lg.arc("fill", x, y, r*2/5 - edge/2, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x, y, r*1/5 + edge/2) + + --[[ + 1-4 on first dial, main dial + 5-8 on second dial + + 1 Time orange + 2 Ammo red + 3 Fuel yellow + 4 Supplies blue ? + + 5 Water teal ? + 6 Food green + 7 Metal silver + 8 Ore brown + ]] + + lg.setColor(0, 255, 255) + for i=1,stats.water do + lg.arc("fill", x2, y2, r, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x2, y2, r*4/5 + edge/2) + + lg.setColor(0, 255, 0) + for i=1,stats.food do + lg.arc("fill", x2, y2, r*4/5 - edge/2, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x2, y2, r*3/5 + edge/2) + + lg.setColor(100, 100, 100) + for i=1,stats.metal do + lg.arc("fill", x2, y2, r*3/5 - edge/2, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x2, y2, r*2/5 + edge/2) + + lg.setColor(107, 66, 38) + for i=1,stats.ore do + lg.arc("fill", x2, y2, r*2/5 - edge/2, (i-1)*timeSegmentRadius - verticalOffset, i*timeSegmentRadius - timeDividerRadius - verticalOffset) + end + + lg.setColor(0, 0, 0) + lg.circle("fill", x2, y2, r*1/5 + edge/2) + + lg.setColor(255, 255, 255) + lg.print(stats.time, x, y) +end diff --git a/src/main.lua b/src/main.lua index b1749fe..21d616c 100644 --- a/src/main.lua +++ b/src/main.lua @@ -9,6 +9,8 @@ local scale = 8 local images = {} local fleet = {} +local hud = require "hud" + local bsg = require "ships.bsg" local viper = require "ships.viper" @@ -31,6 +33,121 @@ function love.load() end end +local timer = 0 +local stats = { + time = 60, + ammo = 40, + fuel = 55, + supplies = 10, + water = 30, + food = 40, + metal = 60, + ore = 24 +} +local function getStats() + local ammo = 0 + local fuel = 0 + local supplies = 0 + local water = 0 + local food = 0 + local metal = 0 + local ore = 0 + + local maxAmmo = 0 + local maxFuel = 0 + local maxSupplies = 0 + local maxWater = 0 + local maxFood = 0 + local maxMetal = 0 + local maxOre = 0 + + for i=1,#fleet do + ammo = ammo + fleet[i].Resources.ammo + fuel = fuel + fleet[i].Resources.fuel + supplies = supplies + fleet[i].Resources.supplies + water = water + fleet[i].Resources.water + food = food + fleet[i].Resources.food + metal = metal + fleet[i].Resources.metal + ore = ore + fleet[i].Resources.ore + + maxAmmo = maxAmmo + fleet[i].Resources.maxAmmo + maxFuel = maxFuel + fleet[i].Resources.maxFuel + maxSupplies = maxSupplies + fleet[i].Resources.maxSupplies + maxWater = maxWater + fleet[i].Resources.maxWater + maxFood = maxFood + fleet[i].Resources.maxFood + maxMetal = maxMetal + fleet[i].Resources.maxMetal + maxOre = maxOre + fleet[i].Resources.maxOre + end + + ammo = ammo * 60 / maxAmmo + fuel = fuel * 60 / maxFuel + supplies = supplies * 60 / maxSupplies + water = water * 60 / maxWater + food = food * 60 / maxFood + metal = metal * 60 / maxMetal + ore = ore * 60 / maxOre + + if ammo > 0 and ammo < 1 then + ammo = 1 + end + if fuel > 0 and fuel < 1 then + fuel = 1 + end + if supplies > 0 and supplies < 1 then + supplies = 1 + end + if water > 0 and water < 1 then + water = 1 + end + if food > 0 and food < 1 then + food = 1 + end + if metal > 0 and metal < 1 then + metal = 1 + end + if ore > 0 and ore < 1 then + ore = 1 + end + + return { + ammo = math.floor(ammo), + fuel = math.floor(fuel), + supplies = math.floor(supplies), + water = math.floor(water), + food = math.floor(food), + metal = math.floor(metal), + ore = math.floor(ore) + } +end +local timing = -60 +function love.update(dt) + timer = timer + dt + if timer >= 1 then + timer = timer - 1 + --stat = current * 60 / max + stats = getStats() + --[[ + stats = { + time = math.random(0, 60), + ammo = math.random(0, 60), + fuel = math.random(0, 60), + supplies = math.random(0, 60), + water = math.random(0, 60), + food = math.random(0, 60), + metal = math.random(0, 60), + ore = math.random(0, 60) + } + --]] + end + + timing = timing + dt + if timing >= 60 then + timing = timing -120 + end + + stats.time = math.floor(timing) --TMP +end + function love.draw() lg.translate(hx, hy) @@ -44,6 +161,8 @@ function love.draw() lg.setColor(220, 180, 0) lg.point(selected.x * scale, selected.y * scale) end + + hud(stats) end function love.keypressed(key, unicode) diff --git a/src/ships/Resources.lua b/src/ships/Resources.lua index 057a080..1b7a1a5 100644 --- a/src/ships/Resources.lua +++ b/src/ships/Resources.lua @@ -36,6 +36,25 @@ function Resources:initialize() self.crewUse = 0 end +function Resources:update(dt, engineStatus) + self.ammo = self.ammo - self.ammoUse * dt + if engineStatus == "idle" then + self.fuel = self.fuel - self.fuelUseIdle * dt + elseif engineStatus == "moving" then + self.fuel = self.fuel - self.fuelUseMoving * dt + else + error("Invalid engineStatus!") + end + self.supplies = self.supplies - self.suppliesUse * dt + self.water = self.water - self.waterUse * dt + self.food = self.food - self.foodUse * dt + self.metal = self.metal - self.metalUse * dt + self.ore = self.ore - self.oreUse * dt + self.crew = self.crew - self.crewUse * dt + + --TODO check if running out of anything, and do whatever is appropriate +end + function Resources:maxEverything() self.ammo = self.maxAmmo self.fuel = self.maxFuel diff --git a/src/ships/Ship.lua b/src/ships/Ship.lua index 9bd8326..84974f0 100644 --- a/src/ships/Ship.lua +++ b/src/ships/Ship.lua @@ -24,6 +24,7 @@ function Ship:initialize(x, y, rotation) self.dockedTo = false + self.engineStatus = "idle" self.Resources = Resources() end @@ -77,6 +78,7 @@ function Ship:moveTo(x, y) end function Ship:update(dt) + self.Resources:update(dt, self.engineStatus) --check our speed, see how far along the "line" we can go, go there -- if reached destination ... WELL SHIT DEST NEEDS TO BE ABLE TO KNOW IF IS SHIP OR WHATEVER end