Ejemplo n.º 1
0
        private void CheckCollisions()
        {
            List <Fish> fishToRemoveList = new List <Fish>();


            //check for collisions with the fish in the list
            foreach (var fish in _fishes)
            {
                if (fish.IsOffScreen(_GameWindow))
                {
                    fishToRemoveList.Add(fish);
                }

                if (_Player.CollideWith(fish) && _Player.CheckScale() >= fish._FishBitmap.CellHeight)
                {
                    _fishEaten.Add(fish);
                    _score.Add(fish);
                    fishToRemoveList.Add(fish);
                    var biteSound = new SoundEffect("bite", "./resources/sounds/bite.wav");
                    SplashKit.LoadSoundEffect("bite", "./resources/sounds/bite.wav");

                    SplashKit.PlaySoundEffect("bite");

                    switch (_fishEaten.Count)
                    {
                    case 1:
                        _Player._PlayerBitmap = new Bitmap("playerMedium", "./Resources/images/Small/Guppy Medium Sick right.png");    //

                        SplashKit.DrawBitmap("playerMedium", _Player.X, _Player.Y);
                        break;

                    case 5:
                        _Player._PlayerBitmap = new Bitmap("playerLarge", "./Resources/images/Small/Guppy Large Sick right.png");    //

                        SplashKit.DrawBitmap("playerLarge", _Player.X, _Player.Y);
                        break;

                    case 7:
                        _Player._PlayerBitmap = new Bitmap("playerMedium2", "./Resources/images/Large/Guppy Small Sick right.png");    //

                        SplashKit.DrawBitmap("playerMedium2", _Player.X, _Player.Y);
                        break;

                    case 10:
                        _Player._PlayerBitmap = new Bitmap("playerMedium3", "./Resources/images/Large/Guppy Medium Sick right.png");

                        SplashKit.DrawBitmap("playerMedium3", _Player.X, _Player.Y);
                        break;

                    case 12:
                        _Player._PlayerBitmap = new Bitmap("playerMedium4", "./Resources/images/Large/Guppy Large Sick right.png");

                        SplashKit.DrawBitmap("playerMedium4", _Player.X, _Player.Y);
                        break;

                    case 18:
                        _Player._PlayerBitmap = new Bitmap("playerPredator", "./Resources/images/Large/Predator Sick right.png");

                        SplashKit.DrawBitmap("playerPredator", _Player.X, _Player.Y);
                        break;
                    }
                }

                if (_Player.CollideWith(fish) && _Player.CheckScale() < fish._FishBitmap.CellHeight)
                {
                    int remove = Math.Min(_fishEaten.Count, 2);
                    _fishEaten.RemoveRange(0, remove);



                    if (_fishEaten.Count == 0)
                    {
                        _Player._PlayerBitmap = new Bitmap("DeadFish", "./Resources/images/Large/Guppy Small Dead.png");

                        SplashKit.DrawBitmap("DeadFish", _Player.X, _Player.Y);
                        SplashKit.LoadMusic("endMusic", "./resources/sounds/endmusic.mp3");

                        var font = SplashKit.LoadFont("Hand Scribble Sketch Times",
                                                      "./resources/fonts/Hand Scribble Sketch Times.otf");

                        SplashKit.PlayMusic("endMusic");
                        SplashKit.DisplayDialog("gameover", ($"Game Over Your Score is {_score.Count}"), font, 25);

                        _Player.Quit = true;
                    }
                    else
                    {
                        _Player._PlayerBitmap = new Bitmap("Small", "./Resources/images/Small/Guppy Small Sick right.png");

                        SplashKit.DrawBitmap("Small", _Player.X, _Player.Y);
                    }
                }
            }

            foreach (var fish in fishToRemoveList)
            {
                _fishes.Remove(fish);
            }
        }