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); }
public SprinklerProjectile(Piece parent, double timeToLiveInSeconds) : base(parent, timeToLiveInSeconds) { Color = GsMath.Lerp(GsColor.LightBlue, GsColor.DarkBlue, .65f); Size = new GsSize(10f, 8f); ImageKey = "fragment"; }
public static float ComputeOrientation(float orientation, GsVector direction, float turnSpeed) { float desiredAngle = (float)Math.Atan2(direction.Y, direction.X); float difference = GsMath.WrapAngle(desiredAngle - orientation); return(GsMath.WrapAngle(orientation + difference)); }
/// <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 override void Update(TimeSpan elapsed) { base.Update(elapsed); if (Level == MaxLevel) { Orientation = Environment.TickCount / 1000f; Orientation = GsMath.WrapAngle(Orientation); } }
protected void UpdateVariables(float elapsedSeconds) { //mScale += elapsedSeconds * ScalesPerSecond; //Size = mOwnerBounds.Size * .5f * mScale; // spin the projectile Orientation += elapsedSeconds * RotationsPerSecond; Orientation = GsMath.WrapAngle(Orientation); }
public override void Update(TimeSpan elapsed) { // let the base do it's thing base.Update(elapsed); // spin around in a circle Orientation += ((float)elapsed.TotalSeconds * RadiansPerSecond); Orientation = GsMath.WrapAngle(Orientation); }
public DebriProjectile(Piece parent, Projectile projectile, float orientation) : base(parent, .3) { Velocity = Calculator.ComputeProjectileDirection(orientation) * 100f; Attack = projectile.Attack * 3f; Color = GsMath.Lerp(GsColor.Yellow, GsColor.Black, .55f); Orientation = orientation; Position = projectile.Position; Size = new GsSize(3.5f, 3.5f); ImageKey = "debri"; }
protected override void UpgradeProjectileVariables(float factor) { base.UpgradeProjectileVariables(factor); float mu = (float)Level / (float)MaxLevel; ProjectileSpeed = GsMath.Lerp(MinVelocity, MaxVelocity, mu); mPiePieces = GsMath.Lerp(MinPieSlices, MaxPieSlices, mu); NumberProjectilesToFire = 1; ProjectilesPerSecond = TotalSeconds * mPiePieces; }
public static DebriProjectile[] Create(Projectile projectile, int count) { List <DebriProjectile> retval = new List <DebriProjectile>(count + 1); float angle = GsMath.ToRadians(90f); float step = GsMath.ToRadians(360f) / count; for (int i = 0; i < count; ++i, angle += step) { retval.Add(new DebriProjectile(projectile.Parent, projectile, angle)); } return(retval.ToArray()); }
private void AdjustOrientation() { if (TargetCell == null) { Orientation = (DijkstraKey == DijkstraType.LeftToRight) ? 0f : GsMath.PiOver2; } else { float dx = TargetCell.X - X; float dy = TargetCell.Y - Y; float desiredAngle = (float)Math.Atan2(dy, dx); float difference = GsMath.WrapAngle(desiredAngle - Orientation); Orientation = GsMath.WrapAngle(Orientation + difference); } }
protected void DrawProgressState(DrawParams dparams, GsRectangle bounds, GsRectangle inside) { float width = inside.Width; float height = (float)Math.Round(inside.Height / 3f); float x = inside.X + ((inside.Width / 2f) - (width / 2f)); float y = inside.Y + ((inside.Height / 2f) - (height / 2f)); float progressWidth = width * Calculator.CalculatePercent(ProgressValue, 0, MaxProgress); float factor = ProgressValue / (MaxProgress); GsColor barFill = GsMath.Lerp(GsColor.Red, GsColor.DarkGreen, factor); GsColor barBder = GsColor.Black; dparams.Graphics.FillRectangle(barFill, x, y, progressWidth, height); dparams.Graphics.DrawRectangle(barBder, x, y, width, height); }
private float CalculateFuzzyTime(Invader invader) { // to calcuate the fuzzy time value, first we figure out how long we've // been chasing this mouse. For most mice, this will of course be no // time at all. TimeSpan time = TimeSpan.Zero; if (invader == Target) { time = mTimeChasingTarget; } // next we calculate fuzzyTime, which is a value ranging from 0 to 1. It // will increase as the amount of time we have spent chasing this mouse // increases. The value must be clamped to enforce the 0 to 1 rule. float fuzzyTime = (float)((time - MinTime).TotalSeconds / (MaxTime - MinTime).TotalSeconds); return(GsMath.Clamp(fuzzyTime, 0, 1)); }
public override void Update(TimeSpan elapsed) { // let the base update base.Update(elapsed); // if we're idle, then we COULD be firing if (State == PieceState.Idle) { UpdateTeslaState(elapsed); } else { mTeslaState = TeslaState.Idle; mIndex = 0; } float factor = ((float)mIndex) / ((float)NumberIndexFrames); Color = GsMath.Lerp(GsColor.Beige, LightningColor, factor); }
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; } } } } } }
public TeslaCoilPiece() { // setup the description StringBuilder sb = new StringBuilder(); sb.AppendLine("Fires a charged burst of electricity. The burst is very effective against ground units."); // set the properties needed Attack = 9000; Price = 2500; Radius = 250; UpgradePercent = 45; LevelVisibility = 75; Description = sb.ToString(); ProjectileLifeInSeconds = 6.7f; CanFireProjectiles = false; Name = TeslaCoilName; UltimateName = UltimateTeslaCoilName; Grouping = PieceGrouping.Three; ImageKey = "teslaCoil"; Element = Element.Electricity; Specialty = PieceSpecialty.Both; // set the properties of the piece mIndex = 0; mAggregateTimeSinceUpdate = 0; mTeslaState = TeslaState.Idle; Color = GsColor.White; // get the image var image = GetImage(); var imageSize = ImageProvider.GetSize(image); FrameSize = new GsSize(imageSize.Width / (NumberIndexFrames + 1), imageSize.Height); LightningColor = GsMath.Lerp(GsColor.Purple, GsColor.DarkBlue, .5f); LightningColor = GsMath.Lerp(LightningColor, GsColor.Red, .75f); }
private void InitializeGrid() { int midCol = (NumCols - 1) / 2; int midRow = (NumRows - 1) / 2; int midColLeft = midCol - HalfThroughWay; int midColRight = midCol + HalfThroughWay; int midRowUp = midRow - HalfThroughWay; int midRowDown = midRow + HalfThroughWay; int dc = (NumCols - 1) % 2; int dr = (NumRows - 1) % 2; Grid = new GridCell[NumCols, NumRows]; for (int c = 0; c < NumCols; ++c) { for (int r = 0; r < NumRows; ++r) { bool isOuter = (c == 0 || r == 0 || c == (NumCols - 1) || r == (NumRows - 1)); bool isThroughway = isOuter && (GsMath.InRange(c, midColLeft + dc, midColRight) || GsMath.InRange(r, midRowUp + dr, midRowDown)); GridCell cell = new GridCell(c, r, isOuter, isThroughway); cell.Bounds = new GsRectangle(c * CellWidth, r * CellHeight, CellWidth, CellHeight); Grid[c, r] = cell; } } HorzGoalCell = Grid[NumCols - 1, midRow]; VertGoalCell = Grid[midCol, NumRows - 1]; HorzStartCell = Grid[0, midRow]; VertStartCell = Grid[midCol, 0]; gridBounds = GsRectangle.FromLTRB(Grid[0, 0].X, Grid[0, 0].Y, Grid[NumCols - 1, 0].X + CellWidth, Grid[0, NumRows - 1].Y + CellHeight); gridBounds.Offset(MiddleOffset + Position); }
/// <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; }
public RailgunProjectile(Piece parent, double timeToLiveInSeconds) : base(parent, timeToLiveInSeconds) { Color = GsMath.Lerp(GsColor.Yellow, GsColor.Red, .65f); ImageKey = "pulse"; }