WindGenerator.gd 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. extends EntityGenerator
  2. @export_range(1, 8, 1) var wind_force := 4
  3. @export_enum("Right" , "Left") var wind_direction := 0
  4. func _ready() -> void:
  5. await get_tree().create_timer(0.1, false).timeout
  6. get_parent().move_child(self, 0)
  7. func _physics_process(delta: float) -> void:
  8. [$CanvasLayer/Left, $CanvasLayer/Right][wind_direction].show()
  9. for i in [$CanvasLayer/Left/Particles, $CanvasLayer/Right/Particles]:
  10. i.emitting = active
  11. i.speed_scale = float(wind_force) / 4
  12. i.amount = wind_force * 16
  13. if active:
  14. for i: Player in get_tree().get_nodes_in_group("Players"):
  15. if i.spring_bouncing == false and i.is_on_wall() == false and i.state_machine.state.name == "Normal":
  16. i.simulated_velocity.x = wind_force * [1, -1][wind_direction]
  17. i.global_position.x += ((wind_force * 10) * [1, -1][wind_direction]) * delta
  18. if $SFX.is_playing() == false:
  19. $SFX.play()
  20. else:
  21. $SFX.stop()
  22. func activate() -> void:
  23. if not active:
  24. active = true
  25. func deactivate_all_generators() -> void:
  26. for i in get_tree().get_nodes_in_group("EntityGenerators"):
  27. i.active = false