예제 #1
0
        void EmptyCell_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            List <EmptyCell> cand = new List <EmptyCell>();

            cand.Add(this);
            {
                System.Windows.Point qq = e.GetPosition(this);
                if (qq.X > 0 && qq.Y > 0 && qq.X < this.Width && qq.Y < this.Height)
                {
                }
                else
                {
                    //this.Body.Fill = System.Windows.Media.Brushes.DarkGreen;
                    // this.Body.StrokeThickness = 0;
                }
            }
            foreach (EmptyCell ec in Adjacent)
            {
                System.Windows.Point qq = e.GetPosition(ec);
                if (qq.X > 0 && qq.Y > 0 && qq.X < ec.Width && qq.Y < ec.Height)
                {
                    cand.Add(ec);
                    //      ec.Body.Stroke = System.Windows.Media.Brushes.LightGreen;
                    //    ec.Body.StrokeThickness = 2;
                }
                else
                {
                    // ec.Body.Fill = System.Windows.Media.Brushes.DarkGreen;
                    //ec.Body.StrokeThickness = 0;
                }
            }

            EmptyCell result = null;

            if (cand.Count == 1)
            {
                result = cand[0];
            }
            else
            {
                double dd = double.MaxValue;

                foreach (EmptyCell pr in cand)
                {
                    Point  p1 = e.GetPosition(Arena.instance);
                    Point  p2 = pr.CenterPoint;
                    double d  = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
                    if (d < dd)
                    {
                        result = pr;
                        dd     = d;
                    }
                    //pr.pc.Content = d.ToString();
                }
            }

            Arena.instance.hovering = result;
            //result.Body.Stroke = Brushes.Blue;
            //this.
        }
예제 #2
0
        public List <EmptyCell> FindPathCells(EmptyCell PathFrom, EmptyCell PathTo)
        {
            while (Arena.instance.PathInvaliation.Count > 0)
            {
                EmptyCell xxx = Arena.instance.PathInvaliation.Dequeue();
                xxx.ValidatePath();
            }

            System.Collections.Generic.Queue <EmptyCell> Endpoints = new Queue <EmptyCell>();

            EmptyCell        backtrace = End;//new Point(End.X, End.Y);
            List <EmptyCell> PathCells = new List <EmptyCell>();

            while ((backtrace != Begin) && (backtrace.ToTarget != null))
            {
                PathCells.Add(backtrace);
                backtrace = (EmptyCell)backtrace.ToTarget[0];
            }

            return(PathCells);
        }
예제 #3
0
        Creep(double health)
        {
            this.Visibility = Visibility.Hidden;
            Counter = CreepCounter++;
            Health = health;
            MaxHealth = health;

            XPos = 10000;
            YPos = 10000;
            SetValue(System.Windows.Controls.Canvas.LeftProperty, (double)10000);
            SetValue(System.Windows.Controls.Canvas.TopProperty, (double)10000);

          //  this.RenderTransformOrigin = new Point(0, 0);
            PreviousCell = Arena.instance.End;
            CurrentCell = Arena.instance.End;
            //NextCell = Arena.instance.End;
            NextCell = CurrentCell.ToTarget[Counter % CurrentCell.ToTarget.Count];

            //Speed = R.Next(1,4);
            //XPos = R.Next(1, 15);
            //YPos = R.Next(1, 15);
        }
예제 #4
0
        Creep(double health)
        {
            this.Visibility = Visibility.Hidden;
            Counter         = CreepCounter++;
            Health          = health;
            MaxHealth       = health;

            XPos = 10000;
            YPos = 10000;
            SetValue(System.Windows.Controls.Canvas.LeftProperty, (double)10000);
            SetValue(System.Windows.Controls.Canvas.TopProperty, (double)10000);

            //  this.RenderTransformOrigin = new Point(0, 0);
            PreviousCell = Arena.instance.End;
            CurrentCell  = Arena.instance.End;
            //NextCell = Arena.instance.End;
            NextCell = CurrentCell.ToTarget[Counter % CurrentCell.ToTarget.Count];

            //Speed = R.Next(1,4);
            //XPos = R.Next(1, 15);
            //YPos = R.Next(1, 15);
        }
