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); } } }
public void Sync(Vector2 position, Vector2 direction, float speed) { Position = position; Direction = direction; Speed = speed; SignalBus.Invoke(new BallPositionChangedSignal(this)); }
public virtual void DespawnBall() { _settingsManager.TrySaveHighscore(Score); SignalBus.Invoke(new HighscoreChangedSignal(Score)); SetScore(0); SignalBus.Invoke(new BallDespawnSignal(Ball)); SpawnBall(); }
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)); }
private void SpawnBallInternal() { Ball = new BallMultiplayer( Vector2.zero, GameDifficult.BallSize, GameDifficult.InitialBallSpeed, GameDifficult.BallSpeedIncrement); SignalBus.Invoke(new BallSpawnSignal(Ball)); }
public virtual void SpawnBall() { Ball = new Ball( Vector2.zero, GameDifficult.BallSize, GameDifficult.InitialBallSpeed, GameDifficult.BallSpeedIncrement); SignalBus.Invoke(new BallSpawnSignal(Ball)); }
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)); }
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); }
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); } }
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; } }
private void PaddleInput(int direction, float force) { SignalBus.Invoke(new MoveInputSignal(1, direction, force)); }
private void PaddleHitBall(int index, float point) { SignalBus.Invoke(new BallHitSignal(index, point)); }
public override void Exit() { _pongManager.Dispose(); SignalBus.Invoke(new MatchStopSignal()); ServiceLocator.Get <GuiManager>().CloseAll(); }
public void Sync(float pos) { Position = new Vector2(pos, Position.y); SignalBus.Invoke(new PaddlePositionChangedSignal(this)); }
protected virtual void SetScore(int value) { Score = value; SignalBus.Invoke(new ScoreChangedSignal(Score)); }