Browse Source

tweak spawn chance

master
Nicholas Hayashi 4 years ago
parent
commit
51d9027de4
  1. 16
      main.lua
  2. 12
      src/game.lua
  3. 24
      src/mob.lua

16
main.lua

@ -65,12 +65,18 @@ function make_main_scene_toolbelt()
false,
{
texture = TEXTURES.NEW_GAME_HEX,
action = function() game_init() end
action = function()
win.scene:remove"menu"
game_init()
end
},
false,
{
texture = TEXTURES.LOAD_GAME_HEX,
action = function() game_init(am.load_state("save", "json")) end
action = function()
win.scene:remove"menu"
game_init(am.load_state("save", "json"))
end
},
false,
false,
@ -191,9 +197,11 @@ function main_scene(do_backdrop)
group:action(main_action)
return group
return group:tag"menu"
end
win.scene = main_scene(true)
win.scene = am.group(
main_scene(true)
)
noglobals()

12
src/game.lua

@ -23,7 +23,7 @@ local TRDTS = {
}
local function get_initial_game_state(seed)
local STARTING_MONEY = 100000
local STARTING_MONEY = 200
-- 2014
local map, world = random_map()
@ -45,7 +45,8 @@ local function get_initial_game_state(seed)
time_until_next_wave = 0,
time_until_next_break = 0,
spawning = false,
spawn_chance = 55,
spawn_chance = 0.01,
last_mob_spawn_time = 0,
selected_tower_type = false,
selected_toolbelt_button = false,
@ -117,7 +118,7 @@ end
local function game_pause()
win.scene("game").paused = true
win.scene:append(main_scene(false):tag"pause_menu")
win.scene:append(main_scene(false))
end
local function game_deserialize(json_string)
@ -213,8 +214,6 @@ local function game_action(scene)
state.time = state.time + am.delta_time
state.score = state.score + am.delta_time
state.spawn_chance = math.clamp(state.spawn_chance - math.floor(state.time / 100), 1, 25)
if state.spawning then
state.time_until_next_break = state.time_until_next_break - am.delta_time
@ -231,6 +230,9 @@ local function game_action(scene)
if state.time_until_next_wave <= 0 then
state.time_until_next_wave = 0
-- calculate spawn chance for next wave
state.spawn_chance = (state.current_wave + 1)/200
state.spawning = true
state.time_until_next_break = get_wave_time(state.current_wave)
end

24
src/mob.lua

@ -40,8 +40,8 @@ local function grow_mob_speed(mob_type, spec_speed, time)
-- if it does, a small amount with a horizontal asymptote
return spec_speed --* math.abs(math.log(time / 100))
end
local function grow_mob_bounty(mob_type, spec_speed, time)
return spec_speed * (time / 100 + 1)
local function grow_mob_bounty(mob_type, spec_bounty, time)
return spec_bounty * (time / 100 + 1)
end
function mobs_on_hex(hex)
@ -313,9 +313,25 @@ function mob_deserialize(json_string)
return mob
end
function do_mob_spawning(spawn_chance)
local function can_spawn_mob()
local MAX_SPAWN_RATE = 0.1
if not state.spawning or (state.time - state.last_mob_spawn_time) < MAX_SPAWN_RATE then
return false
end
if math.random() <= state.spawn_chance then
--log('yes %f', state.spawn_chance)
state.last_mob_spawn_time = state.time
return true
else
--log('no %f', state.spawn_chance)
return false
end
end
function do_mob_spawning()
--if win:key_pressed"space" then
if state.spawning and math.random(spawn_chance) == 1 then
if can_spawn_mob() then
--if #state.mobs < 1 then
make_and_register_mob(MOB_TYPE.BEEPER)
end

Loading…
Cancel
Save