예제 #5
0
        public System.Windows.Media.PathFigure FindPath(EmptyCell PathFrom, EmptyCell PathTo)
        {
            //FindPathCells(PathFrom, PathTo);

            EmptyCell backtrace = PathTo;
            EmptyCell Prev1     = PathTo;

            System.Collections.Generic.List <Point> Tracky = new List <Point>();
            System.Windows.Media.PathFigure         pf     = new System.Windows.Media.PathFigure();
            //Point Prev2 = End;
            //Point Prev3 = End;
            Point p0;
            Point p1;
            Point ppa;

            System.Windows.Media.BezierSegment bs;
            //TrackLength = 0;

            pf.StartPoint = backtrace.CenterPoint;//.TranslatePoint(new Point(21.65, 25), Arena.instance);

            //pf.StartPoint = backtrace.TranslatePoint(new Point(21.65, 25), Arena.instance);

            foreach (EmptyCell ec in FindPathCells(Begin, End))
//            //while ((backtrace.X != Begin.X || backtrace.Y != Begin.Y) && ((Cells[backtrace].Tag) as Point?).HasValue)
            {
                // ec.Body.Fill = System.Windows.Media.Brushes.Purple;
                backtrace = ec;
                //  TrackLength++;
                // System.Windows.Shapes.Line L = new System.Windows.Shapes.Line();
                // L.X1 = Cells[backtrace].TranslatePoint(new Point(.5, .5), Arena.instance).X + 21.65;
                // L.Y1 = Cells[backtrace].TranslatePoint(new Point(.5, .5), Arena.instance).Y + 25;
                //double xx = 0;
                //double yy = 0;
                //xx = (Cells[backtrace].Tag as Point?).Value.X;
                //yy = (Cells[backtrace].Tag as Point?).Value.Y;

                p0 = backtrace.CenterPoint; // .TranslatePoint(new Point(21.65, 25), Arena.instance);
                p1 = Prev1.CenterPoint;     // .TranslatePoint(new Point(21.65, 25), Arena.instance);

                ppa = new Point((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2);

                bs = new System.Windows.Media.BezierSegment(p1, p1, ppa, true);
                pf.Segments.Add(bs);


                //backtrace = new Point(xx, yy);

                //Prev3 = Prev2;
                //Prev2 = Prev1;
                Prev1 = ec;

                // L.X2 = Cells[new Point(xx, yy)].TranslatePoint(new Point(.5, .5), Arena.instance).X + 21.65;
                // L.Y2 = Cells[new Point(xx, yy)].TranslatePoint(new Point(.5, .5), Arena.instance).Y + 25;

                // L.Stroke = System.Windows.Media.Brushes.Green;
                // L.StrokeThickness = 4;
                //L.IsHitTestVisible = false;
                //L.Fill = System.Windows.Media.Brushes.Green;
                //L.Opacity = 1;

                //Arena.instance.Children.Add(L);
                //PathLines.Enqueue(L);
            }
            p0 = backtrace.CenterPoint; //.TranslatePoint(new Point(21.65, 25), Arena.instance);
            p1 = Prev1.CenterPoint;     //.TranslatePoint(new Point(21.65, 25), Arena.instance);

            ppa = new Point((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2);

            bs = new System.Windows.Media.BezierSegment(p1, p1, ppa, true);
            pf.Segments.Add(bs);

            return(pf);
        }
예제 #6
0
        // Create a DrawingVisual that contains a rectangle.
//        MyVisualHost mvh = new MyVisualHost();

        protected override void OnInitialized(EventArgs e)
        {
            //base.OnInitialized(e);
            Arena.instance = this;

            NACellColor[0] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 0f, 1f);
            NACellColor[1] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 0f);
            NACellColor[2] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 1f);
            NACellColor[3] = System.Windows.Media.Color.FromScRgb(.1f, 1f, 0f, 0f);
            // NACellColor[4] = System.Windows.Media.Color.FromScRgb(1f, 1f, 0f, 1f);
            //  NACellColor[5] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 0f);
            //  NACellColor[6] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 1f);


            //          mvh.IsHitTestVisible = false;
            //        mvh.SetValue(Canvas.ZIndexProperty, 99);
            //      mvh.SetValue(System.Windows.Media.RenderOptions.EdgeModeProperty, System.Windows.Media.EdgeMode.Aliased);
            //    this.Children.Add(mvh);

            //this

            this.Loaded += new RoutedEventHandler(Arena_Loaded);



            //Debug.Content = Arena.instance.Children[0].GetType().ToString();
            bool AltRowToggle = false;
            bool AltColToggle = false;
            int  xx           = 0;
            int  yy           = 0;

            NACells[0] = new List <EmptyCell>();
            NACells[1] = new List <EmptyCell>();
            NACells[2] = new List <EmptyCell>();
            NACells[3] = new List <EmptyCell>();

            for (double y = -36.6; y < 707; y += 36.6)
            {
                yy          += 1;
                xx           = 0;
                AltRowToggle = !AltRowToggle;
                for (double x = -43.3; x < 930.95; x += 43.3)
                {
                    AltColToggle = !AltColToggle;
                    double mx = x;
                    if (!AltRowToggle)
                    {
                        mx += 21.65;
                    }
                    xx += 1;

                    //UIElement b;
                    EmptyCell b = new EmptyCell();

                    int qq = 0;
                    if (AltColToggle)
                    {
                        qq += 1;
                    }
                    if (AltRowToggle)
                    {
                        qq += 2;
                    }

                    b.Body.Fill = new System.Windows.Media.SolidColorBrush(NACellColor[qq]);
                    NACells[qq].Add(b);

                    b.CenterPoint = new Point(mx + 21.65, y + 25);
                    //Height="50" Width="43.3"

                    if (mx < 0 || mx >= 866 || y < 0 || y >= 707 - 36.6)//- 43.3
                    {
                        b.Occupant = new Block();
                        b.Occupied = true;
                    }
                    else
                    {
                        // b = new EmptyCell();
                        Cells.Add(new Point(xx, yy), b as EmptyCell);
                        Arena.instance.PathInvaliation.Enqueue(b);
                    }



                    b.SetValue(Canvas.TopProperty, y);
                    b.SetValue(Canvas.LeftProperty, mx);
                    Arena.instance.Children.Add(b);
                    if (b.Occupant as UIElement != null)
                    {
                        UIElement bo = b.Occupant as UIElement;
                        bo.SetValue(Canvas.TopProperty, y);
                        bo.SetValue(Canvas.LeftProperty, mx);

                        Arena.instance.Children.Add(b.Occupant as UIElement);
                    }
                    PathInvaliation.Enqueue(b);
                }
            }



            foreach (Point P in Cells.Keys)
            {
                //if (Cells[P].Occupied == false)
                {
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y)]);
                    }
                    catch
                    { }

                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y - 1)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y + 1)]);
                    }
                    catch
                    { }

                    if ((P.Y / 2) == Math.Floor(P.Y / 2))
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y + 1)]);
                        }
                        catch
                        { }
                    }
                    else
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y + 1)]);
                        }
                        catch
                        { }
                    }
                }

                //Arena.instance.MouseMove += new System.Windows.Input.MouseEventHandler(instance_MouseMove);
            }


            Begin = Cells[new Point(2, 2)];
            End   = Cells[new Point(21, 20)];


            CreepSpawn c = new CreepSpawn();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            TheSpawner = c;
            c.SetValue(Canvas.TopProperty, End.GetValue(Canvas.TopProperty));
            c.SetValue(Canvas.LeftProperty, End.GetValue(Canvas.LeftProperty));

            Begin.Occupant = c as IArenaObject;
            //c.Opacity = .5;
            Arena.instance.Children.Add(c);

            CreepTarget d = new CreepTarget();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            d.SetValue(Canvas.TopProperty, Begin.GetValue(Canvas.TopProperty));
            d.SetValue(Canvas.LeftProperty, Begin.GetValue(Canvas.LeftProperty));

            End.Occupant = d as IArenaObject;
            //d.Opacity = .5;
            Arena.instance.Children.Add(d);

            /*
             * System.Windows.Shapes.Line L = new System.Windows.Shapes.Line();
             * L.X1 = 0;
             * L.Y1 = 0;
             *
             * L.X2 = Begin.TranslatePoint(new Point(.5, .5), Arena.instance).X;
             * L.Y2 = 500;
             *
             * L.Stroke = System.Windows.Media.Brushes.Salmon;
             * L.StrokeThickness = 5;
             * L.Fill = System.Windows.Media.Brushes.PowderBlue;
             * L.Opacity = 1;
             *
             * Arena.instance.Children.Add(L);
             */


            Arena.instance.MouseLeave += new System.Windows.Input.MouseEventHandler(instance_MouseLeave);
            Arena.instance.MouseDown  += new System.Windows.Input.MouseButtonEventHandler(instance_MouseDown);

            Arena.instance.FindPathCells(Begin, End);

            // this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(Hooks_DispatcherInactive);

            //System.Windows.Media.CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

            DT = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Background);



            DT.Tick += new EventHandler(DT_Tick);

            DT.Interval = TimeSpan.FromSeconds(.01);
            DT.Start();
        }
