Example #1
0
        /// <summary>
        /// Briefs the invader on it's mission. It should go from the start cell and try to
        /// reach the goal cell.
        /// </summary>
        /// <param name="start">The cell to start on.</param>
        /// <param name="goal">The goal to get to.</param>
        /// <param name="key">The key to assign to this invader to aid in path finding.</param>
        public void BriefOnMission(GridCell start, GridCell goal, DijkstraType key)
        {
            TargetCell  = start;
            GoalCell    = goal;
            DijkstraKey = key;

            float dx = (DijkstraKey == DijkstraType.LeftToRight ? TargetCell.Width * 2f : 0);
            float dy = (DijkstraKey == DijkstraType.TopToBottom ? TargetCell.Height * 2f : 0);

            float mux = RandomGenerator.NextSingle();
            float muy = RandomGenerator.NextSingle();

            X = TargetCell.X - (dx * GsMath.SmoothStep(1, 5, mux));
            Y = TargetCell.Y - (dy * GsMath.SmoothStep(1, 5, muy));

            Width  = TargetCell.Width * (Flying ? 1.5f : 1f);
            Height = TargetCell.Height * (Flying ? 1.5f : 1f);

            Velocity = new GsVector(mAttributes[InvaderAttributes.Speed]);
            AdjustOrientation();

            var texture = GetImage();
            var size    = ImageProvider.GetSize(texture);

            Origin = new GsVector(size.Width / 2f, size.Height / 2f);

            CurrentLife = MaximumLife;
            TargetCell  = Flying ? goal : start;
        }
        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);
        }
Example #3
0
 /// <summary>
 /// Creates a new node.
 /// </summary>
 /// <param name="cell">The cell to associate with this node.</param>
 /// <param name="type">The type of node this is. Used to link up with the cell.</param>
 public DijkstraNodeAlliance(GridCell cell, DijkstraType type)
     : base(new Index(cell.Column, cell.Row), !cell.IsWalkable)
 {
     mAssociatedCell = cell;
     mAssociatedCell.LinkDijkstraNode(this, type);
 }
 /// <summary>
 /// Sets the goal cell for a specific grid type. Note that the cell must be
 /// created and initialized before this can be called.
 /// </summary>
 /// <param name="type">The type of grid of to set the goal cell for.</param>
 /// <param name="c">The column index of the goal cell.</param>
 /// <param name="r">The row index of the goal cell.</param>
 public void SetGoal(DijkstraType type, int c, int r)
 {
     mGoal[type] = mGrids[type][c, r];
 }
 /// <summary>
 /// Solves the specific grid using Dijkstra's algorithm.
 /// </summary>
 /// <param name="type">The type of grid to solve.</param>
 public void Solve(DijkstraType type)
 {
     Dijkstra.SolveGrid(mGrids[type], mGoal[type]);
 }
 /// <summary>
 /// Gets or sets the grid for a specific dijkstra type.
 /// </summary>
 /// <param name="type">The type used to get or set a grid.</param>
 /// <returns>The grid corresponding to the Dijkstra type.</returns>
 public DijkstraNode[, ] this[DijkstraType type]
 {
     get { return(mGrids[type]); }
     set { mGrids[type] = value; }
 }
Example #7
0
 public DijkstraNodeAlliance this[DijkstraType key]
 {
     get { return(mDijkstraData[(int)key]); }
 }
Example #8
0
 public void LinkDijkstraNode(DijkstraNodeAlliance node, DijkstraType type)
 {
     mDijkstraData[(int)type] = node;
 }