LeapingCheepCheep.gd 809 B

123456789101112131415161718192021222324252627
  1. extends Enemy
  2. func _ready() -> void:
  3. direction = sign(get_viewport().get_camera_2d().get_screen_center_position().x - global_position.x)
  4. velocity.x = randf_range(50, 200) * direction
  5. velocity.y = randf_range(-250, -350)
  6. $Sprite.scale.x = direction
  7. setup_line()
  8. if Settings.file.audio.extra_sfx == 1:
  9. AudioManager.play_sfx("cheep_cheep", global_position)
  10. func setup_line() -> void:
  11. $Line2D.clear_points()
  12. var line_velocity = velocity
  13. var line_position = $Sprite.global_position
  14. for i in 200:
  15. line_position += line_velocity * 0.016
  16. line_velocity.y += (5 / 0.016) * 0.016
  17. $Line2D.add_point(line_position)
  18. func _physics_process(delta: float) -> void:
  19. velocity.y += (5 / delta) * delta
  20. $Line2D.remove_point(0)
  21. if global_position.y > 64 and velocity.y > 0:
  22. queue_free()
  23. move_and_slide()