Skip to content

Commit

Permalink
Merge pull request #14 from togfoxy/WIP
Browse files Browse the repository at this point in the history
Wip
  • Loading branch information
togfoxy authored Dec 3, 2022
2 parents 8917e53 + 5992e22 commit e8269d7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 48 deletions.
4 changes: 3 additions & 1 deletion Autarky2/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function constants.load()
TRANSLATEX = cf.round(SCREEN_WIDTH / 2) -- starts the camera in the middle of the ocean
TRANSLATEY = cf.round(SCREEN_HEIGHT / 2) -- need to round because this is working with pixels
ZOOMFACTOR = 1

GAME_LOG_DRAWX = SCREEN_WIDTH - 275
MAP = {}
SHOW_GRAPH = false
Expand All @@ -34,13 +34,15 @@ function constants.load()
WORLD_HOURS = 0
WORLD_DAYS = 0
TICKER = 0 -- dt or seconds (in fractions)
PAUSED = false
SALES_TAX = 0.05
TREASURY = 0 -- govt coffers

PERSONS = {}
PERSONS_RADIUS = 7 -- for drawing and mouse click purposes
MOVEMENT_RATE = 300 -- number of pixels person moves pers second (not per dt)
VILLAGERS_SELECTED = 0
PERSONS_LEFT = 0 -- number of persons left the village (died)

STRUCTURES = {} -- any sort of tile improvement
WELLROW = 0 -- stored here for convenience and easy recall
Expand Down
18 changes: 16 additions & 2 deletions Autarky2/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ function draw.world()

-- draw world hours
love.graphics.setColor(1,1,1,1)
local str = "Time: " .. WORLD_HOURS .. " Day: " .. WORLD_DAYS .. " Treasury: " .. TREASURY
local str = "Time: " .. WORLD_HOURS .. ":00 Day: " .. WORLD_DAYS .. " Treasury: " .. TREASURY .. " "
if PAUSED then str = str .. "PAUSED" end
love.graphics.print(str, 10, 10)

-- draw villager counts
local occupationtable = people.getOccupationCount()
local str = "Farmers: " .. occupationtable[enum.jobFarmer] .. ". "
str = str .. "Healers: " .. occupationtable[enum.jobHealer] .. ". "
str = str .. "Woodsmen: " .. occupationtable[enum.jobWoodsman] .. ". "
str = str .. "Builders: " .. occupationtable[enum.jobBuilder] .. ". "
love.graphics.print(str, (SCREEN_WIDTH / 2) - 250, 10)

-- draw more counts on the far right margin
local str = "Villagers available: " .. #PERSONS .. " Villagers quit: " .. PERSONS_LEFT
love.graphics.print(str, SCREEN_WIDTH - 300, 10)


end

function draw.daynight()
Expand Down Expand Up @@ -79,7 +93,7 @@ function draw.daynight()
end

love.graphics.setColor(0,0,0,alpha)
love.graphics.rectangle("fill", 0,0, SCREEN_WIDTH, SCREEN_HEIGHT)
love.graphics.rectangle("fill", TILE_SIZE,TILE_SIZE, SCREEN_WIDTH, SCREEN_HEIGHT)

if alpha > 0 then --!
-- draw some lights
Expand Down
103 changes: 58 additions & 45 deletions Autarky2/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ function love.keyreleased( key, scancode )
if key == "escape" then
cf.RemoveScreen(SCREEN_STACK)
end
if key == "space" then
-- pause
PAUSED = not PAUSED
end


if key == "g" then
SHOW_GRAPH = not SHOW_GRAPH
end
Expand Down Expand Up @@ -133,11 +139,15 @@ end

function love.mousepressed( x, y, button, istouch, presses )
local gamex, gamey = res.toGame(x, y)
-- local wx, wy = cam:toWorld(gamex, gamey) -- converts screen x/y to world x/y
local wx, wy = cam:toWorld(x, y) -- converts screen x/y to world x/y

if button == 1 then
-- select the villager if clicked, else select the tile (further down)
for k, person in pairs(PERSONS) do
local x2, y2 = fun.getDrawXY(person)
local dist = math.abs(cf.GetDistance(gamex, gamey, x2, y2))
-- local dist = math.abs(cf.GetDistance(gamex, gamey, x2, y2))
local dist = math.abs(cf.GetDistance(wx, wy, x2, y2))

if dist <= PERSONS_RADIUS then
if person.isSelected then
Expand Down Expand Up @@ -168,7 +178,7 @@ end

function love.load()

