Ball.cs 566 B

123456789101112131415161718192021222324252627282930
  1. using Godot;
  2. public partial class Ball : Area2D
  3. {
  4. private const int DefaultSpeed = 100;
  5. public Vector2 direction = Vector2.Left;
  6. private Vector2 _initialPos;
  7. private float _speed = DefaultSpeed;
  8. public override void _Ready()
  9. {
  10. _initialPos = Position;
  11. }
  12. public override void _Process(float delta)
  13. {
  14. _speed += delta * 2;
  15. Position += _speed * delta * direction;
  16. }
  17. public void Reset()
  18. {
  19. direction = Vector2.Left;
  20. Position = _initialPos;
  21. _speed = DefaultSpeed;
  22. }
  23. }