From 00cdb68a8134da3227ef4f3ddf682018971a955a Mon Sep 17 00:00:00 2001 From: Nicholas Hayashi Date: Tue, 30 Mar 2021 22:37:05 -0400 Subject: [PATCH] better spawn rates --- conf.lua | 2 +- src/game.lua | 20 +++++++++++++++++--- src/mob.lua | 3 ++- src/tower.lua | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/conf.lua b/conf.lua index cea3ce0..bcdde05 100644 --- a/conf.lua +++ b/conf.lua @@ -2,7 +2,7 @@ title = "hexyz" author = "nick hayashi" shortname = "hexyz" -version = "0.1.1" +version = "0.1.2" support_email = "" copyright_message = "Copyright © 2021 Nick Hayashi" diff --git a/src/game.lua b/src/game.lua index fd9d5b4..06d3548 100644 --- a/src/game.lua +++ b/src/game.lua @@ -108,6 +108,12 @@ end local function game_deserialize(json_string) -- @TODO decode from some compressed format or whatever local new_state = am.parse_json(json_string) + + if new_state.version ~= version then + log("loading old save data.") + return nil + end + new_state.map, new_state.world = random_map(new_state.seed) new_state.seed = nil @@ -221,7 +227,8 @@ local function game_action(scene) state.spawning = true -- calculate spawn chance for next wave - state.spawn_chance = math.log(state.current_wave)/2 + 0.002 + state.spawn_chance = math.log(state.current_wave)/100 + 0.002 + log(state.spawn_chance) state.time_until_next_break = get_wave_time(state.current_wave) end @@ -580,7 +587,7 @@ local function game_scene() state.current_wave = state.current_wave + 1 -- calculate spawn chance for next wave - state.spawn_chance = math.log(state.current_wave)/2 + 0.002 + state.spawn_chance = math.log(state.current_wave)/100 + 0.002 state.time_until_next_break = state.time_until_next_break + get_break_time(state.current_wave) @@ -624,7 +631,8 @@ local function game_scene() ) :tag"game" - scene:action(game_action) + -- dangling actions run before the main action + scene:late_action(game_action) return scene end @@ -647,6 +655,12 @@ function game_init(saved_state) if saved_state then state = game_deserialize(saved_state) + if not state then + -- failed to load a save + win.scene:append(main_scene(true, true)) + return + end + -- @HACK fixes a bug where loading game state with a tower type selected, -- but you don't have a built tower cursor node, so hovering a buildable tile throws an error select_tower_type(nil) diff --git a/src/mob.lua b/src/mob.lua index d3da9af..81dee55 100644 --- a/src/mob.lua +++ b/src/mob.lua @@ -221,7 +221,8 @@ local function update_mob_spooder(mob, mob_index) if mob_can_pass_through(mob, mob.frame_target) then local from = hex_map_get(state.map, mob.hex) local to = hex_map_get(state.map, mob.frame_target) - local rate = math.abs(from.elevation - to.elevation) + 0.01 * mob.speed * am.delta_time + local spider_speed = ((math.simplex(mob.hex) + 1.5) * 1.5) ^ 2 + local rate = (spider_speed * mob.speed - math.abs(to.elevation - from.elevation)) * am.delta_time mob.position = mob.position + math.normalize(hex_to_pixel(mob.frame_target, vec2(HEX_SIZE)) - mob.position) * rate mob.node.position2d = mob.position diff --git a/src/tower.lua b/src/tower.lua index 853e3c1..6195d45 100644 --- a/src/tower.lua +++ b/src/tower.lua @@ -434,7 +434,7 @@ function update_tower_lighthouse(tower, tower_index) local mobs = mobs_on_hex(h) for _,m in pairs(mobs) do - if not m.path then + if not m.path and not m.seen_lighthouse then -- @TODO only attract the mob if its frame target (direction vector) -- is within some angle range...? if the mob is heading directly away from the tower, then -- the lighthouse shouldn't do much @@ -443,6 +443,7 @@ function update_tower_lighthouse(tower, tower_index) if made_it then m.path = path + m.seen_lighthouse = true --[[ local area = spiral_map(tower.hex, tower.range)