コード例 #1
0
ファイル: Spawner.cs プロジェクト: Whojoo/Bubble-popper
        /// <summary>
        /// Adds a ScoreBall to the game.
        /// </summary>
        /// <param name="portal"></param>
        private void AddBall()
        {
            ScoreBall ball;
            int lastInGraveyard = graveyard.Count - 1;

            //Do we need an enemy?
            bool isEnemy = enemies == 0 || (int)(friendlies / enemies) >= friendliesPerEnemies;

            //Get the right portal.
            SpawnPortal portal = GetNextPortal(isEnemy);

            //Get a ScoreBall from the graveyard or create a new one.
            if (lastInGraveyard >= 0)
            {
                ball = graveyard[lastInGraveyard];
                graveyard.RemoveAt(lastInGraveyard);
                ball.Remove = false;
                ball.Position = portal.GetSpawnPosition();
            }
            else
            {
                ball = new ScoreBall(Game, portal.GetSpawnPosition(),
                    Sinusoid.GetInstance().GetRandomIndex());
            }

            try
            {
                Game.GetActiveScreen().Components.Add(ball);
                active.Add(ball);
                ball.Initialize();

                //Do we need a friendly?
                if (!isEnemy)
                {
                    ball.ChangeState(ScoreBall.State.Friendly);
                    friendlies++;
                }
                //We need an enemy.
                else
                {
                    ball.ChangeState(ScoreBall.State.Enemy);
                    enemies++;
                }
            }
            catch (ArgumentException e)
            {
            }
        }
コード例 #2
0
ファイル: Spawner.cs プロジェクト: Whojoo/Bubble-popper
        /// <summary>
        /// Removes a ScoreBall from the active list.
        /// </summary>
        /// <param name="ball"></param>
        public void RemoveBall(ScoreBall ball)
        {
            //Set the ball for removing. The game-loop will remove it when it's safe.
            ball.Remove = true;
            active.Remove(ball);

            if (ball.ScoreState == ScoreBall.State.Enemy)
            {
                enemies--;
            }
            else
            {
                friendlies--;
            }

            graveyard.Add(ball);
        }