diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-02-08 11:24:51 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-02-08 11:24:51 +0100 |
commit | eea642395bb0ef706c7241d4a749f3e0ac4cc460 (patch) | |
tree | 6c015c9315b0102247661f942b018ccf8c45551d /scripts/wave.gd | |
parent | e8b2ea6b2bf789b7942d86faebbcc4d810741f25 (diff) |
revised wave generation
Diffstat (limited to 'scripts/wave.gd')
-rw-r--r-- | scripts/wave.gd | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/scripts/wave.gd b/scripts/wave.gd index e61dfef..691b703 100644 --- a/scripts/wave.gd +++ b/scripts/wave.gd @@ -10,6 +10,8 @@ var ongoing = false var load_shapes : Node var gui : Node +var rng = RandomNumberGenerator.new() + func fetch (): var root = get_tree().root.get_node("world") var saveload = root.get_node("saveload") @@ -22,7 +24,8 @@ func make_queue (spawn): for n in order.amount: var e = { "cooldown": order.cooldown, - "enemy": order.enemy + "enemy": order.enemy, + "hp": order.hp } queue += [e] if spawn.random: queue.shuffle() @@ -50,25 +53,40 @@ func get_affordable_enemies (hp_budget : int): if load_shapes.info[enemy].cost <= hp_budget: aff += [load_shapes.info[enemy]] return aff + +func sort_aff_comp(a, b): return a.cost < b.cost -func pick_enemy (hp_budget : int): +func pick_enemy (hp_budget : int, density : float, height: float): var amt = 1 var aff = get_affordable_enemies(hp_budget) - var enemy = aff[randi() % aff.size()] + aff.sort_custom(self, "sort_aff_comp") + + #var rn = rng.randf() + #var pick : float = pow(rn, 2*height*(1-rn) + rn) + var enemy = aff[round(height * (aff.size()-1))] + + var cooldown : float = rng.randf() * pow(4, density - 0.5) + + var hp_adjusted = max(1, enemy.lives * height) + var cost = enemy.cost - enemy.lives + hp_adjusted + + print(cost) + var order = { "amount" : amt, "enemy": enemy.name, - "cooldown": 0.5 + "hp": hp_adjusted, + "cooldown": cooldown } - return { "enemy": order, "cost": enemy.cost } + return { "enemy": order, "cost": cost } -func gen_wave (wave_num : int): +func gen_wave (wave_num : int, density : float, height: float): var hp_budget = get_hp_budget(wave_num) var enemies = [] for i in range(0, 1000): if hp_budget < 10: break - var enemy_cost = pick_enemy(hp_budget) + var enemy_cost = pick_enemy(hp_budget, density, height) enemies += [ enemy_cost.enemy ] hp_budget -= enemy_cost.cost @@ -82,10 +100,11 @@ func gen_wave (wave_num : int): func start(): fetch() + rng.randomize() ongoing = true var w = null if wave_num <= waves.size()-1: w = waves[wave_num] - else: w = gen_wave(wave_num) + else: w = gen_wave(wave_num, 0.5, 0.2) start_wave(w) func end(): |