love.window.setMode(800, 600, {resizable = true, display = 1})
love.window.setMode(800, 600, {resizable = true, display = 1, fullscreen = true})
res.setGame(1920, 1080)

SCREEN_WIDTH = 1920
Expand Down Expand Up @@ -210,63 +220,66 @@ end

function love.update(dt)

local movement = people.moveToDestination(dt)
if not PAUSED then

TICKER = TICKER + dt
if TICKER >= 1 then
TICKER = TICKER - 1
if not movement then
WORLD_HOURS = WORLD_HOURS + 1
if WORLD_HOURS == 8 then
people.assignDestination(WORLD_HOURS)
end
local movement = people.moveToDestination(dt)

if WORLD_HOURS == 20 then
people.assignDestination(WORLD_HOURS)
end
TICKER = TICKER + dt
if TICKER >= 1 then
TICKER = TICKER - 1
if not movement then
WORLD_HOURS = WORLD_HOURS + 1
if WORLD_HOURS == 8 then
people.assignDestination(WORLD_HOURS)
end

if WORLD_HOURS == 20 then
people.assignDestination(WORLD_HOURS)
end

if WORLD_HOURS >= 24 then
-- do once per day
people.heal()
structures.age()
people.buildHouse()
people.payTaxes()
people.claimSocialSecurity()
fun.RecordHistoryStock() -- record key stats for graphs etc. Do before the day ticker increments
fun.RecordHistoryTreasury()
if WORLD_HOURS >= 24 then
-- do once per day
people.heal()
structures.age()
people.buildHouse()
people.payTaxes()
people.claimSocialSecurity()
fun.RecordHistoryStock() -- record key stats for graphs etc. Do before the day ticker increments
fun.RecordHistoryTreasury()


WORLD_HOURS = WORLD_HOURS - 24
WORLD_DAYS = WORLD_DAYS + 1
WORLD_HOURS = WORLD_HOURS - 24
WORLD_DAYS = WORLD_DAYS + 1

MARKET_RESOLVED = false -- reset this every midnight
MARKET_RESOLVED = false -- reset this every midnight

-- print("Person 1 belief history (food and herbs)")
-- print(inspect(PERSONS[1].beliefRangeHistory[enum.stockFood]))
-- print(inspect(PERSONS[1].beliefRangeHistory[enum.stockHerbs]))
-- print("Person 1 belief history (food and herbs)")
-- print(inspect(PERSONS[1].beliefRangeHistory[enum.stockFood]))
-- print(inspect(PERSONS[1].beliefRangeHistory[enum.stockHerbs]))
end
end
end

-- pay time
if WORLD_HOURS == 17 then
people.pay()
end
-- pay time
if WORLD_HOURS == 17 then
people.pay()
end

-- dinner time
if WORLD_HOURS == 18 then
print("Nom")
people.eat()
end
-- dinner time
if WORLD_HOURS == 18 then
print("Nom")
people.eat()
end

if WORLD_HOURS == 19 then
-- market time
if not MARKET_RESOLVED then
people.doMarketplace()
MARKET_RESOLVED = true
if WORLD_HOURS == 19 then
-- market time
if not MARKET_RESOLVED then
people.doMarketplace()
MARKET_RESOLVED = true
end
end
end
end

cam:setPos(TRANSLATEX, TRANSLATEY)
cam:setZoom(ZOOMFACTOR)
res.update()
Expand Down
21 changes: 21 additions & 0 deletions Autarky2/people.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function people.draw()
if person.isSelected then
quad = QUADS[enum.spriteRedWoman][2]
spritenumber = enum.spriteRedWoman

love.graphics.circle("line", drawx, drawy + 7, PERSONS_RADIUS + 5)

else
quad = QUADS[enum.spriteBlueWoman][2]
spritenumber = enum.spriteBlueWoman
Expand Down Expand Up @@ -263,6 +266,7 @@ function people.dies(person, reason)
if PERSONS[i] == person then
table.remove(PERSONS, i)
print("Person died. Reason = " .. reason)
PERSONS_LEFT = PERSONS_LEFT + 1
end
end
end
Expand Down Expand Up @@ -524,5 +528,22 @@ function people.claimSocialSecurity()
end
end

function people.getOccupationCount()

local result = {}
result[enum.jobFarmer] = 0
result[enum.jobHealer] = 0
result[enum.jobBuilder] = 0
result[enum.jobWoodsman] = 0

for _, person in pairs(PERSONS) do
local occupation = person.occupation -- e.g enum.jobFarmer
if occupation ~= nil then
result[occupation] = result[occupation] + 1
end
end
return result
end


return people

0 comments on commit e8269d7

Please sign in to comment.