Skip to content

Commit

Permalink
Hotfixed creeper effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderv committed Apr 23, 2018
1 parent 36f02bc commit a4984d3
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 7 deletions.
4 changes: 2 additions & 2 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ end

DEBUG = true
STATE = {
properties = { population = 0, money = 50 },
properties = { population = 0, money = -50 },
buildings = {
{ x = 1, y = 1, building = "small_park" },
},
hand = {},
discardPile = { "small_office", "small_generator", "small_residential"},
drawPile = {},
drawPile = {"loan"},
currentTurnEffects = {},
cars = {},
helis = {},
Expand Down
3 changes: 2 additions & 1 deletion scripts/helpers/calculations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ local nameChanger = {
nuisance = {"Nuisance", 1},
relaxation = {"Relaxation", 1},
housing = {"Housing", 1},
power = {"Nuisance", 1},
power = {"Power", 1},
money_per_turn = {"Money per turn", 1},
draw = {"Hand limit: ", 1},
}
Expand All @@ -92,6 +92,7 @@ function z.requirementToString(requirement)
if requirement.type == "resource" then
--{ type = "resource", property = "power", relation = "gt", value = 5 }
local row = (nameChanger[requirement.property])
if not row then print(requirement.property) end
return row[1] .. " " .. opTable[requirement.relation] .. " " .. row[2]*requirement.value
end
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/rendering/renderUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end
R.drawMessage = function(message)
love.graphics.rectangle("fill", 300, 538, 766, 30)
love.graphics.setColor(0, 0, 0)
love.graphics.print(message, 330, 548)
love.graphics.print(message, 320, 538)
love.graphics.setColor(1, 1, 1)
end
local iconOffset = function(index)
Expand Down
136 changes: 136 additions & 0 deletions scripts/states/creeperEffect.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
--
-- Created by IntelliJ IDEA.
-- User: nander
-- Date: 21/04/2018
-- Time: 18:03
-- To change this template use File | Settings | File Templates.
--

--
-- Created by IntelliJ IDEA.
-- User: nander
-- Date: 21/04/2018
-- Time: 18:25
-- To change this template use File | Settings | File Templates.
--

local menu = {} -- previously: Gamestate.new()
menu.name = "runCard"

function menu:enter(prev, state, cardIndex, card)
menu.prev = prev
menu.state = state
menu.card = cardIndex
menu.cardData = card or STATE.hand[cardIndex]
menu.showing = "costs"
menu.item = 1
menu.time = 0
menu.fromHand = not card
menu.cardDone = false
menu.cardEnding = false
end

local effects = {}
effects.add_cost = {
exec = function(card, index)
local c = scripts.gameobjects.cards[menu.cardData]

if c.costs and c.costs.type then
STATE.properties[c.costs.type] = STATE.properties[c.costs.type] - c.costs.value
end
end,
draw = function(card, index, time)
end,
duration = 1,
small = false,
}
effects.add_card = {
exec = function(card, index)
local c = scripts.gameobjects.cards[menu.cardData]
local effect = c.effects[index]
STATE.discardPile[#STATE.discardPile + 1] = effect.card
end,
draw = function(c, index, time)
scripts.rendering.renderCard.renderCard(scripts.gameobjects.cards[c.effects[index].card], 1210 - 1200 * (0.5 - time), 568 - 800 * (0.5 - time), 0.5)
end,
duration = 0.5,
small = false,
}
effects.place_building = {
exec = function(card, index)
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,
duration = 0,
small = true,
}
effects.next_turn = {
exec = function(card, index)
local c = scripts.gameobjects.cards[STATE.hand[card]]
local effect = c.effects[index]
table.insert(STATE.currentTurnEffects, table.clone(effect))
end,
draw = function(card, index, time) end,
duration = 0,
small = true,
}

effects.resource = {
exec = function(card, index)
pprint(STATE.currentTurnEffects)
local c = scripts.gameobjects.cards[menu.cardData]
local effect = c.effects[index]
-- pprint(STATE.properties)
-- pprint(effect)
STATE.properties[effect.resource] = STATE.properties[effect.resource] + effect.value
end,
draw = function(card, index, time)
end,
duration = 0.5,
small = false,
}

menu.effects = effects
function menu:update(dt, wait)
menu.prev:update(dt, true)
end

function menu:draw()
menu.prev:draw(true)
love.graphics.push()
love.graphics.scale(GLOBSCALE())
scripts.rendering.renderUI.drawCard(menu.state, menu.cardData, false, true)

if scripts.gameobjects.cards[menu.cardData].is_creeper then
scripts.rendering.renderUI.drawMessage("Drew creeper .. " .. scripts.gameobjects.cards[menu.cardData].name .. "; a disaster occured.")
end
if menu.showing == "effects" then
effects[scripts.gameobjects.cards[menu.cardData].effects[menu.item].type].draw(scripts.gameobjects.cards[menu.cardData], menu.item, menu.time)
end
love.graphics.pop()
end

function menu:mousepressed(x, y, click)
if click == 1 then
Gamestate.pop()
for item = 1, #scripts.gameobjects.cards[menu.cardData].effects do
effects[scripts.gameobjects.cards[menu.cardData].effects[item].type].exec(menu.cardData, item)
end
else
scripts.rendering.renderUI.mousePressed(x, y, click)
end
end

function menu:mousereleased(x, y, mouse_btn)
scripts.rendering.renderUI.mouseReleased(x, y, mouse_btn)
end

function menu:wheelmoved(x, y)
scripts.rendering.renderUI.wheelmoved(x, y)
end

return menu
7 changes: 5 additions & 2 deletions scripts/states/dealHand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ local menu = {} -- previously: Gamestate.new()
menu.name = "dealHand"
function menu:enter(prev)
menu.prev = prev
menu.counter = 0
menu.counter = -1
-- setup entities here
end

function menu:update(dt, bo)
scripts.rendering.renderUI.updateMove(dt)
if not bo then
if menu.counter == #STATE.hand then Gamestate.switch(scripts.states.playCards) end
if #STATE.hand >= scripts.helpers.gamerules.getCardDraw(STATE) then
Gamestate.switch(scripts.states.playCards)
return
end
menu.counter = #STATE.hand
Gamestate.push(scripts.states.drawCard)
menu.counter = menu.counter + 1
end
end

function menu:draw(bo)
scripts.rendering.renderMapView.draw(LOWEST)
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/states/drawCard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function menu:update(dt, bo)
if not card:verifyRequirements(STATE) then
Gamestate.push(scripts.states.creeperNothingHappened, STATE, nil, c)
else
Gamestate.push(scripts.states.runCard, STATE, nil, c)
Gamestate.push(scripts.states.creeperEffect, STATE, nil, c)
end
table.remove(STATE.drawPile, 1)
else
Expand Down

0 comments on commit a4984d3

Please sign in to comment.