public new void Tick(int FrameCount) { base.Tick(FrameCount); if (this.SubClassData == null) { if (this.Data == null) { return; } SubClassData = Data as ProjectileTowerData; } if (ProjectileColor == Colors.Transparent) { ProjectileColor = System.Windows.Media.Color.FromRgb((byte)R.Next(255), (byte)R.Next(255), (byte)R.Next(255)); // Arena.instance.AddToArena(TargetLaserD); //Arena.instance.AddToArena(TargetLaserB); } if (RefireCount > 0) { RefireCount--; } CurrentTarget = null; double TXV; double TYV; double V; //System.Windows.Media.Color bc = Color.FromScRgb(1f, (float)(Heat / Data.ShutdownHeat), 0f, 0f);//(float)(Target.LockDuration / 255) //Body.Fill = new System.Windows.Media.SolidColorBrush(HeatColor(Heat, Data.ShutdownHeat)); Body.Fill = StaticHelpers.HeatBrush(Heat, Data.ShutdownHeat); // Are we already locked on? if (Target.LockedTarget != null && Target.LockedTarget.IsAlive == true) { // is the locked target still in range? TXV = (Target.LockedTarget.XPos - PivotPoint.X); TYV = (Target.LockedTarget.YPos - PivotPoint.Y); V = (TXV)*(TXV) + (TYV)*(TYV); if (V < (SubClassData.Range * SubClassData.Range)) { CurrentTarget = Target.LockedTarget; Target.LockDuration++; } } // Find a new target if (CurrentTarget == null) { CurrentTarget = NearestCreep(SubClassData.Range); Target.LockedTarget = CurrentTarget; Target.LockDuration = 0; return; } // No valid targets if (CurrentTarget == null) { // Body.Fill = Brushes.Blue; return; } Point TargetPoint = new Point(CurrentTarget.XPos, CurrentTarget.YPos); //lastsetrotation = new CoercedAngle(StaticHelpers.Angle(PivotPoint, TargetPoint)); if (Target.LockDuration > 0) { float MuzzleVelocity = 25; // TargetLaserB.X1 = this.PivotPoint.X; // TargetLaserB.Y1 = this.PivotPoint.Y; // TargetLaserB.X2 = CurrentTarget.XPos; // TargetLaserB.Y2 = CurrentTarget.YPos; // TargetLaserB.Stroke = Brushes.Green; // TargetLaserB.StrokeThickness = 1; //calculate the distance to the target TXV = (CurrentTarget.XPos - PivotPoint.X); TYV = (CurrentTarget.YPos - PivotPoint.Y); V = Math.Sqrt((TXV)*(TXV) + (TYV)*(TYV)); //calculate the targets velocity double VelocityX = TXV - Target.LockedTargetPriorX; double VelocityY = TYV - Target.LockedTargetPriorY; //save the current position to calc velocity next frame Target.LockedTargetPriorX = TXV; Target.LockedTargetPriorY = TYV; // calculate where the target will be in the time it takes the projectile to travel to it's current location. double ExPosX = CurrentTarget.XPos + (VelocityX * V / MuzzleVelocity); double ExPosY = CurrentTarget.YPos + (VelocityY * V / MuzzleVelocity); TargetPoint = new Point(ExPosX, ExPosY); // TargetLaserA.X1 = this.PivotPoint.X; // TargetLaserA.Y1 = this.PivotPoint.Y; // TargetLaserA.X2 = ExPosX; // TargetLaserA.Y2 = ExPosY; // TargetLaserA.Stroke = Brushes.Red; // TargetLaserA.StrokeThickness = 1; //Arena.instance.AddToArena(TargetLaserA); //calculate the distance to the new position. TXV = (ExPosX - PivotPoint.X); TYV = (ExPosY - PivotPoint.Y); V = Math.Sqrt((TXV)*(TXV) + (TYV)*(TYV)); // re-calculate where the target will be in the time it takes the projectile to travel to it's current location. ExPosX = CurrentTarget.XPos + (VelocityX * V / MuzzleVelocity); ExPosY = CurrentTarget.YPos + (VelocityY * V / MuzzleVelocity); // TargetLaserC.X1 = this.PivotPoint.X; // TargetLaserC.Y1 = this.PivotPoint.Y; // TargetLaserC.X2 = ExPosX; // TargetLaserC.Y2 = ExPosY; // TargetLaserC.Stroke = Brushes.Blue; // TargetLaserC.StrokeThickness = 1; //Arena.instance.AddToArena(TargetLaserC); //calculate the distance to the new position. TXV = (ExPosX - PivotPoint.X); TYV = (ExPosY - PivotPoint.Y); V = Math.Sqrt((TXV)*(TXV) + (TYV)*(TYV)); // re-re-calculate where the target will be in the time it takes the projectile to travel to it's current location. ExPosX = CurrentTarget.XPos + (VelocityX * V / MuzzleVelocity); ExPosY = CurrentTarget.YPos + (VelocityY * V / MuzzleVelocity); // TargetLaserD.X1 = this.PivotPoint.X; // TargetLaserD.Y1 = this.PivotPoint.Y; // TargetLaserD.X2 = ExPosX; // TargetLaserD.Y2 = ExPosY; // TargetLaserD.Stroke = Brushes.White; // TargetLaserD.StrokeThickness = 1; // DoubleCollection dc = new DoubleCollection(); // dc.Add(1); // dc.Add(4); // TargetLaserD.StrokeDashArray = dc; TargetPoint = new Point(ExPosX, ExPosY); // Rotate barrel if not aligned with leading point. if (!IsAlignedTo(TargetPoint, SubClassData.TrackingSpeed)) { CoercedAngle diff = new CoercedAngle(StaticHelpers.Angle(PivotPoint, TargetPoint) - currentrotation.Angle); if (diff.Angle > 180) { currentrotation.Angle -= SubClassData.TrackingSpeed; } else { currentrotation.Angle += SubClassData.TrackingSpeed; } // Body.Fill = Brushes.Yellow; Barrel.RenderTransform = new RotateTransform(currentrotation.Angle); //return; } else { // We are aligned (within tracking speed margin of error) with the targets predicted position. currentrotation.Angle = StaticHelpers.Angle(PivotPoint, TargetPoint); this.Barrel.RenderTransform = new RotateTransform(StaticHelpers.Angle(PivotPoint, TargetPoint)); //Are we ready to fire? if (RefireCount <= 0 && Target.LockDuration > 1 && this.Heat <= this.Data.ShutdownHeat) { //FIRE!!! Projectile P = Projectile.Create( FrameCount, (float)PivotPoint.X, (float)PivotPoint.Y, (float)(TXV / V) * (float)MuzzleVelocity, (float)(TYV / V) * (float)MuzzleVelocity, Projectile.GenericHitCreep ); RefireCount = SubClassData.RefireDelay; this.Heat += this.SubClassData.FiringHeat; } } } }
public HeatTowerData SubClassData;// = new ProjectileTowerData(); // public TargetLock Target = new TargetLock(); // public Creep CurrentTarget; // public Shape Barrel; // public float RefireCount = 0; // static Random R = new Random(); // System.Windows.Media.Color ProjectileColor = Colors.Transparent; public new void Tick(int Frame) { if (this.SubClassData == null) { if (this.Data == null) { return; } SubClassData = Data as HeatTowerData; } //Shape bb = LogicalTreeHelper.FindLogicalNode(VisualObject, "_Grill") as Shape; //Body.Fill = new System.Windows.Media.VisualBrush(this); //System.Windows.Media.Color bc = Color.FromScRgb(1f, (float)(Heat / Data.ShutdownHeat), 0f, 0f); //Body.Fill = new System.Windows.Media.SolidColorBrush(bc); List <Tower> HotNeighbor = new List <Tower>(); float TotalNeighborHeat = 0; float startingheat = this.Heat; float HottestNeighborHeat = 0; //Make of list of neighbors who's heat level is higher than self. foreach (EmptyCell C in this.OwningCell.Adjacent) { Tower CT = C.Occupant as Tower; if (CT != null) { if (CT.Heat / CT.Data.ShutdownHeat > startingheat / Data.ShutdownHeat) { HotNeighbor.Add(CT); TotalNeighborHeat += (CT.Heat - startingheat); HottestNeighborHeat = Math.Max(HottestNeighborHeat, CT.Heat); } } } if (HotNeighbor.Count > 0 && TotalNeighborHeat > 1) { float RemainingHeatAbsorb = SubClassData.HeatAbsorb; // if self is close to overheating, don't take more heat than capacity, and never get hotter than hottest neighbor. float ModifiedHeatLimit = Math.Min(this.Data.ShutdownHeat, HottestNeighborHeat); if (RemainingHeatAbsorb + startingheat > ModifiedHeatLimit) { RemainingHeatAbsorb = ModifiedHeatLimit - startingheat; } //ModifiedHeatAbsorb = SubClassData.HeatAbsorb / HotNeighbor.Count; foreach (Tower HN in HotNeighbor) { float SplitHeatAbsorb; float HeatDiff = (HN.Heat - startingheat); //figure this neighors 'share' of heat absorbtion. SplitHeatAbsorb = (HeatDiff / TotalNeighborHeat) * RemainingHeatAbsorb; //Take no more than half the heat differance. if (HeatDiff < SplitHeatAbsorb * 2) { //float s = (this.Heat +CT.Heat) this.Heat += HeatDiff / 2; HN.Heat -= HeatDiff / 2; } else { this.Heat += SplitHeatAbsorb; HN.Heat -= SplitHeatAbsorb; } } } //Body.Fill = new System.Windows.Media.SolidColorBrush(HeatColor(Heat, Data.ShutdownHeat)); Body.Fill = StaticHelpers.HeatBrush(Heat, Data.ShutdownHeat); base.Tick(Frame); }
public bool IsAlignedTo(Point TargetPoint, double tolerance) { CoercedAngle diff = new CoercedAngle(StaticHelpers.Angle(PivotPoint, TargetPoint) - currentrotation.Angle); return(diff.Angle < tolerance || diff.Angle > (360 - tolerance)); }
public new void Tick(int FrameCount) { base.Tick(FrameCount); if (this.SubClassData == null) { if (this.Data == null) { return; } SubClassData = Data as BeamTowerData; } //if (ProjectileColor == Colors.Transparent) { // ProjectileColor = System.Windows.Media.Color.FromRgb((byte)R.Next(255), (byte)R.Next(255), (byte)R.Next(255)); // Arena.instance.AddToArena(TargetLaserD); //Arena.instance.AddToArena(TargetLaserB); } CurrentTarget = null; double TXV; double TYV; double V; //System.Windows.Media.Color bc = Color.FromScRgb(1f, (float)(Heat / Data.ShutdownHeat), 0f, 0f);//(float)(Target.LockDuration / 255) //Body.Fill = new System.Windows.Media.SolidColorBrush(HeatColor(Heat, Data.ShutdownHeat)); Body.Fill = StaticHelpers.HeatBrush(Heat, Data.ShutdownHeat); // Are we already locked on? if (Target.LockedTarget != null && Target.LockedTarget.IsAlive == true) { // is the locked target still in range? TXV = (Target.LockedTarget.XPos - PivotPoint.X); TYV = (Target.LockedTarget.YPos - PivotPoint.Y); V = (TXV)*(TXV) + (TYV)*(TYV); if (V < (SubClassData.Range * SubClassData.Range)) { CurrentTarget = Target.LockedTarget; Target.LockDuration++; } } else { Arena.instance.Children.Remove(Beam); Beam.Stroke = Brushes.Transparent; Arena.instance.AddToArena(Beam); } // Find a new target if (CurrentTarget == null) { CurrentTarget = NearestCreep(SubClassData.Range); Target.LockedTarget = CurrentTarget; Target.LockDuration = 0; return; } // No valid targets if (CurrentTarget == null) { return; } if (RefireCount > 0) { RefireCount--; } Point TargetPoint = new Point(CurrentTarget.XPos, CurrentTarget.YPos); //lastsetrotation = new CoercedAngle(StaticHelpers.Angle(PivotPoint, TargetPoint)); if (Target.LockDuration > 0) { // float MuzzleVelocity = 25; Beam.X1 = this.PivotPoint.X; Beam.Y1 = this.PivotPoint.Y; Beam.X2 = CurrentTarget.XPos; Beam.Y2 = CurrentTarget.YPos; // Beam.Stroke = Brushes.Green; Beam.StrokeThickness = 3; //calculate the distance to the target TXV = (CurrentTarget.XPos - PivotPoint.X); TYV = (CurrentTarget.YPos - PivotPoint.Y); V = Math.Sqrt((TXV)*(TXV) + (TYV)*(TYV)); // Rotate barrel if not aligned with leading point. if (!IsAlignedTo(TargetPoint, SubClassData.TrackingSpeed)) { CoercedAngle diff = new CoercedAngle(StaticHelpers.Angle(PivotPoint, TargetPoint) - currentrotation.Angle); if (diff.Angle > 180) { currentrotation.Angle -= SubClassData.TrackingSpeed; } else { currentrotation.Angle += SubClassData.TrackingSpeed; } // Body.Fill = Brushes.Yellow; Barrel.RenderTransform = new RotateTransform(currentrotation.Angle); //return; } else { // We are aligned (within tracking speed margin of error) with the targets predicted position. currentrotation.Angle = StaticHelpers.Angle(PivotPoint, TargetPoint); this.Barrel.RenderTransform = new RotateTransform(StaticHelpers.Angle(PivotPoint, TargetPoint)); //Are we ready to fire? if (this.Heat > this.Data.ShutdownHeat) { RefireCount += 5; } if (RefireCount <= 0 && Target.LockDuration > 1 && this.Heat <= this.Data.ShutdownHeat) { //FIRE!!! /* * Projectile P = Projectile.Create( * FrameCount, * (float)PivotPoint.X, * (float)PivotPoint.Y, * (float)(TXV / V) * (float)MuzzleVelocity, * (float)(TYV / V) * (float)MuzzleVelocity, * Projectile.GenericHitCreep * ); * RefireCount = SubClassData.RefireDelay; */ Beam.Stroke = StaticHelpers.HeatBrush((float)Target.LockDuration + 50, 100f); CurrentTarget.TakeDamage(Target.LockDuration / 20); this.Heat += this.SubClassData.FiringHeat; } else { Beam.Stroke = Brushes.Transparent; } } } else { Beam.Stroke = Brushes.Transparent; } }