/// <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; }
protected virtual void DrawBackground(DrawParams dparams, GsRectangle bounds, GsRectangle inside) { GsColor bgColor = (Level == MaxLevel ? GsMath.SmoothStep(GsColor.Beige, GsColor.SkyBlue, .5f) : GsColor.Beige); GsColor color = Selected ? GsColor.DarkGreen : bgColor; dparams.Graphics.FillRectangle(color, bounds); }
private void DrawGrid(DrawParams dparams) { GsVector offset = dparams.Offset; for (int c = 0; c < NumCols; ++c) { for (int r = 0; r < NumRows; ++r) { GridCell cell = Grid[c, r]; GsRectangle bounds = new GsRectangle(cell.X + offset.X, cell.Y + offset.Y, cell.Width, cell.Height); if (cellsToFlash.ContainsKey(cell)) { // draw the flashing cells int index = ((int)((SecondsToFlashCell - cellsToFlash[cell]) * FlashesPerSecond)) % MaxFlashes; float mu = ((float)index) / ((float)MaxFlashes); GsColor color = GsMath.SmoothStep(FlashStart, FlashEnd, mu); color = new GsColor(color, 200); dparams.Graphics.FillRectangle(color, bounds); } if (cell.IsOuter && !cell.IsThroughway) { switch (dparams.FillMode) { case GridFillMode.Solid: { dparams.Graphics.FillRectangle(GsColor.White, bounds); break; } case GridFillMode.Polygons: { dparams.Graphics.DrawRectangle(GsColor.White, bounds); break; } } } } } }
/// <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; }