예제 #7
0
        public void InnerTick(int Frame)
        {
            if (Health < 0)
            {
                Die(this);
                return;
            }

            Progress += 0.01;

            if (Progress < 0)
            {
                this.Visibility = Visibility.Hidden;

            }
            else
            {
                
                if (this.Visibility == Visibility.Hidden)
                {
                    this.Visibility = Visibility.Visible;    
                    Arena.instance.AddToArena(this);
                }
                

                if (Progress >= .75)//|| NextCell != CurrentCell.ToTarget[Counter % CurrentCell.ToTarget.Count]
                {
                    PreviousCell = CurrentCell;

                    lock (CurrentCell.CreepsInCell)
                    {
                        CurrentCell.CreepsInCell.Remove(this);
                    }
                    CurrentCell = NextCell;
                    lock (CurrentCell.CreepsInCell) CurrentCell.CreepsInCell.Add(this);
                    if (CurrentCell.ToTarget.Count == 0)
                    {
                        // no prize for failure.
                        Bounty = 0;

                        // remove the creep from play.
                        Die(this);

                        if (Arena.instance.Lifes-- <= 0)
                        {
                            // Game Over.
                            //MessageBox.Show("Game Over");
                        }
                    }
                    else// if (CurrentCell.ToTarget.Count == 1)
                    {
                        // NextCell = CurrentCell.ToTarget[0];
                        //}
                        //else
                        //{

                        if ((Counter & 1) == 0)
                        {
                            Counter >>= 2;
                        }
                        else
                        {
                            Counter >>= 2;
                            Counter = Counter | 1073741824;
                        }
                        NextCell = CurrentCell.ToTarget[Counter % CurrentCell.ToTarget.Count];
                    }
                    Progress -= 0.5;

                    // PERF:

                    // Generating Bezier's is expensive; some kind of cache...? or not generate per creep*per frame...

                    // should only be 30 possible curves
                    // 

                    Track = new System.Windows.Media.PathGeometry();
                    System.Windows.Media.PathFigure pf = new System.Windows.Media.PathFigure();
                    pf.StartPoint = new Point(PreviousCell.CenterPoint.X, PreviousCell.CenterPoint.Y);
                    Point p0 = new Point(CurrentCell.CenterPoint.X, CurrentCell.CenterPoint.Y);
                    //Point p1 = new Point(CurrentCell.CenterPoint.X, CurrentCell.CenterPoint.Y);
                    Point ppa = new Point(NextCell.CenterPoint.X, NextCell.CenterPoint.Y);
                    //System.Windows.Media.BezierSegment bs;
                    //bs = ;
                    pf.Segments.Add(new System.Windows.Media.BezierSegment(p0, p0, ppa, true));
                    Track.Figures.Add(pf);
                    //CreepTrack.Data = Track;
                    //CreepTrack.Stroke = System.Windows.Media.Brushes.Blue;
                    //CreepTrack.StrokeThickness = .5;
                    //CreepTrack.IsHitTestVisible = false;
                    //Arena.instance.AddToArena(CreepTrack);
                }



                Point op;
                Point ta;

                //Track.GetPointAtFractionLength((1 / Arena.instance.TrackLength) * (Progress), out op, out ta);

                //once/if I have a bezier cache, maybe cache the point-at-fraction-lenghts?
                if (Track!=null)
                {
                    
                
                Track.GetPointAtFractionLength((Progress), out op, out ta);


                XPos = (float)op.X;
                YPos = (float)op.Y;
                SetValue(System.Windows.Controls.Canvas.LeftProperty, op.X);
                SetValue(System.Windows.Controls.Canvas.TopProperty, op.Y);

                    // this.RenderTransformOrigin = new Point(0, 0);
                    //this.RenderTransform = null;

                    //this.RenderTransform = new System.Windows.Media.RotateTransform(Math.Atan2(ta.Y, ta.X) * 180 / Math.PI, 0, 0);

                }

                System.Windows.Media.Brush B = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)((Health / MaxHealth) * 255), 0, 0));
                Stroke = B;
                this.InvalidateVisual();
                
               

                
            }

        }
