made fruits drop less when there are too many on screen

main
Artur David 2026-06-02 08:34:03 +02:00
parent e7e0e2ce9f
commit 7fe0990949
1 changed files with 8 additions and 1 deletions

View File

@ -34,8 +34,15 @@ func on_enemy_died(enemy):
func drop_item(enemy): func drop_item(enemy):
if not is_instance_valid(enemy): if not is_instance_valid(enemy):
return return
var fruit_count = get_children().filter(func(c): return c is DropsBase).size()
for entry in enemy.drop_table: for entry in enemy.drop_table:
if randf() < entry.chance: var effective_chance = entry.chance
if fruit_count >= fruit_drop_ceiling:
continue
elif fruit_count > fruit_drop_threshold:
var scale = 1.0 - float(fruit_count - fruit_drop_threshold) / float(fruit_drop_ceiling - fruit_drop_threshold)
effective_chance *= scale
if randf() < effective_chance:
var drop = entry.drop.instantiate() var drop = entry.drop.instantiate()
drop.global_position = enemy.global_position drop.global_position = enemy.global_position
add_child(drop) add_child(drop)