Skip to content

Commit

Permalink
Adds tax collection to the game, added some fixes to some card change…
Browse files Browse the repository at this point in the history
… logic.
  • Loading branch information
nanderv committed Apr 23, 2018
1 parent f9413a8 commit 59c19be
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end

DEBUG = true
STATE = {
properties = { population = 0, money = 40 },
properties = { population = 0, money = 50 },
buildings = {
{ x = 1, y = 1, building = "small_park" },
},
Expand Down
13 changes: 13 additions & 0 deletions scripts/gameobjects/buildings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ buildings.start = {
},
}

buildings.taxCollection = {
name = "Tax Collection",
size = { x = 1, y = 1 },
asset = "tax_building",
effects = {
{
type = "resource",
resource = "money_per_turn",
value = -10,
},
},
}

for k, v in pairs(buildings) do
v.key = k
function v:build(state)
Expand Down
4 changes: 2 additions & 2 deletions scripts/gameobjects/cards.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ cards.loan = {
value = 100,
},
{
type = "add_card",
card="payback",
type = "place_building",
building="taxCollection",
},
},
requirements = {{type="resource", property="money", relation="lt", value=-10}},
Expand Down
30 changes: 28 additions & 2 deletions scripts/rendering/renderMapView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ mapView.draw = function(lowest)
end

local objects = {}

local x, y = scripts.helpers.calculations.getCoordinatesFromScreenPosition(love.mouse.getPosition())
local b = scripts.helpers.calculations.hasBuilding(STATE, x, y)
if b and b.building then
-- calculate neighbours with adjacency
for _, effect in ipairs(scripts.gameobjects.buildings[b.building].effects) do
if effect.type == "adjacent" then
for _, i in ipairs({ -1, 0, 1 }) do
for _, j in ipairs({ -1, 0, 1 }) do
local zf = scripts.helpers.calculations.hasBuilding(STATE, x + i, y + j)
if zf then
local keepTrack = false
for _, filter in ipairs(effect.filter) do
keepTrack = keepTrack or filter == zf.building
end
zf = keepTrack
end
if not (i == 0 and j == 0) and zf then
objects[#objects + 1] = { position = { x = (b.x + i) * 64 + 32, y = (b.y + j) * 64, z = 0, r = 0 }, texture = "normalCursor" }
end
end
end
end
end
end

for _, v in pairs(helis) do
if math.floor(v.timer) == 0 then
objects[#objects + 1] = { position = { x = v.x * 64 + 32, y = v.y * 64, z = 60, r = v.direction * math.pi / 2 }, texture = "heli1" }
Expand All @@ -60,7 +86,7 @@ mapView.draw = function(lowest)

love.graphics.push()
love.graphics.scale(GLOBSCALE())
love.graphics.setColor(167/256, 188/256, 119/256)
love.graphics.setColor(167 / 256, 188 / 256, 119 / 256)
love.graphics.rectangle("fill", 0, 0, 1366, 768)
love.graphics.setColor(1, 1, 1)
for _, v in ipairs(STATE.cars) do
Expand All @@ -79,7 +105,7 @@ mapView.draw = function(lowest)
end
if CAMERA.focus then
local v = CAMERA.focus
if not scripts.helpers.calculations.hasBuilding(STATE, CAMERA.focus.x, CAMERA.focus.y) and scripts.helpers.calculations.neighbouring(STATE, CAMERA.focus.x, CAMERA.focus.y) then
if not b and scripts.helpers.calculations.neighbouring(STATE, CAMERA.focus.x, CAMERA.focus.y) then
objects[#objects + 1] = { position = { x = v.x * 64 + 32, y = v.y * 64, z = 0, r = (v.x * 3 * v.y * 5) % 4 * math.pi / 2 }, texture = "underConstruction" }
else

Expand Down
1 change: 0 additions & 1 deletion scripts/rendering/renderUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ R.drawBuilding = function(state)
local x, y = scripts.helpers.calculations.getCoordinatesFromScreenPosition(love.mouse.getPosition())
local b = scripts.helpers.calculations.hasBuilding(state, x, y)
if CAMERA.buildingFocus then

b = { building = CAMERA.buildingFocus }
end

Expand Down
10 changes: 8 additions & 2 deletions scripts/states/runCard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function menu:enter(prev, state, cardIndex, card)
menu.item = 1
menu.time = 0
menu.fromHand = not card
menu.cardDone = false
menu.cardEnding = false
end

local effects = {}
Expand Down Expand Up @@ -56,9 +58,11 @@ effects.add_card = {
}
effects.place_building = {
exec = function(card, index)
print("HERE")
local c = scripts.gameobjects.cards[menu.cardData]
local effect = c.effects[index]
scripts.gameobjects.buildings[effect.building]:build(STATE)
menu.cardEnding = true
end,
draw = function(card, index, time)
end,
Expand Down Expand Up @@ -128,8 +132,10 @@ function menu:update(dt, wait)
table.remove(STATE.hand, menu.card)
end
end
if not scripts.gameobjects.cards[menu.cardData].is_creeper then
if not scripts.gameobjects.cards[menu.cardData].is_creeper or menu.cardEnding then
Gamestate.pop()
else
menu.cardDone = true
end
end
end
Expand All @@ -151,7 +157,7 @@ function menu:draw()
end

function menu:mousepressed(x, y, click)
if scripts.gameobjects.cards[menu.cardData].is_creeper then
if scripts.gameobjects.cards[menu.cardData].is_creeper and menu.cardDone then
Gamestate.pop()
else
scripts.rendering.renderUI.mousePressed(x, y, click)
Expand Down

0 comments on commit 59c19be

Please sign in to comment.