Ejemplo n.º 1
0
        public IEnumerable <Invader> GenerateWave(GridDestination horizontal, GridDestination vertical, IEnumerable <Piece> pieces, GridCell[,] grid)
        {
            // create a list to store the invaders created
            List <Invader> retval = new List <Invader>();

            // if the invader level is past the maximum, then return an empty invader list
            if (SentAllInvaders)
            {
                return(retval);
            }

            // TODO: This could be something to adjust based on the difficulty
            // decide how many invaders we're going to send
            int invaderCount = 10;

            // create a class that holds the default weights of everything
            InvaderLevelUpInfo info = new InvaderLevelUpInfo(pieces, mMadeItCount, mDestroyedCount);

            // now then, create a loop to generate the invaders
            for (int i = 0; i < invaderCount; ++i)
            {
                // determine the boolean properties for the invader
                bool flying    = RandomGenerator.NextBool();
                bool leftRight = RandomGenerator.NextBool();

                // get the start/goal and key
                GridCell     start = leftRight ? horizontal.Start : vertical.Start;
                GridCell     goal  = leftRight ? horizontal.End : vertical.End;
                DijkstraType key   = leftRight ? DijkstraType.LeftToRight : DijkstraType.TopToBottom;

                // create a base invader. This invader will have a 50% chance of flying.
                Invader invader = new Invader(this, flying);

                // set the experience of the invader given the weights
                invader.LevelUp((InvaderLevel * 10), InvaderLevel, info);

                // send the invader to the map
                invader.BriefOnMission(start, goal, key);

                // next, add the invader to the list
                retval.Add(invader);
            }

            // increase the level
            ++InvaderLevel;

            // if we increased the level to the maximum invader level, then we've sent all of the invaders
            if (InvaderLevel > Invader.MaxInvaderLevel)
            {
                SentAllInvaders = true;
                InvaderLevel    = Invader.MaxInvaderLevel;
            }

            // return the invaders
            return(retval);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Levels up this invader by adding on the experience points. Each experience is
        /// distributed to a certain attribute of the invader based on the weights that
        /// are passed in.
        /// </summary>
        /// <param name="experiencePts">The amount of experience points.</param>
        /// <param name="info">The info to use when distributing the experience points.</param>
        public void LevelUp(float experiencePts, float level, InvaderLevelUpInfo info)
        {
            // add on to the current experience
            Experience += experiencePts;

            // from here, determine the mu
            float mu = Calculator.CalculatePercent(level, MinInvaderLevel, MaxInvaderLevel);

            // now, determine the level (make sure we're at least lvl1)
            Level = level;

            // determine the value
            Value = (float)Math.Ceiling(Level * 5);

            // calculate the maximum life
            MaximumLife = (float)Math.Floor(GsMath.SmoothStep(MinInvaderLife, MaxInvaderLife, mu));

            // get the elements with the highest count
            int max = info.ElementCounts.Max(i => i.Value);

            Element[] elements = (from kvp in info.ElementCounts
                                  where kvp.Value.Equals(max)
                                  select kvp.Key).ToArray();

            // for now, set the first one to be our element
            Element = elements.Length == 1 ? elements[0] : Element.None;

            // create a dictionary
            List <InvaderAttributes> attributes = mAttributes.Keys.ToList();

            // based on the level, add on the to the attributes
            foreach (InvaderAttributes attribute in attributes)
            {
                var minmax = MinMaxValues[attribute];
                mAttributes[attribute] = (float)Math.Floor(GsMath.SmoothStep(minmax.Min, minmax.Max, mu));

                // TODO:
                // here, we need to determine if we're going to increase/decrease the defense, skill, or speed
                // based on how many invaders made it.
                //
                // An easy AI would take away abilities when invaders didn't
                // make it. It would also decrease defense and skill. Basically making it easier on the player.
                //
                // A normal AI wouldn't do anything.
                // A hard AI would very slightly increase the attributes
                // A difficult AI...you get the picture.
            }

            // set the color based on the element
            Color = Colors[Element];

            // TODO:
            // here, based on the skill, we would update the abilities.

            // set the base image key
            int key = (int)Math.Floor(Level / LevelDenominator);

            ImageKey = BaseImageKeys[key][Flying ? 1 : 0];

            // randomize the animation settings
            mIndex = RandomGenerator.Next() % ImageProvider.GetFramedImage(ImageKey).NumberFrames;
            mTotalElapsedSeconds = RandomGenerator.Next(10) * SecondsPerFrame;
        }