예제 #8
0
        public List<EmptyCell> FindPathCells(EmptyCell PathFrom, EmptyCell PathTo)
        {

            while (Arena.instance.PathInvaliation.Count > 0)
            {
                EmptyCell xxx = Arena.instance.PathInvaliation.Dequeue();
                xxx.ValidatePath();
            }

            System.Collections.Generic.Queue<EmptyCell> Endpoints = new Queue<EmptyCell>();

            EmptyCell backtrace = End;//new Point(End.X, End.Y);
            List<EmptyCell> PathCells = new List<EmptyCell>();

            while ((backtrace != Begin) && (backtrace.ToTarget != null))
            {
                PathCells.Add(backtrace);
                backtrace = (EmptyCell)backtrace.ToTarget[0];
            }

            return PathCells;
        }
예제 #9
0
        public System.Windows.Media.PathFigure FindPath(EmptyCell PathFrom, EmptyCell PathTo)
        {
            //FindPathCells(PathFrom, PathTo);

            EmptyCell backtrace = PathTo;
            EmptyCell Prev1 = PathTo;
            System.Collections.Generic.List<Point> Tracky = new List<Point>();
            System.Windows.Media.PathFigure pf = new System.Windows.Media.PathFigure();
            //Point Prev2 = End;
            //Point Prev3 = End;
            Point p0;
            Point p1;
            Point ppa;

            System.Windows.Media.BezierSegment bs;
            //TrackLength = 0;

            pf.StartPoint = backtrace.CenterPoint;//.TranslatePoint(new Point(21.65, 25), Arena.instance);
            
            //pf.StartPoint = backtrace.TranslatePoint(new Point(21.65, 25), Arena.instance);
            
            foreach (EmptyCell ec in FindPathCells(Begin, End))
//            //while ((backtrace.X != Begin.X || backtrace.Y != Begin.Y) && ((Cells[backtrace].Tag) as Point?).HasValue)
            {
                // ec.Body.Fill = System.Windows.Media.Brushes.Purple;
                backtrace = ec;
              //  TrackLength++;
                // System.Windows.Shapes.Line L = new System.Windows.Shapes.Line();
                // L.X1 = Cells[backtrace].TranslatePoint(new Point(.5, .5), Arena.instance).X + 21.65;
                // L.Y1 = Cells[backtrace].TranslatePoint(new Point(.5, .5), Arena.instance).Y + 25;
                //double xx = 0;
                //double yy = 0;
                //xx = (Cells[backtrace].Tag as Point?).Value.X;
                //yy = (Cells[backtrace].Tag as Point?).Value.Y;

                p0 = backtrace.CenterPoint;// .TranslatePoint(new Point(21.65, 25), Arena.instance);
                p1 = Prev1.CenterPoint;// .TranslatePoint(new Point(21.65, 25), Arena.instance);

                ppa = new Point((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2);

                bs = new System.Windows.Media.BezierSegment(p1, p1, ppa, true);
                pf.Segments.Add(bs);


                //backtrace = new Point(xx, yy);

                //Prev3 = Prev2;
                //Prev2 = Prev1;
                Prev1 = ec;

                // L.X2 = Cells[new Point(xx, yy)].TranslatePoint(new Point(.5, .5), Arena.instance).X + 21.65;
                // L.Y2 = Cells[new Point(xx, yy)].TranslatePoint(new Point(.5, .5), Arena.instance).Y + 25;

                // L.Stroke = System.Windows.Media.Brushes.Green;
                // L.StrokeThickness = 4;
                //L.IsHitTestVisible = false;
                //L.Fill = System.Windows.Media.Brushes.Green;
                //L.Opacity = 1;

                //Arena.instance.Children.Add(L);
                //PathLines.Enqueue(L);

            
            }
            p0 = backtrace.CenterPoint;//.TranslatePoint(new Point(21.65, 25), Arena.instance);
            p1 = Prev1.CenterPoint;//.TranslatePoint(new Point(21.65, 25), Arena.instance);

            ppa = new Point((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2);

            bs = new System.Windows.Media.BezierSegment(p1, p1, ppa, true);
            pf.Segments.Add(bs);

            return pf;
        }
예제 #10
0
        // Create a DrawingVisual that contains a rectangle.
//        MyVisualHost mvh = new MyVisualHost();
        
        protected override void OnInitialized(EventArgs e)
        {
            //base.OnInitialized(e);
            Arena.instance = this;

            NACellColor[0] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 0f, 1f);
            NACellColor[1] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 0f);
            NACellColor[2] = System.Windows.Media.Color.FromScRgb(.1f, 0f, 1f, 1f);
            NACellColor[3] = System.Windows.Media.Color.FromScRgb(.1f, 1f, 0f, 0f);
           // NACellColor[4] = System.Windows.Media.Color.FromScRgb(1f, 1f, 0f, 1f);
          //  NACellColor[5] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 0f);
          //  NACellColor[6] = System.Windows.Media.Color.FromScRgb(1f, 1f, 1f, 1f);

            
  //          mvh.IsHitTestVisible = false;
    //        mvh.SetValue(Canvas.ZIndexProperty, 99);
      //      mvh.SetValue(System.Windows.Media.RenderOptions.EdgeModeProperty, System.Windows.Media.EdgeMode.Aliased);
        //    this.Children.Add(mvh);

            //this

            this.Loaded += new RoutedEventHandler(Arena_Loaded);

       


            //Debug.Content = Arena.instance.Children[0].GetType().ToString();
            bool AltRowToggle = false;
            bool AltColToggle = false;
            int xx = 0;
            int yy = 0;

            NACells[0] = new List<EmptyCell>();
            NACells[1] = new List<EmptyCell>();
            NACells[2] = new List<EmptyCell>();
            NACells[3] = new List<EmptyCell>();

            for (double y = -36.6; y < 707; y += 36.6)
            {
                yy += 1;
                xx = 0;
                AltRowToggle = !AltRowToggle;
                for (double x = -43.3; x < 930.95; x += 43.3)
                {
                    AltColToggle = !AltColToggle;
                    double mx = x;
                    if (!AltRowToggle)
                    {
                        mx += 21.65;
                    }
                    xx += 1;

                    //UIElement b;
                    EmptyCell b = new EmptyCell();

                    int qq = 0;
                    if (AltColToggle) qq += 1;
                    if (AltRowToggle) qq += 2;
                    
                    b.Body.Fill = new System.Windows.Media.SolidColorBrush(NACellColor[qq]);
                    NACells[qq].Add(b);
                    
                    b.CenterPoint = new Point(mx+21.65,y+25);
                    //Height="50" Width="43.3"

                    if (mx < 0 || mx >= 866 || y < 0 || y >= 707 - 36.6)//- 43.3 
                    {
                        b.Occupant = new Block();
                        b.Occupied = true;
                    }
                    else
                    {
                        // b = new EmptyCell();
                        Cells.Add(new Point(xx, yy), b as EmptyCell);
                        Arena.instance.PathInvaliation.Enqueue(b);
                    }



                    b.SetValue(Canvas.TopProperty, y);
                    b.SetValue(Canvas.LeftProperty, mx);
                    Arena.instance.Children.Add(b);
                    if (b.Occupant as UIElement != null)
                    {
                        UIElement bo = b.Occupant as UIElement;
                        bo.SetValue(Canvas.TopProperty, y);
                        bo.SetValue(Canvas.LeftProperty, mx);

                        Arena.instance.Children.Add(b.Occupant as UIElement);
                    }
                    PathInvaliation.Enqueue(b);
                }


            }



            foreach (Point P in Cells.Keys)
            {
                //if (Cells[P].Occupied == false)
                {
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y)]);
                    }
                    catch
                    { }

                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y - 1)]);
                    }
                    catch
                    { }
                    try
                    {
                        Cells[P].Adjacent.Add(Cells[new Point(P.X, P.Y + 1)]);
                    }
                    catch
                    { }

                    if ((P.Y / 2) == Math.Floor(P.Y / 2))
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X + 1, P.Y + 1)]);
                        }
                        catch
                        { }

                    }
                    else
                    {
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y - 1)]);
                        }
                        catch
                        { }
                        try
                        {
                            Cells[P].Adjacent.Add(Cells[new Point(P.X - 1, P.Y + 1)]);
                        }
                        catch
                        { }

                    }
                }

                //Arena.instance.MouseMove += new System.Windows.Input.MouseEventHandler(instance_MouseMove);

                
            }


            Begin = Cells[new Point(2, 2)];
            End = Cells[new Point(21, 20)];


            CreepSpawn c = new CreepSpawn();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            TheSpawner = c;
            c.SetValue(Canvas.TopProperty, End.GetValue(Canvas.TopProperty));
            c.SetValue(Canvas.LeftProperty, End.GetValue(Canvas.LeftProperty));

            Begin.Occupant = c as IArenaObject;
            //c.Opacity = .5;
            Arena.instance.Children.Add(c);

            CreepTarget d = new CreepTarget();// Tower((TowerType)Enum.Parse(TT.GetType(), Towers.SelectedItem.ToString()));

            d.SetValue(Canvas.TopProperty, Begin.GetValue(Canvas.TopProperty));
            d.SetValue(Canvas.LeftProperty, Begin.GetValue(Canvas.LeftProperty));

            End.Occupant = d as IArenaObject;
            //d.Opacity = .5;
            Arena.instance.Children.Add(d);

            /*
            System.Windows.Shapes.Line L = new System.Windows.Shapes.Line();
            L.X1 = 0;
            L.Y1 = 0;

            L.X2 = Begin.TranslatePoint(new Point(.5, .5), Arena.instance).X;
            L.Y2 = 500;

            L.Stroke = System.Windows.Media.Brushes.Salmon;
            L.StrokeThickness = 5;
            L.Fill = System.Windows.Media.Brushes.PowderBlue;
            L.Opacity = 1;

            Arena.instance.Children.Add(L);
            */


            Arena.instance.MouseLeave += new System.Windows.Input.MouseEventHandler(instance_MouseLeave);
            Arena.instance.MouseDown += new System.Windows.Input.MouseButtonEventHandler(instance_MouseDown);

            Arena.instance.FindPathCells(Begin, End);

           // this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(Hooks_DispatcherInactive);

            //System.Windows.Media.CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

            DT = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Background);

            


            DT.Tick += new EventHandler(DT_Tick);
            
            DT.Interval = TimeSpan.FromSeconds(.01);
            DT.Start();
            

        }
