예제 #1
0
        private IGameObject[] PlaceAsteroidsOnLine(System.Random random, AsteroidPlacement asteroidPlacement, ref float?prevRandomPct)
        {
            var retVal           = new List <IGameObject>();
            var xcoordRangeIndex = 0;
            var prevXCoord       = X_MIN; //we want the asteroids to start at the left edge of the screen, but the source asteroid is in the center of the screen, so we need to start with this offset value. (X_MIN is negative)

            Utils.Vector3 transVector;
            do
            {
                var isFirstAsteroidOnLine = (xcoordRangeIndex == 0);
                transVector = GetAsteroidPosition(random, asteroidPlacement, prevXCoord, isFirstAsteroidOnLine); //todo 2nd game: should GetAsteroidPosition be moved to a different class? That way, we can mock its return value and test the loop logic

                if (transVector != null)                                                                         //null value means we've placed all the asteroids we can fit on this line
                {
                    var curAsteroid = _gameEngineInterface.Clone(_sourceAsteroid, asteroidPlacement.LineName + xcoordRangeIndex.ToString());

                    //curAsteroid.Transform.Translate(10, 0, -100); //source asteroid's initial position is -10, 0, 0
                    curAsteroid.Transform.Translate(transVector.X, transVector.Y, transVector.Z);
                    retVal.Add(curAsteroid);

                    prevXCoord = transVector.X;
                    xcoordRangeIndex++;
                }
            } while (transVector != null);

            return(retVal.ToArray());
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="random"></param>
        /// <param name="asteroidPlacement"></param>
        /// <param name="prevXCoord"></param>
        /// <param name="isFirstAsteroidOnLine"></param>
        /// <returns>returns a translation vector, telling you how far to translate an asteroid from its source position</returns>
        private Utils.Vector3 GetAsteroidPosition(System.Random random, AsteroidPlacement asteroidPlacement, float prevXCoord, bool isFirstAsteroidOnLine)
        {
            var distance = getCurDistance(_asteroidDensity, isFirstAsteroidOnLine);
            var xCoord   = prevXCoord + distance;

            if (xCoord > X_MAX - (ASTEROID_WIDTH / 2))
            {
                //if we placed an asteroid at this xCoord, it would be partially or completely off-screen. (so we're done placing asteroids on this line)
                return(null);
            }
            else
            {
                return(new Utils.Vector3(xCoord, 0, asteroidPlacement.ZCoord));
            }
        }