Beispiel #1
0
        public void Update(float deltaTime)
        {
            var force = DefaultForce * deltaTime;

            if (UnityEngine.Input.GetKey(KeyCode.RightArrow))
            {
                SignalBus.Invoke(new MoveInputSignal(0, 1, force));
                if (!ServiceLocator.Get <PongManager>().IsMultiplayer)
                {
                    SignalBus.Invoke(new MoveInputSignal(1, 1, force));
                }
                else
                {
                    ServiceLocator.Get <NetworkGameManager>().CallPaddleInput(1, force);
                }
            }

            if (UnityEngine.Input.GetKey(KeyCode.LeftArrow))
            {
                SignalBus.Invoke(new MoveInputSignal(0, -1, force));
                if (!ServiceLocator.Get <PongManager>().IsMultiplayer)
                {
                    SignalBus.Invoke(new MoveInputSignal(1, -1, force));
                }
                else
                {
                    ServiceLocator.Get <NetworkGameManager>().CallPaddleInput(-1, force);
                }
            }
        }
Beispiel #2
0
    public void Sync(Vector2 position, Vector2 direction, float speed)
    {
        Position  = position;
        Direction = direction;
        Speed     = speed;

        SignalBus.Invoke(new BallPositionChangedSignal(this));
    }
Beispiel #3
0
    public virtual void DespawnBall()
    {
        _settingsManager.TrySaveHighscore(Score);
        SignalBus.Invoke(new HighscoreChangedSignal(Score));
        SetScore(0);

        SignalBus.Invoke(new BallDespawnSignal(Ball));
        SpawnBall();
    }
Beispiel #4
0
    protected virtual void OnMoveInput(MoveInputSignal data)
    {
        if (data.Arg1 != Index)
        {
            return;
        }

        Position = new Vector2(Mathf.Clamp(Position.x + data.Arg2 * data.Arg3, -1f + Length, 1f - Length), Position.y);
        SignalBus.Invoke(new PaddlePositionChangedSignal(this));
    }
Beispiel #5
0
    private void SpawnBallInternal()
    {
        Ball = new BallMultiplayer(
            Vector2.zero,
            GameDifficult.BallSize,
            GameDifficult.InitialBallSpeed,
            GameDifficult.BallSpeedIncrement);

        SignalBus.Invoke(new BallSpawnSignal(Ball));
    }
Beispiel #6
0
    public virtual void SpawnBall()
    {
        Ball = new Ball(
            Vector2.zero,
            GameDifficult.BallSize,
            GameDifficult.InitialBallSpeed,
            GameDifficult.BallSpeedIncrement);

        SignalBus.Invoke(new BallSpawnSignal(Ball));
    }
Beispiel #7
0
        public override void Enter()
        {
            _inputSystem = ServiceLocator.Get <IInputSystem>();
            ServiceLocator.Get <GuiManager>().Open(GuiViewType.Match, true);

            var difficult = (int)FsmManager.GetBlackboardValue("Difficult");

            _pongManager = CreatePongManager();
            _pongManager.Initialize(ServiceLocator.Get <SettingsManager>().Config.Difficulties[difficult]);
            _pongManager.SpawnPaddles();
            _pongManager.SpawnBall();

            SignalBus.Invoke(new GameStartedSignal(_pongManager.Paddle1, _pongManager.Paddle2));
        }
Beispiel #8
0
    public virtual bool HandleCollision(Ball ball, out Vector2 newDirection)
    {
        if (!CheckCollision(ball, out var relativeIntersect, out var currentPaddle))
        {
            newDirection = ball.Direction;
            return(false);
        }

        SetScore(Score + 1);

        SignalBus.Invoke(new BallHitSignal(currentPaddle.Index, relativeIntersect));
        newDirection = new Vector2(relativeIntersect * BounceCoefficient, -ball.Direction.y).normalized;

        return(true);
    }
Beispiel #9
0
        public void Update(float deltaTime)
        {
            if (UnityEngine.Input.touchCount <= 0)
            {
                return;
            }

            var delta     = UnityEngine.Input.GetTouch(0).deltaPosition;
            var direction = (int)Mathf.Sign(delta.x);
            var force     = Mathf.Abs(delta.x / Screen.width) * Speed * deltaTime;

            SignalBus.Invoke(new MoveInputSignal(0, direction, force));

            if (!ServiceLocator.Get <PongManager>().IsMultiplayer)
            {
                SignalBus.Invoke(new MoveInputSignal(1, direction, force));
            }
            else
            {
                ServiceLocator.Get <NetworkGameManager>().CallPaddleInput(direction, force);
            }
        }
Beispiel #10
0
    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;
        }
    }
Beispiel #11
0
 private void PaddleInput(int direction, float force)
 {
     SignalBus.Invoke(new MoveInputSignal(1, direction, force));
 }
Beispiel #12
0
 private void PaddleHitBall(int index, float point)
 {
     SignalBus.Invoke(new BallHitSignal(index, point));
 }
Beispiel #13
0
 public override void Exit()
 {
     _pongManager.Dispose();
     SignalBus.Invoke(new MatchStopSignal());
     ServiceLocator.Get <GuiManager>().CloseAll();
 }
Beispiel #14
0
 public void Sync(float pos)
 {
     Position = new Vector2(pos, Position.y);
     SignalBus.Invoke(new PaddlePositionChangedSignal(this));
 }
Beispiel #15
0
 protected virtual void SetScore(int value)
 {
     Score = value;
     SignalBus.Invoke(new ScoreChangedSignal(Score));
 }