Esempio n. 1
0
        public CountDownState GetCountDownState()
        {
            var res = new CountDownState()
            {
                Countdown = false
            };

            if (gameState == resetBall)
            {
                resetBallAction(ballStartX, ballStartY);
            }
            if (gameState >= startCountDown && gameState < endCountDown)
            {
                res.Countdown = true;
                if (TryGetBallWall(out var tuple))
                {
                    res.StrokeThickness = tuple.radius - (Constants.ballWallLen * (gameState - startCountDown) / ((double)(endCountDown - startCountDown)));
                    res.Radius          = tuple.radius;
                    res.BallOpacity     = gameState > resetBall ? (gameState - resetBall) / (double)(endCountDown - resetBall) : ((resetBall - startCountDown) - (gameState - startCountDown)) / (double)(resetBall - startCountDown);
                    res.X = tuple.x;
                    res.Y = tuple.y;
                }
                else
                {
                    throw new Exception("bug");
                }
            }
            if (gameState == endCountDown)
            {
                gameState = play;
            }
            return(res);
        }
Esempio n. 2
0
 public GameStateUpdate(Collision[] collisions, GoalScored[] goalsScored, Player[] players, Ball ball, int frame, CountDownState countDownState, int leftScore, int rightScore)
 {
     this.Collisions  = collisions ?? throw new ArgumentNullException(nameof(collisions));
     this.GoalsScored = goalsScored ?? throw new ArgumentNullException(nameof(goalsScored));
     this.Players     = players ?? throw new ArgumentNullException(nameof(players));
     this.Ball        = ball ?? throw new ArgumentNullException(nameof(ball));
     this.Frame       = frame;
     CountDownState   = countDownState;
     this.LeftScore   = leftScore;
     this.RightScore  = rightScore;
 }
Esempio n. 3
0
        //public static void Handle(this GameState gameState, UpdateFrameEvent evnt)
        //{
        //    if (evnt.frame > gameState.frame)
        //    {
        //        gameState.frame = evnt.frame;

        //        foreach (var update in evnt.updatePlayers)
        //        {
        //            if (gameState.players.TryGetValue(update.Id, out var player))
        //            {
        //                player.body.position = update.bodyPosition;
        //                player.body.velocity = update.bodyVelocity;
        //                player.foot.position = update.footPosition;
        //                player.foot.velocity = update.footVelocity;
        //                player.externalVelocity = update.externalVelocity;
        //            }
        //        }

        //        gameState.ball.velocity = evnt.updateBall.velocity;
        //        gameState.ball.posistion = evnt.updateBall.posistion;

        //        gameState.CountDownState.Countdown = evnt.updateCountDown.countdown;
        //        gameState.CountDownState.BallOpacity = evnt.updateCountDown.ballOpacity;
        //        gameState.CountDownState.Radius = evnt.updateCountDown.radius;
        //        gameState.CountDownState.StrokeThickness = evnt.updateCountDown.strokeThickness;
        //        gameState.CountDownState.X = evnt.updateCountDown.posistion.x;
        //        gameState.CountDownState.Y = evnt.updateCountDown.posistion.y;
        //        if (evnt.goalScored != null)
        //        {
        //            GameStateUpdater.Handle(gameState,evnt.goalScored);
        //        }

        //        foreach (var collision in evnt.collisions)
        //        {
        //            gameState.collisions.Add(collision);
        //        }
        //    }
        //}
        public static void Handle(this GameState gameState, CountDownState countDownState)
        {
            gameState.CountDownState = countDownState;
        }