예제 #1
0
        public void UpdateState()
        {
            for (var i = 0; i < CountWallsInStage; i++)
            {
                var currentWall = Walls.Dequeue();
                currentWall.Location -= Velocity;

                if (currentWall.Location < -Setting.WidthWall)
                {
                    var lastWall    = Walls.Last();
                    var startWindow = random.Next(Setting.HeightWindowOfWall + 10, HeightWindow - 10);
                    var newWall     = new Wall(lastWall.Location + IntervalBetweenWalls, startWindow);
                    Walls.Enqueue(newWall);
                }
                else
                {
                    Walls.Enqueue(currentWall);
                }
            }

            FlappyBird.UpdatePosition();
            UpdateScore();

            if (FlappyBird.LocationY >= HeightWindow - Setting.HeightBird)
            {
                FlappyBird.UpdatePosition(Setting.StartPosition, HeightWindow - Setting.HeightBird - 5);
                StateChanged?.Invoke(true);
                IsGameOver = true;
                return;
            }

            foreach (var wall in Walls)
            {
                if (IsСollisionBirdInWall(wall))
                {
                    var pointCollision = GetPointCollision(wall);
                    FlappyBird.UpdatePosition(pointCollision.X, pointCollision.Y);
                    StateChanged?.Invoke(true);
                    IsGameOver = true;
                    return;
                }
            }

            StateChanged?.Invoke(false);
        }