game.gd 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. extends Node2D
  2. @onready var net = $net
  3. @onready var fishes_store = $Fishes
  4. @onready var pond = $pond
  5. const Fish = preload("res://scenes/fish/fish.tscn")
  6. const Diseased_Fish = preload("res://scenes/fish/diseased_fish/diseased_fish.tscn")
  7. var radius : int = 200
  8. var center : Vector2 = Vector2(576,324)
  9. var target_point : Vector2 = Vector2(576,44)
  10. var fishes_count : Vector2 = Vector2(2, 1)
  11. var is_queud_respawn : bool = false
  12. var is_initing = false
  13. func _ready() -> void:
  14. Globals.normal_fish_collected.connect(on_normal_fish_collected)
  15. Globals.diseased_fish_collected.connect(on_diseased_fish_collected)
  16. pond.spawn_fishes(fishes_count)
  17. func _draw() -> void:
  18. draw_circle(target_point, 10, Color.YELLOW)
  19. func _physics_process(delta: float) -> void:
  20. if not net.is_moving:
  21. rotate_target_point(delta)
  22. if Input.is_action_just_pressed("player_action"):
  23. net.move(target_point)
  24. if is_queud_respawn:
  25. pond.clear_fishes()
  26. fishes_count += Vector2(1, 1)
  27. pond.spawn_fishes(fishes_count)
  28. is_queud_respawn = false
  29. func rotate_target_point(delta: float) -> void:
  30. target_point = center + (target_point - center).rotated(deg_to_rad(90)*delta)
  31. queue_redraw()
  32. func _on_fishes_child_exiting_tree(fish: Node) -> void:
  33. #check diseased_fish
  34. if not is_initing:
  35. if fish is DiseasedFish:
  36. is_initing = true
  37. reload()
  38. return
  39. #check end
  40. var is_playing = false
  41. for fish_ in fishes_store.get_children():
  42. if not fish_ is DiseasedFish and fish != fish_:
  43. is_playing = true
  44. # if not is_playing:
  45. # if is_adding_normal:
  46. # fishes_count.y +=1
  47. # else:
  48. # fishes_count.x += 1
  49. # is_adding_normal = not is_adding_normal
  50. # is_initing = true
  51. #clear_fishes()
  52. #spawn_fishes.call_deferred()
  53. return
  54. func reload() -> void:
  55. net.position = Vector2(576,44)
  56. target_point = Vector2(576,44)
  57. fishes_count = Vector2(2, 1)
  58. #is_adding_normal = false
  59. #clear_fishes()
  60. #spawn_fishes.call_deferred()
  61. func respawn_fishes() -> void:
  62. is_initing = true
  63. #clear_fishes()
  64. #spawn_fishes.call_deferred()
  65. set_deferred("is_initing", false)
  66. func on_normal_fish_collected() -> void:
  67. pond.normal_fish_count -= 1
  68. if not pond.contains_normal_fish():
  69. is_queud_respawn = true
  70. func on_diseased_fish_collected() -> void:
  71. get_tree().reload_current_scene()