예제 #11
0
        public void InnerTick(int Frame)
        {
            if (Health < 0)
            {
                Die(this);
                return;
            }

            Progress += 0.01;

            if (Progress < 0)
            {
                this.Visibility = Visibility.Hidden;
            }
            else
            {
                if (this.Visibility == Visibility.Hidden)
                {
                    this.Visibility = Visibility.Visible;
                    Arena.instance.AddToArena(this);
                }


                if (Progress >= .75)//|| NextCell != CurrentCell.ToTarget[Counter % CurrentCell.ToTarget.Count]
                {
                    PreviousCell = CurrentCell;

                    lock (CurrentCell.CreepsInCell)
                    {
                        CurrentCell.CreepsInCell.Remove(this);
                    }
                    CurrentCell = NextCell;
                    lock (CurrentCell.CreepsInCell) CurrentCell.CreepsInCell.Add(this);
                    if (CurrentCell.ToTarget.Count == 0)
                    {
                        // no prize for failure.
                        Bounty = 0;

                        // remove the creep from play.
                        Die(this);

                        if (Arena.instance.Lifes-- <= 0)
                        {
                            // Game Over.
                            //MessageBox.Show("Game Over");
                        }
                    }
                    else// if (CurrentCell.ToTarget.Count == 1)
                    {
                        // NextCell = CurrentCell.ToTarget[0];
                        //}
                        //else
                        //{

                        if ((Counter & 1) == 0)
                        {
                            Counter >>= 2;
                        }
                        else
                        {
                            Counter >>= 2;
                            Counter   = Counter | 1073741824;
                        }
                        NextCell = CurrentCell.ToTarget[Counter % CurrentCell.ToTarget.Count];
                    }
                    Progress -= 0.5;

                    // PERF:

                    // Generating Bezier's is expensive; some kind of cache...? or not generate per creep*per frame...

                    // should only be 30 possible curves
                    //

                    Track = new System.Windows.Media.PathGeometry();
                    System.Windows.Media.PathFigure pf = new System.Windows.Media.PathFigure();
                    pf.StartPoint = new Point(PreviousCell.CenterPoint.X, PreviousCell.CenterPoint.Y);
                    Point p0 = new Point(CurrentCell.CenterPoint.X, CurrentCell.CenterPoint.Y);
                    //Point p1 = new Point(CurrentCell.CenterPoint.X, CurrentCell.CenterPoint.Y);
                    Point ppa = new Point(NextCell.CenterPoint.X, NextCell.CenterPoint.Y);
                    //System.Windows.Media.BezierSegment bs;
                    //bs = ;
                    pf.Segments.Add(new System.Windows.Media.BezierSegment(p0, p0, ppa, true));
                    Track.Figures.Add(pf);
                    //CreepTrack.Data = Track;
                    //CreepTrack.Stroke = System.Windows.Media.Brushes.Blue;
                    //CreepTrack.StrokeThickness = .5;
                    //CreepTrack.IsHitTestVisible = false;
                    //Arena.instance.AddToArena(CreepTrack);
                }



                Point op;
                Point ta;

                //Track.GetPointAtFractionLength((1 / Arena.instance.TrackLength) * (Progress), out op, out ta);

                //once/if I have a bezier cache, maybe cache the point-at-fraction-lenghts?
                if (Track != null)
                {
                    Track.GetPointAtFractionLength((Progress), out op, out ta);


                    XPos = (float)op.X;
                    YPos = (float)op.Y;
                    SetValue(System.Windows.Controls.Canvas.LeftProperty, op.X);
                    SetValue(System.Windows.Controls.Canvas.TopProperty, op.Y);

                    // this.RenderTransformOrigin = new Point(0, 0);
                    //this.RenderTransform = null;

                    //this.RenderTransform = new System.Windows.Media.RotateTransform(Math.Atan2(ta.Y, ta.X) * 180 / Math.PI, 0, 0);
                }

                System.Windows.Media.Brush B = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)((Health / MaxHealth) * 255), 0, 0));
                Stroke = B;
                this.InvalidateVisual();
            }
        }
