Example #1
0
        private void DoLogic()
        {
            #region VARIABLES
            List <Shoot>      listShoot          = new List <Shoot>();
            List <Shoot>      listCollShoot      = new List <Shoot>();
            List <Invasor>    listCollInvasor    = new List <Invasor>();
            List <Background> listCollBackground = new List <Background>();
            Tank    collTank     = null;
            Ufo     collUfo      = null;
            int     countInvasor = 0;
            Invasor invasorDied  = null;
            #endregion

            foreach (GameComponent gc in Components)
            {
                if (gc is Shoot)
                {
                    if (((Shoot)gc).die)
                    {
                        listCollShoot.Add((Shoot)gc);
                    }
                    else
                    {
                        listShoot.Add((Shoot)gc);
                    }
                }
                if (gc is Invasor)
                {
                    countInvasor++;
                    if (((Invasor)gc).die)
                    {
                        invasorDied = ((Invasor)gc);
                    }
                }
            }

            if (countInvasor == 1 &&
                invasorDied != null)
            {
                listCollInvasor.Add(invasorDied);
            }

            foreach (GameComponent gc in Components)
            {
                foreach (Shoot sh in listShoot)
                {
                    #region TANK
                    if (gc is Tank)
                    {
                        if (sh.collisionRect.Intersects(((Tank)gc).collisionRectOffset) && !((Tank)gc).die)
                        {
                            collTank = (Tank)gc;
                            listCollShoot.Add(sh);
                        }
                        if (!((Tank)gc).enable && ((Tank)gc).die)
                        {
                            collTank = (Tank)gc;
                        }
                    }

                    #endregion

                    #region INVASOR
                    if (gc is Invasor)
                    {
                        if (sh.collisionRect.Intersects(((Invasor)gc).collisionRectOffset) &&
                            !((Invasor)gc).die &&
                            !((Invasor)gc).shooted)
                        {
                            ((Invasor)gc).shooted = true;
                            listCollInvasor.Add((Invasor)gc);
                            listCollShoot.Add(sh);
                        }
                        if (!((Invasor)gc).enable && ((Invasor)gc).die)
                        {
                            listCollInvasor.Add((Invasor)gc);
                        }
                    }
                    #endregion

                    #region BACKGROUND
                    if (gc is Background)
                    {
                        if (sh.collisionRect.Intersects(((Background)gc).collisionRect))
                        {
                            listCollBackground.Add((Background)gc);
                            listCollShoot.Add(sh);
                        }
                    }
                    #endregion

                    #region UFO
                    if (gc is Ufo)
                    {
                        if (sh.collisionRect.Intersects(((Ufo)gc).collisionRectOffset) && !((Ufo)gc).die)
                        {
                            collUfo = (Ufo)gc;
                            listCollShoot.Add(sh);
                        }
                        if (!((Ufo)gc).enable && ((Ufo)gc).die)
                        {
                            collUfo  = (Ufo)gc;
                            ufoBonus = true;
                        }
                    }
                    #endregion

                    #region SHOOT
                    if (gc is Shoot)
                    {
                        if (sh.collisionRect.Intersects(((Shoot)gc).collisionRect) &&
                            sh.position != ((Shoot)gc).position)
                        {
                            listCollShoot.Add(sh);
                            listCollShoot.Add((Shoot)gc);
                        }
                    }
                    #endregion
                }
            }

            #region INTERSECTIONS
            if (collTank != null)
            {
                player.Intesects(collTank);
            }
            if (listCollInvasor.Count > 0)
            {
                foreach (Invasor ivr in listCollInvasor)
                {
                    invasorsManager.Intesects(ivr, listCollInvasor);
                }
            }
            if (listCollBackground.Count > 0)
            {
                foreach (Background bg in listCollBackground)
                {
                    backgoundManager.Intesects(bg);
                }
            }
            if (listCollShoot.Count > 0)
            {
                foreach (Shoot sh in listCollShoot)
                {
                    sh.Intesects();
                }
            }
            if (collUfo != null)
            {
                ufo.Intesects(collUfo);
            }
            #endregion
        }