37 lines
732 B
C#
37 lines
732 B
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Bucket : Node2D
|
|
{
|
|
|
|
[Signal]
|
|
public delegate void BallEnteredEventHandler(Ball BALL);
|
|
public int _minX = -500, _maxX = 500, _movementSign = 1, _movementSpeed = 3;
|
|
public Vector2 _startPoisition;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
_startPoisition = GlobalPosition;
|
|
}
|
|
|
|
|
|
public void Move()
|
|
{
|
|
GlobalPosition += new Vector2(_movementSign * _movementSpeed, 0);
|
|
Vector2 offset = _startPoisition - GlobalPosition;
|
|
if (offset.X >= _maxX || offset.X <= _minX)
|
|
{
|
|
_movementSign *= -1;
|
|
}
|
|
}
|
|
public void OnBodyEntered(Node2D BODY)
|
|
{
|
|
if (BODY is Ball ball)
|
|
{
|
|
EmitSignal(SignalName.BallEntered, ball);
|
|
ball.EnteredBucket();
|
|
}
|
|
}
|
|
}
|