Ejemplo n.º 1
0
        /*****************************************************
         * Name: George Trieu
         * Date: 2018-06-08
         * Title: Destroy
         * Purpose: Function used to destroy itself
         * Inputs: none
         * Returns: none
         ****************************************************/
        public void Destroy()
        {
            ArrayList al = BasePair.FindBasePair(Form1.shootingAt, this);

            foreach (BasePair bp in al)
            {
                Form1.shootingAt.Remove(bp);
            }
            Form1.towers.Remove(this);
        }
Ejemplo n.º 2
0
        /*****************************************************
         * Name: George Trieu
         * Date: 2018-06-08
         * Title: CheckEnemies
         * Purpose: Function to detect enemy collisions, and act on them
         * Inputs: none
         * Returns: none
         ****************************************************/
        public virtual void CheckEnemies()
        {
            //ToDo optomize checkEnemies, check whether there is more enemies or towers, and use that to check the rest.
            foreach (BaseEnemy be in Form1.enemies)
            {
                bool collision = false;
                if (be.GetHealth() <= 0)
                {
                    Form1.cash += be.GetReward();
                    be.Destroy();

                    break;
                }

                int xDiff = Math.Abs(loc.X + 15 - be.GetLocation().X);
                int yDiff = Math.Abs(loc.Y + 15 - be.GetLocation().Y);
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        be.SetHealth(be.GetHealth() - damage);
                        if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Add(new BasePair(this, be));
                        }

                        if (path != null)
                        {
                            var sound = new System.Windows.Media.MediaPlayer();
                            sound.Open(new Uri(path, UriKind.Relative));
                            sound.Play();
                        }
                        break;
                    }

                    collision = true;
                }

                xDiff = Math.Abs(loc.X + 15 - (be.GetLocation().X + 31));
                yDiff = Math.Abs(loc.Y + 15 - be.GetLocation().Y);
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        be.SetHealth(be.GetHealth() - damage);
                        if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Add(new BasePair(this, be));
                        }

                        if (path != null)
                        {
                            var sound = new System.Windows.Media.MediaPlayer();
                            sound.Open(new Uri(path, UriKind.Relative));
                            sound.Play();
                        }
                        break;
                    }

                    collision = true;
                }

                xDiff = Math.Abs(loc.X + 15 - (be.GetLocation().X + 31));
                yDiff = Math.Abs(loc.Y + 15 - (be.GetLocation().Y + 31));
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        be.SetHealth(be.GetHealth() - damage);
                        if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Add(new BasePair(this, be));
                        }

                        if (path != null)
                        {
                            var sound = new System.Windows.Media.MediaPlayer();
                            sound.Open(new Uri(path, UriKind.Relative));
                            sound.Play();
                        }
                        break;
                    }

                    collision = true;
                }

                xDiff = Math.Abs(loc.X + 15 - be.GetLocation().X);
                yDiff = Math.Abs(loc.Y + 15 - (be.GetLocation().Y + 31));
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        be.SetHealth(be.GetHealth() - damage);
                        if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Add(new BasePair(this, be));
                        }

                        if (path != null)
                        {
                            var sound = new System.Windows.Media.MediaPlayer();
                            sound.Open(new Uri(path, UriKind.Relative));
                            sound.Play();
                        }
                        break;
                    }

                    collision = true;
                }

                //else there is no collision
                //Checks if the enemy has left the radius
                if (!collision)
                {
                    if (Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                    {
                        Form1.shootingAt.Remove(BasePair.FindBasePair(Form1.shootingAt, this, be));
                    }
                }
            }

            if (cycle >= shootRate)
            {
                cycle = 0;
            }
            else
            {
                cycle++;
            }
        }