예제 #12
0
        static private void PPThread(object whic)
        {
            int?w = whic as int?;

            if (w == null)
            {
                return;
            }

            while (Window1.AppIsClosing == false)
            {
                SyncIn[(int)w].Reset();
                //int x = 0;
                foreach (Projectile P in Projectiles)
                {
                    if ((P.pIndex % ThreadCount) == w)
                    {
                        // lock (P)
                        {
                            EmptyCell OverCell = null;
                            //ValidTargets

                            P.Flight--;
                            //P.XPos += (P.XVel );
                            //P.YPos += (P.YVel );
                            int Frames = Arena.instance.Frame - P.AquiredFrame; // bad reaching out of scope
                            int cxPos  = (int)(P.XPos + P.XVel * Frames);
                            int cyPos  = (int)(P.YPos + P.YVel * Frames);

                            if (P.Flight <= 0)
                            {
                                Released[(int)w].Enqueue(P);
                            }
                            else
                            {
                                int py = (int)Math.Round((cyPos / 36.6) + 1);
                                int px;
                                if ((py) % 2 == 1)
                                {
                                    px = (int)Math.Round(((cxPos + 21.65) / 43.3) + 1);
                                }
                                else
                                {
                                    px = (int)Math.Round((cxPos / 43.3) + 1);
                                }

                                Point p = new Point(px, py);


                                OverCell       = null;
                                P.ValidTargets = new List <Creep>();

                                if (Arena.instance.Cells.ContainsKey(p))
                                {
                                    OverCell = Arena.instance.Cells[p];
                                }
                                if (OverCell != null)
                                {
                                    //lock (OverCell)
                                    {
                                        lock (OverCell.CreepsInCell)
                                        {
                                            if (OverCell.CreepsInCell.Count > 0)
                                            {
                                                P.ValidTargets.AddRange(OverCell.CreepsInCell);
                                            }
                                        }
                                        foreach (EmptyCell NearCell in OverCell.Adjacent)
                                        {
                                            lock (NearCell.CreepsInCell)
                                            {
                                                if (NearCell.CreepsInCell.Count > 0)
                                                {
                                                    P.ValidTargets.AddRange(NearCell.CreepsInCell);
                                                }
                                            }
                                        }
                                    }
                                }
                                Double NearestCreepDistanceSquared = (10) * (10);
                                P.NearestCreep = null;

                                foreach (Creep C in P.ValidTargets)
                                {
                                    lock (C)
                                    {
                                        if (C != null)
                                        {
                                            if (C.IsAlive == true)
                                            {
                                                float XD = (cxPos - C.XPos);
                                                float YD = (cyPos - C.YPos);
                                                float DS = (XD)*(XD) + (YD)*(YD);

                                                if (DS < NearestCreepDistanceSquared)
                                                {
                                                    NearestCreepDistanceSquared = DS;
                                                    P.NearestCreep = C;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //end per projectile
                    }
                }
                SyncIn[(int)w].Set();
                SyncOut[(int)w].Reset();
                SyncOut[(int)w].WaitOne();
                //lock (SyncIn[(int)w])
                //System.Threading.AutoResetEvent.SignalAndWait(SyncIn[(int)w], SyncIn[(int)w]);
            }
        }