示例#1
0
        /// <summary>
        /// Tests for collison of player and the invader ,and player and the invader bullets
        /// </summary>
        public override void Collision()
        {
            foreach (Control y in maingame.Controls)
            {
                if (y is PictureBox && y.Tag == "invader")
                {
                    //If player and tank intersect, ends the game entirely.
                    if (((PictureBox)y).Bounds.IntersectsWith(_tank.Bounds))
                    {
                        //Player explodes and soudn is played.
                        Explosion();
                        playersound.URL = "playerexplosion.wav";
                        playersound.controls.play();
                        if (MainGame.GodMode == false) //Implemented to prevent death if GodMode is on.
                        {
                            mechanisms.gameOver();
                        }
                    }
                }

                if (y is PictureBox && y.Tag == "enemybullet")               //if tag is a enemy bullet
                {
                    if (((PictureBox)y).Bounds.IntersectsWith(_tank.Bounds)) //if enemybullet and tank intersect
                    {
                        maingame.Controls.Remove(y);                         //removed the bullet
                        playersound.URL = "playerexplosion.wav";             //explodes the player
                        playersound.controls.play();
                        Explosion();
                        mechanisms.livesChecker(); //Manages the players lives with livesChecker()
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// This function probably should be in GameFunctions but I originaly had trouble implementing it where i wanted
        /// for some reason I discuss more in depth in my log. Ultimatelly decided to put it here and it works so I don't want to
        /// potentially break it.
        ///
        /// Creates explosions for when the bullets hit the ground and not the player. Also controls collision for the enemies and
        /// and ground. If enemies touch the ground, player loses the game. This prevents player avoiding their fire after a certain side
        /// has been removed.
        /// </summary>
        public async void GroundCollision()
        {
            foreach (Control i in this.Controls)
            {
                foreach (Control j in this.Controls)
                {
                    if (i is PictureBox && i.Tag == "enemybullet")
                    {
                        if (j is PictureBox && j.Tag == "ground")
                        {
                            if (i.Bounds.IntersectsWith(j.Bounds))
                            {
                                this.Controls.Remove(i);

                                PictureBox myexplosion = new PictureBox();
                                myexplosion.Image    = Properties.Resources.myexplosion;
                                myexplosion.Location = i.Location;
                                myexplosion.Size     = new Size(20, 20);
                                myexplosion.SizeMode = PictureBoxSizeMode.StretchImage;
                                this.Controls.Add(myexplosion);
                                myexplosion.Visible = true;

                                await Task.Delay(150);

                                myexplosion.Visible = false;
                                this.Controls.Remove(myexplosion);
                            }
                        }
                    }
                }
            }
            if (GameDone == false) //Was used in attempt to prevent the creation of multiple menus after game over. doesn't work, but it does
                                   //at least control the collision to end the game. Wish i knew why it wouldn't work though
            {
                foreach (Control i in this.Controls)
                {
                    foreach (Control j in this.Controls)
                    {
                        if (i is PictureBox && i.Tag == "invader")
                        {
                            if (j is PictureBox && j.Tag == "ground")
                            {
                                if (i.Bounds.IntersectsWith(j.Bounds))
                                {
                                    GameDone = true;
                                    mechanisms.gameOver();
                                }
                            }
                        }
                    }
                }
            }
        }