Ejemplo n.º 3
0
        /*****************************************************
         * Name: George Trieu
         * Date: 2018-06-08
         * Title: CheckEnemies
         * Purpose: Method used to check collisions and act on them
         * Inputs: none
         * Returns: none
         ****************************************************/
        public override void CheckEnemies()
        {
            foreach (BaseEnemy be in Form1.enemies)
            {
                bool collision = false;
                int  xDiff     = Math.Abs(loc.X + 15 - be.GetLocation().X);
                int  yDiff     = Math.Abs(loc.Y + 15 - be.GetLocation().Y);
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        if (be.GetFrozenTicks() <= 0)
                        {
                            if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                            {
                                Form1.shootingAt.Add(new BasePair(this, be));
                            }
                            if (path != null)
                            {
                                var sound = new System.Windows.Media.MediaPlayer();
                                sound.Open(new Uri(path, UriKind.Relative));
                                sound.Play();
                            }

                            be.SetFrozenTicks(100);
                            break;
                        }
                    }

                    if (be.GetFrozenTicks() <= 0)
                    {
                        if (Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Remove(BasePair.FindBasePair(Form1.shootingAt, this, be));
                        }
                    }

                    collision = true;
                }

                xDiff = Math.Abs(loc.X + 15 - (be.GetLocation().X + 31));
                yDiff = Math.Abs(loc.Y + 15 - be.GetLocation().Y);
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        if (be.GetFrozenTicks() <= 0)
                        {
                            if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                            {
                                Form1.shootingAt.Add(new BasePair(this, be));
                            }
                            if (path != null)
                            {
                                var sound = new System.Windows.Media.MediaPlayer();
                                sound.Open(new Uri(path, UriKind.Relative));
                                sound.Play();
                            }

                            be.SetFrozenTicks(100);
                            break;
                        }
                    }

                    if (be.GetFrozenTicks() <= 0)
                    {
                        if (Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Remove(BasePair.FindBasePair(Form1.shootingAt, this, be));
                        }
                    }

                    collision = true;
                }

                xDiff = Math.Abs(loc.X + 15 - (be.GetLocation().X + 31));
                yDiff = Math.Abs(loc.Y + 15 - (be.GetLocation().Y + 31));
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        if (be.GetFrozenTicks() <= 0)
                        {
                            if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                            {
                                Form1.shootingAt.Add(new BasePair(this, be));
                            }
                            if (path != null)
                            {
                                var sound = new System.Windows.Media.MediaPlayer();
                                sound.Open(new Uri(path, UriKind.Relative));
                                sound.Play();
                            }

                            be.SetFrozenTicks(100);
                            break;
                        }
                    }

                    if (be.GetFrozenTicks() <= 0)
                    {
                        if (Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Remove(BasePair.FindBasePair(Form1.shootingAt, this, be));
                        }
                    }

                    collision = true;
                }

                xDiff = Math.Abs(loc.X + 15 - be.GetLocation().X);
                yDiff = Math.Abs(loc.Y + 15 - (be.GetLocation().Y + 31));
                if (Math.Pow(radius, 2) >= (Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)))
                {
                    if (cycle >= shootRate)
                    {
                        if (be.GetFrozenTicks() <= 0)
                        {
                            if (!Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                            {
                                Form1.shootingAt.Add(new BasePair(this, be));
                            }
                            if (path != null)
                            {
                                var sound = new System.Windows.Media.MediaPlayer();
                                sound.Open(new Uri(path, UriKind.Relative));
                                sound.Play();
                            }

                            be.SetFrozenTicks(100);
                            break;
                        }
                    }

                    if (be.GetFrozenTicks() <= 0)
                    {
                        if (Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                        {
                            Form1.shootingAt.Remove(BasePair.FindBasePair(Form1.shootingAt, this, be));
                        }
                    }

                    collision = true;
                }

                //else there is no collision
                //Checks if the enemy has left the radius
                if (!collision)
                {
                    if (Form1.shootingAt.Contains(BasePair.FindBasePair(Form1.shootingAt, this, be)))
                    {
                        Form1.shootingAt.Remove(BasePair.FindBasePair(Form1.shootingAt, this, be));
                    }
                }
            }

            if (cycle >= shootRate)
            {
                cycle = 0;
            }
            else
            {
                cycle++;
            }
        }