コード例 #1
0
        private bool IntersectsVP(Rectangle rect)
        {
            if (this.matrixNoRot)
            {
                bool isIntersects;
                this.viewport.Intersects(ref rect, out isIntersects);
                return(isIntersects);
            }
            else
            {
                var     mt = this.matrix.Value;
                Vector2 lt = new Vector2(rect.Left, rect.Top),
                        rt = new Vector2(rect.Right, rect.Top),
                        lb = new Vector2(rect.Left, rect.Bottom),
                        rb = new Vector2(rect.Right, rect.Bottom);
                Vector2.Transform(ref lt, ref mt, out lt);
                Vector2.Transform(ref rt, ref mt, out rt);
                Vector2.Transform(ref lb, ref mt, out lb);
                Vector2.Transform(ref rb, ref mt, out rb);

                int  left   = (int)Math.Floor(MathHelper2.Min(lt.X, rt.X, lb.X, rb.X));
                int  top    = (int)Math.Floor(MathHelper2.Min(lt.Y, rt.Y, lb.Y, rb.Y));
                int  right  = (int)Math.Ceiling(MathHelper2.Max(lt.X, rt.X, lb.X, rb.X));
                int  bottom = (int)Math.Ceiling(MathHelper2.Max(lt.Y, rt.Y, lb.Y, rb.Y));
                var  bound  = new Rectangle(left, top, right - left, bottom - top);
                bool isIntersects;
                this.viewport.Intersects(ref bound, out isIntersects);
                return(isIntersects);
            }
        }
コード例 #2
0
        private void DrawFootholds(GameTime gameTime)
        {
            var color = MathHelper2.HSVtoColor((float)gameTime.TotalGameTime.TotalSeconds * 100 % 360, 1f, 1f);

            if (patchVisibility.FootHoldVisible)
            {
                var lines = new List <Point>();
                foreach (LayerNode layer in this.mapData.Scene.Layers.Nodes)
                {
                    var fhList = layer.Foothold.Nodes.OfType <ContainerNode <FootholdItem> >()
                                 .Select(container => container.Item);
                    foreach (var fh in fhList)
                    {
                        lines.Add(new Point(fh.X1, fh.Y1));
                        lines.Add(new Point(fh.X2, fh.Y2));
                    }
                }

                if (lines.Count > 0)
                {
                    var meshItem = this.batcher.MeshPop();
                    meshItem.RenderObject = new LineListMesh(lines.ToArray(), color, 2);
                    this.batcher.Draw(meshItem);
                    this.batcher.MeshPush(meshItem);
                }
            }

            if (patchVisibility.LadderRopeVisible)
            {
                var lines      = new List <Point>();
                var ladderList = this.mapData.Scene.Fly.LadderRope.Slots.OfType <LadderRopeItem>();
                foreach (var item in ladderList)
                {
                    lines.Add(new Point(item.X, item.Y1));
                    lines.Add(new Point(item.X, item.Y2));
                }

                if (lines.Count > 0)
                {
                    var meshItem = this.batcher.MeshPop();
                    meshItem.RenderObject = new LineListMesh(lines.ToArray(), color, 3);
                    this.batcher.Draw(meshItem);
                    this.batcher.MeshPush(meshItem);
                }
            }

            if (patchVisibility.SkyWhaleVisible)
            {
                var lines        = new List <Point>();
                var skyWhaleList = this.mapData.Scene.Fly.SkyWhale.Slots.OfType <SkyWhaleItem>();
                foreach (var item in skyWhaleList)
                {
                    foreach (var dx in new[] { 0, -item.Width / 2, item.Width / 2 })
                    {
                        Point start = new Point(item.Start.X + dx, item.Start.Y);
                        Point end   = new Point(item.End.X + dx, item.End.Y);
                        //画箭头
                        lines.Add(start);
                        lines.Add(end);
                        lines.Add(end);
                        lines.Add(new Point(end.X - 5, end.Y + 8));
                        lines.Add(end);
                        lines.Add(new Point(end.X + 5, end.Y + 8));
                    }
                }

                if (lines.Count > 0)
                {
                    var meshItem = this.batcher.MeshPop();
                    meshItem.RenderObject = new LineListMesh(lines.ToArray(), color, 1);
                    this.batcher.Draw(meshItem);
                    this.batcher.MeshPush(meshItem);
                }
            }
        }