Nicholas Hayashi 4 years ago
parent
commit
0cc62960ad
  1. 36
      src/game.lua
  2. 8
      src/mob.lua
  3. 30
      src/tower.lua

36
src/game.lua

@ -84,23 +84,15 @@ local function get_top_right_display_text(hex, evenq, centered_evenq, display_ty
end end
-- initialized later, as part of the init of the toolbelt -- initialized later, as part of the init of the toolbelt
function select_tower_type(tower_type) end
function select_toolbelt_button(i)
state.selected_toolbelt_button = i
if i <= 10 then
select_tower_type(i)
else
select_tower_type(nil)
end
end
local function select_tower_type(tower_type) end
local function select_toolbelt_button(i) end
local function get_wave_time(current_wave) local function get_wave_time(current_wave)
return 15
return 90
end end
local function get_break_time(current_wave) local function get_break_time(current_wave)
return 90
return 15
end end
function do_day_night_cycle() function do_day_night_cycle()
@ -150,7 +142,7 @@ local function game_action(scene)
state.current_wave = state.current_wave + 1 state.current_wave = state.current_wave + 1
state.spawning = false state.spawning = false
state.time_until_next_wave = get_wave_time(state.current_wave)
state.time_until_next_wave = get_break_time(state.current_wave)
end end
else else
state.time_until_next_wave = state.time_until_next_wave - am.delta_time state.time_until_next_wave = state.time_until_next_wave - am.delta_time
@ -159,7 +151,7 @@ local function game_action(scene)
state.time_until_next_wave = 0 state.time_until_next_wave = 0
state.spawning = true state.spawning = true
state.time_until_next_break = get_break_time(state.current_wave)
state.time_until_next_break = get_wave_time(state.current_wave)
end end
end end
@ -224,9 +216,9 @@ local function game_action(scene)
elseif WIN:key_pressed"tab" then elseif WIN:key_pressed"tab" then
if WIN:key_down"lshift" then if WIN:key_down"lshift" then
select_toolbelt_button((state.selected_toolbelt_button + 12 - 2) % 12 + 1)
select_toolbelt_button((state.selected_toolbelt_button + table.count(TOWER_TYPE) - 2) % table.count(TOWER_TYPE) + 1)
else else
select_toolbelt_button((state.selected_toolbelt_button) % 12 + 1)
select_toolbelt_button((state.selected_toolbelt_button) % table.count(TOWER_TYPE) + 1)
end end
elseif WIN:key_pressed"1" then select_toolbelt_button(1) elseif WIN:key_pressed"1" then select_toolbelt_button(1)
elseif WIN:key_pressed"2" then select_toolbelt_button(2) elseif WIN:key_pressed"2" then select_toolbelt_button(2)
@ -354,7 +346,7 @@ local function make_game_toolbelt()
TOWER_TYPE.RADAR, TOWER_TYPE.RADAR,
TOWER_TYPE.LIGHTHOUSE TOWER_TYPE.LIGHTHOUSE
} }
for i = 1, #keys do
for i,v in pairs(tower_type_values) do
local icon_texture = get_tower_icon_texture(tower_type_values[i]) local icon_texture = get_tower_icon_texture(tower_type_values[i])
toolbelt:append( toolbelt:append(
toolbelt_button( toolbelt_button(
@ -394,6 +386,16 @@ local function make_game_toolbelt()
end end
end end
select_toolbelt_button = function(i)
state.selected_toolbelt_button = i
if tower_type_values[i] then
select_tower_type(i)
else
select_tower_type(nil)
end
end
return toolbelt return toolbelt
end end

8
src/mob.lua

@ -33,13 +33,15 @@ function get_mob_spec(mob_type)
end end
local function grow_mob_health(mob_type, spec_health, time) local function grow_mob_health(mob_type, spec_health, time)
return spec_health * math.log(time)
return spec_health * (time / 100 + 1)
end end
local function grow_mob_speed(mob_type, spec_speed, time) local function grow_mob_speed(mob_type, spec_speed, time)
return spec_speed
-- @TODO maybe speed shouldn't grow with time at all.
-- if it does, a small amount with a horizontal asymptote
return spec_speed --* math.abs(math.log(time / 100))
end end
local function grow_mob_bounty(mob_type, spec_speed, time) local function grow_mob_bounty(mob_type, spec_speed, time)
return spec_speed * math.log(time)
return spec_speed * (time / 100 + 1)
end end
function mobs_on_hex(hex) function mobs_on_hex(hex)

30
src/tower.lua

@ -112,7 +112,7 @@ function get_tower_fire_rate(tower_type)
return TOWER_SPECS[tower_type].fire_rate return TOWER_SPECS[tower_type].fire_rate
end end
function get_tower_size(tower_type) function get_tower_size(tower_type)
return TOWER_SPECS[tower_type.size]
return TOWER_SPECS[tower_type].size
end end
local function make_tower_sprite(tower_type) local function make_tower_sprite(tower_type)
@ -212,15 +212,24 @@ end
function towers_on_hex(hex) function towers_on_hex(hex)
local t = {} local t = {}
for tower_index,tower in pairs(TOWERS) do for tower_index,tower in pairs(TOWERS) do
if tower and tower.hex == hex then
if tower then
for _,h in pairs(tower.hexes) do
if h == hex then
table.insert(t, tower_index, tower) table.insert(t, tower_index, tower)
break
end
end
end end
end end
return t return t
end end
function tower_on_hex(hex) function tower_on_hex(hex)
return table.find(TOWERS, function(tower) return tower.hex == hex end)
return table.find(TOWERS, function(tower)
for _,h in pairs(tower.hexes) do
if h == hex then return true end
end
end)
end end
function tower_type_is_buildable_on(hex, tile, tower_type) function tower_type_is_buildable_on(hex, tile, tower_type)
@ -229,8 +238,17 @@ function tower_type_is_buildable_on(hex, tile, tower_type)
-- @TODO remove this shit -- @TODO remove this shit
if hex == HEX_GRID_CENTER then return false end if hex == HEX_GRID_CENTER then return false end
local blocking_towers = towers_on_hex(hex)
local blocking_mobs = mobs_on_hex(hex)
local blocking_towers = {}
local blocking_mobs = {}
for _,h in pairs(spiral_map(hex, get_tower_size(tower_type))) do
table.append(blocking_towers, towers_on_hex(hex))
table.append(blocking_mobs, mobs_on_hex(hex))
end
if WIN:key_down"space" then
log(table.tostring(blocking_towers))
end
local towers_blocking = table.count(blocking_towers) ~= 0 local towers_blocking = table.count(blocking_towers) ~= 0
local mobs_blocking = table.count(blocking_mobs) ~= 0 local mobs_blocking = table.count(blocking_mobs) ~= 0
@ -403,6 +421,8 @@ function make_and_register_tower(hex, tower_type)
tower.range = spec.range tower.range = spec.range
tower.fire_rate = spec.fire_rate tower.fire_rate = spec.fire_rate
tower.last_shot_time = -spec.fire_rate tower.last_shot_time = -spec.fire_rate
tower.size = spec.size
tower.hexes = spiral_map(tower.hex, tower.size)
if tower_type == TOWER_TYPE.REDEYE then if tower_type == TOWER_TYPE.REDEYE then
local tile = state.map.get(hex.x, hex.y) local tile = state.map.get(hex.x, hex.y)

Loading…
Cancel
Save