public static bool isAlone(SightBonus sight)
 {
     for (int i = 0; i < Game1.smile.allSmiles.Count(); i++)
     {
         if (isCollision(sight.Position, Game1.smile.allSmiles[i].Position))
             return false;
     }
     for (int i = 0; i < Game1.sightBonus.allSightBonuses.Count(); i++)
     {
         if ((sight != Game1.sightBonus.allSightBonuses[i]) && isCollision(sight.Position, Game1.sightBonus.allSightBonuses[i].Position))
             return false;
     }
     for (int i = 0; i < Game1.lifeBonus.allLifeBonuses.Count(); i++)
     {
         if (isCollision(sight.Position, Game1.lifeBonus.allLifeBonuses[i].Position))
             return false;
     }
     for (int i = 0; i < Game1.choiceBonus.allChoiceBonuses.Count(); i++)
     {
         if (isCollision(sight.Position, Game1.choiceBonus.allChoiceBonuses[i].Position))
             return false;
     }
     return true;
 }
        public bool Create(int i, int j)
        {
            int color = rand.Next(0, 10);

            SightBonus sight = new SightBonus(TextureLoad.Eye, new Rectangle(i * Size, j * Size, Size, Size), Size, Size, new Vector2(i * Size, j * Size));
            if (color == (int)bonusType.EYE && (j == 0 || !isAlone(sight)))
            {
                allSightBonuses.Add(sight);
                return true;
            }
            return false;
        }
Exemple #3
0
        void createSight()
        {
            drawSight = false;

            sight = new SightBonus(TextureLoad.Sight, new Rectangle(background.Width / 2 - sizeOfSmile / 2, background.Height - sizeOfSmile - 15, sizeOfSmile, sizeOfSmile), sizeOfSmile, sizeOfSmile, new Vector2(background.Width / 2 - sizeOfSmile / 2, background.Height - sizeOfSmile - 15));
            sight.IsMove = true;
        }
        public bool isCollision(ref SightBonus bonus, Smile currSmile)
        {
            float deltaX = bonus.Position.X - currSmile.Position.X;
            float deltaY = bonus.Position.Y - currSmile.Position.Y;
            double r = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);

            if (r <= Size)
            {
                double k = Size / r;
                float newX = currSmile.Position.X * (1 - (float)k) + bonus.Position.X * (float)k;
                float newY = currSmile.Position.Y * (1 - (float)k) + bonus.Position.Y * (float)k;
                bonus.Position = new Vector2(newX, newY);
                bonus.Rectangle = new Rectangle((int)newX, (int)newY, bonus.Rectangle.Width, bonus.Rectangle.Height);

                return true;
            }

            return false;
        }
Exemple #5
0
        public static void newGame()
        {
            setConstants();

            amountOfShot = 0;

            smile = new Smile();
            lifeBonus = new LifeBonus();
            choiceBonus = new ChoiceBonus();
            sightBonus = new SightBonus();

            for (int i = 0; i < maxNumInRow; i++)
                for (int j = 0; j < maxNumInCol; j++)
                {
                    if (smile.Create(i, j)) ;
                    else if (heartIsAvailable && lifeBonus.Create(i, j));
                    else if (sightIsAvailable && choiceBonus.Create(i, j));
                    else if (palmIsAvailable && sightBonus.Create(i, j));
                }

            bullet = new Bullet();
            bullet.Create();

            nextBullet = new Bullet();
            nextBullet.Create();
            nextBullet.Position = new Vector2(140, ScreenSize.Y - sizeOfSmile - 20);
        }