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 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 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 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; } }
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; } }