Esempio n. 1
0
        void ManagePipes()
        {
            if (!Pipes.Any() || Pipes.Last().DistanceFromleft <= 250)
            {
                Pipes.Add(new PipeModel());
            }

            if (Pipes.First().IsOffScreen())
            {
                Pipes.Remove(Pipes.First());
            }
        }
Esempio n. 2
0
        private void ManagePipes()
        {
            if (!Pipes.Any() || Pipes.Last().DistanceFromLeft < GameWidth / 2)
            {
                Pipes.Add(new PipeModel(GameWidth));
            }

            if (Pipes.First().IsOffScreen())
            {
                Pipes.Remove(Pipes.First());
            }
        }
Esempio n. 3
0
        private void ManagePipes()
        {
            if (Pipes.Count == 0 || Pipes.Last().DistanceFromLeft <= 250)
            {
                Pipes.Add(new PipeModel());
            }

            if (Pipes[0].IsOffScreen())
            {
                Pipes.Remove(Pipes[0]);
            }
        }
Esempio n. 4
0
        public void ManagePipes()
        {
            //if the list of pipes don't have any objects in it...
            //OR if the last pipe in the list is halfway across the screen...
            if (!Pipes.Any() || Pipes.Last().DistanceFromLeft <= 250)
            {
                //add another pipe to the list
                Pipes.Add(new PipeModel());
            }

            //if it is true that the first pipe in the list if off the screen...
            if (Pipes.First().IsOffScreen())
            {
                //remove the pipe from the list of pipes
                Pipes.Remove(Pipes.First());
            }
        }
Esempio n. 5
0
        public async void MainLoop()
        {
            IsRunning = true;

            while (IsRunning)
            {
                Bird.Fall(_gravity);

                foreach (var pipe in Pipes)
                {
                    pipe.Move(_speed);
                }

                var centeredPipe = GetCenteredPipe();
                if (centeredPipe != null)
                {
                    var min = 300 - 150 + centeredPipe.DistanceFromBottom;
                    var max = 430 - 150 + centeredPipe.DistanceFromBottom - 45;

                    if (Bird.DistanceFromBottom < min || Bird.DistanceFromBottom > max)
                    {
                        GameOver();
                    }
                }

                if (!Pipes.Any() || Pipes.Last().DistanceFromLeft < 250)
                {
                    GeneratePipe();
                }

                if (Pipes.First().DistanceFromLeft < -60)
                {
                    Pipes.Remove(Pipes.First());
                }

                await Task.Delay(20); // wait 20ms
            }
        }