pond.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. extends Area2D
  2. const Fish = preload("res://scenes/fish/fish.tscn")
  3. const DiseasedFish = preload("res://scenes/fish/diseased_fish/diseased_fish.tscn")
  4. @onready var fishes = $Fishes
  5. var is_initing = false
  6. var radius : int = 200
  7. var center : Vector2 = Vector2(576,324)
  8. var normal_fish_count : int = 0
  9. func clear_fishes() -> void:
  10. normal_fish_count = 0
  11. for fish in fishes.get_children():
  12. fish.queue_free()
  13. func contains_normal_fish() -> bool:
  14. if normal_fish_count == 0:
  15. return false
  16. else:
  17. return true
  18. func spawn_fishes(fishes_count: Vector2) -> void:
  19. normal_fish_count = fishes_count.x
  20. for i in fishes_count.x: #normal
  21. spawn_fish(true)
  22. for i in fishes_count.y: #diseased
  23. spawn_fish(false)
  24. is_initing = false
  25. func spawn_fish(normal : bool) -> void:
  26. var fish
  27. if normal:
  28. fish = Fish.instantiate()
  29. else:
  30. fish = DiseasedFish.instantiate()
  31. fish.area_entered.connect(randomise_position)
  32. randomise_position(fish)
  33. fishes.add_child(fish)
  34. func randomise_position(fish: Node2D) -> void:
  35. var x = randi_range(center.x - radius, center.x + radius)
  36. var y = randi_range(center.y - radius, center.y + radius)
  37. fish.position = Vector2(x, y)
  38. #Globals.fish_collecte
  39. #print(contains_normal_fishes())