Пример #1
0
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            //   Arena.instance.VerticalAlignment = VerticalAlignment.Stretch;// .sca .RenderTransform = new ScaleTransform(1.5, 1.5);
            //  Arena.instance.HorizontalAlignment = HorizontalAlignment.Stretch;// .sca .RenderTransform = new ScaleTransform(1.5, 1.5);

            System.Xml.XPath.XPathDocument  GameData    = new System.Xml.XPath.XPathDocument(".\\GameData.xml");
            System.Xml.XPath.XPathNavigator GameDataNav = GameData.CreateNavigator();

            Arena.instance.BankBalance = double.Parse(GameDataNav.SelectSingleNode("/GameData/StartingCash").ToString());
            Arena.instance.Lifes       = 20;

            //GameDataNav.MoveToRoot();

            //System.Xml.XPath.XPathNodeIterator dx = GameDataNav.Select("/GameData/TowerTypes/RadiatorTowers/RadiatorTower");
            System.Xml.XPath.XPathNodeIterator dx = GameDataNav.Select("/GameData/TowerTypes/*/*/@Name");
            //"/GameData/TowerTypes/*/*/@Price"
            while (dx.MoveNext())
            {
                string      q = dx.Current.ToString();
                ListBoxItem x = new ListBoxItem();
                x.Content = q;
                System.Xml.XPath.XPathNavigator n = GameData.CreateNavigator();
                System.Xml.XPath.XPathNavigator o = n.SelectSingleNode("/GameData/TowerTypes/*/*[@Name='" + q + "']");
                TowerData PTD;
                if (o.Name == "ProjectileTower")
                {
                    PTD = new ProjectileTowerData(o);
                }
                else if (o.Name == "RadiatorTower")
                {
                    PTD = new HeatTowerData(o);
                }
                else if (o.Name == "BeamTower")
                {
                    PTD = new BeamTowerData(o);
                }
                else
                {
                    PTD = new TowerData(o);
                }
                x.Tag = PTD;
                Window1.instance.Towers.Items.Add(x);
            }
        }
Пример #2
0
        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;
                    }
                }
            }
        }
Пример #3
0
        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;
                    }
                }
            }
            
        }
Пример #4
0
        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            
         //   Arena.instance.VerticalAlignment = VerticalAlignment.Stretch;// .sca .RenderTransform = new ScaleTransform(1.5, 1.5);
          //  Arena.instance.HorizontalAlignment = HorizontalAlignment.Stretch;// .sca .RenderTransform = new ScaleTransform(1.5, 1.5);
            
            System.Xml.XPath.XPathDocument GameData = new System.Xml.XPath.XPathDocument(".\\GameData.xml");
            System.Xml.XPath.XPathNavigator GameDataNav = GameData.CreateNavigator();

            Arena.instance.BankBalance = double.Parse(GameDataNav.SelectSingleNode("/GameData/StartingCash").ToString());
            Arena.instance.Lifes = 20;

            //GameDataNav.MoveToRoot();

            //System.Xml.XPath.XPathNodeIterator dx = GameDataNav.Select("/GameData/TowerTypes/RadiatorTowers/RadiatorTower");
            System.Xml.XPath.XPathNodeIterator dx = GameDataNav.Select("/GameData/TowerTypes/*/*/@Name");
            //"/GameData/TowerTypes/*/*/@Price"
            while (dx.MoveNext())
            {
                string q = dx.Current.ToString();
                ListBoxItem x = new ListBoxItem();
                x.Content = q;
                System.Xml.XPath.XPathNavigator n = GameData.CreateNavigator();
                System.Xml.XPath.XPathNavigator o = n.SelectSingleNode("/GameData/TowerTypes/*/*[@Name='" + q + "']");
                TowerData PTD;
                if (o.Name == "ProjectileTower")
                {
                    PTD = new ProjectileTowerData(o);
                }
                else if (o.Name == "RadiatorTower")
                {
                    PTD = new HeatTowerData(o);
                }
                else if (o.Name == "BeamTower")
                {
                    PTD = new BeamTowerData(o);
                }
                else
                {
                    PTD = new TowerData(o);
                }
                x.Tag = PTD;
                Window1.instance.Towers.Items.Add(x);
            }
        }