コード例 #1
0
ファイル: Ball.cs プロジェクト: Niller/Pong
    public virtual void Update(float deltaTime)
    {
        var deltaMove = Direction * deltaTime * Speed;

        Position += deltaMove;

        SignalBus.Invoke(new BallPositionChangedSignal(this));

        if (_postDeath)
        {
            _postDeathFlyLength -= deltaMove.magnitude;

            if (_postDeathFlyLength < 0)
            {
                PongManager.DespawnBall();
            }
            return;
        }

        //Wall collision
        if (Position.x >= 1 - Size || Position.x <= -1 + Size)
        {
            Direction = new Vector2(-Direction.x, Direction.y);
        }

        //Paddle collision
        if (Position.y >= 1 - Size || Position.y <= -1 + Size)
        {
            if (!PongManager.HandleCollision(this, out var newDirection))
            {
                _postDeath = true;
            }

            Speed    += _speedIncrement;
            Direction = newDirection;
        }
    }