void NodeChange()
        {
            LinkedListNode <GameObject> CurrentNode = Nodes.Value.First;

            while (CurrentNode != null)
            {
                WallNode n = (WallNode)CurrentNode.Value;
                n.ParentChain = this;

                MinPos = Logic.Min(MinPos, n.Position.get());
                MaxPos = Logic.Max(MaxPos, n.Position.get());

                if (CurrentNode.Previous == null)
                {
                    n.SetQuadGridPosition();
                }

                if (CurrentNode.Next != null)
                {
                    WallNode n2 = (WallNode)CurrentNode.Next.Value;

                    if (n2.wallConnector == null)
                    {
                        n2.wallConnector = new WallConnector(n2);
                    }
                    n2.wallConnector.SetFrom(n.Position.get(), n2.Position.get(), Math.Min(n.Size.X(), n2.Size.X()));
                    n2.SetQuadGridPosition(Logic.Min(n.Position.get() - n.Size.get() / 2, n2.Position.get() - n2.Size.get() / 2), Logic.Max(n.Position.get() + n.Size.get() / 2, n2.Position.get() + n2.Size.get() / 2));
                }

                CurrentNode = CurrentNode.Next;
            }
        }
        public void DrawFromMiniMap(Vector2 Position, float Size, Vector2 Min, Vector2 Max)
        {
            if (this.MinPos.X > Max.X || this.MinPos.Y > Max.Y || this.MaxPos.X < Min.X || this.MaxPos.Y < Min.Y)
            {
                return;
            }

            LinkedListNode <GameObject> Node = Nodes.Value.First;

            while (Node != null)
            {
                WallNode n = (WallNode)Node.Value;
                if (Node.Next != null)
                {
                    WallNode n2 = (WallNode)Node.Next.Value;

                    Vector2 MapPosition = (n.Position.get() - Min) /
                                          (Max - Min) * Size + Position;
                    Vector2 MapPosition2 = (n2.Position.get() - Min) /
                                           (Max - Min) * Size + Position;

                    Vector2 MPosition = Position + new Vector2(Size);

                    MapPosition  = Logic.Clamp(MapPosition, Position, MPosition);
                    MapPosition2 = Logic.Clamp(MapPosition2, Position, MPosition);

                    Render.DrawLine(MapPosition, MapPosition2, Color.Gray);
                }
                Node = Node.Next;
            }
        }
        private void AddNode(Button b)
        {
            Vector2 p = Vector2.Zero;

            if (Nodes.Value.Count > 0)
            {
                WallNode n = (WallNode)Nodes.Value.Last.Value;
                p = n.Position.get();
            }

            WallNode a;

            Nodes.add(Add(a = new WallNode()));
            a.Position.set(p);
        }
示例#4
0
        private void commitWorldBlocker(Basic2DObject w)
        {
            Vector2 UpperLeftCorner  = (w.getUpperLeftCorner() - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f);
            Vector2 LowerRightCorner = (w.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f);
            Vector2 Center           = (w.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor;

            int MinX = (int)UpperLeftCorner.X;
            int MinY = (int)UpperLeftCorner.Y;
            int MaxX = (int)LowerRightCorner.X;
            int MaxY = (int)LowerRightCorner.Y;

            for (int x = MinX; x < MaxX + 1; x++)
            {
                for (int y = MinY; y < MaxY + 1; y++)
                {
                    CellGrid[x, y] = DeadCell;
                }
            }

            if (w.GetType().Equals(typeof(WallNode)))
            {
                WallNode s = (WallNode)w;
                if (s.wallConnector != null)
                {
                    UpperLeftCorner  = Logic.Min(UpperLeftCorner, (s.wallConnector.PositionNext - s.Size.get() / 2 - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f));
                    LowerRightCorner = Logic.Max(LowerRightCorner, (s.wallConnector.PositionNext + s.Size.get() / 2 - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f));

                    MinX = (int)UpperLeftCorner.X;
                    MinY = (int)UpperLeftCorner.Y;
                    MaxX = (int)LowerRightCorner.X;
                    MaxY = (int)LowerRightCorner.Y;

                    for (int x = MinX; x < MaxX + 1; x++)
                    {
                        for (int y = MinY; y < MaxY + 1; y++)
                        {
                            if (Logic.DistanceLineSegmentToPoint(s.Position.get(), s.wallConnector.PositionNext,
                                                                 (new Vector2(x, y) - new Vector2(0.5f)) * Divisor + Parent2DScene.MinBoundary.get()) < w.Size.X())
                            {
                                CellGrid[x, y] = DeadCell;
                            }
                        }
                    }
                }
            }
        }
        public override void Draw2D(GameObjectTag DrawTag)
        {
            LinkedListNode <GameObject> Node = Nodes.Value.First;

            while (Node != null)
            {
                WallNode n = (WallNode)Node.Value;
                Render.DrawSprite(NodeTexture, n.Position, n.Size, n.Rotation);
                if (Node.Next != null)
                {
                    WallNode n2 = (WallNode)Node.Next.Value;
                    Render.DrawSquare(n.Position.get(), n2.Position.get(), (int)(n.Size.X() / 2), ConnectorTexture, Color.White);
                }
                Node = Node.Next;
            }


            base.Draw2D(DrawTag);
        }
示例#6
0
        public void rebuild()
        {
            CellJobQue.Clear();

            for (int x = 0; x < CellsX.get(); x++)
            {
                for (int y = 0; y < CellsY.get(); y++)
                {
                    CellGrid[x, y] = NeutralCell;
                }
            }

            foreach (GameObject o in ParentScene.Children)
            {
                if (o.GetType().Equals(typeof(MineralRock)))
                {
                    MineralRock s = (MineralRock)o;
                    //if (s.miningPlatform == null)
                    //  commitWorldBlocker(s);
                }
                else if (o.GetType().IsSubclassOf(typeof(SolidStaticWorldObject)))
                {
                    SolidStaticWorldObject s = (SolidStaticWorldObject)o;
                    commitWorldBlocker(s);
                }
                else if (o.GetType().Equals(typeof(WallNode)))
                {
                    WallNode s = (WallNode)o;
                    commitWorldBlocker(s);
                }
            }

            foreach (MiningPlatform r in Parent2DScene.Enumerate(typeof(MiningPlatform)))
            {
                if (!r.Dead)
                {
                    addMineralRock(r);
                }
            }
        }
        public void TestCollision(GameTime gameTime)
        {
            foreach (Basic2DObject o in Parent2DScene.quadGrids.First.Value.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax))
            {
                if (o != this)
                {
                    if (o.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
                    {
                        if (Vector2.Distance(Position.get(), o.Position.get()) < (Size.X() + o.Size.X()) / 2)
                        {
                            BasicShipGameObject s = (BasicShipGameObject)o;
                            Collide(gameTime, s.ReturnCollision());
                            if (Dead)
                            {
                                return;
                            }
                        }
                    }
                    else
                    {
                        WallNode n = (WallNode)o;

                        if (Vector2.Distance(Position.get(), o.Position.get()) < (Size.X() + o.Size.X()) / 2)
                        {
                            float MoveAmount = (Size.X() + o.getSize().X) / 2 - Vector2.Distance(o.Position.get(), Position.get());

                            if (Vector2.Distance(o.Position.get(), Position.get()) > 0.1f)
                            {
                                Position.set(Position.get() + Vector2.Normalize(Position.get() - o.Position.get()) * MoveAmount);
                            }
                            else
                            {
                                Position.set(Position.get() + Vector2.One * MoveAmount * 2);
                            }
                        }
                        if (n.wallConnector != null)
                        {
                            float MoveAmount = (Size.X() + o.getSize().X * 0.75f) / 2 - Logic.DistanceLineSegmentToPoint(n.Position.get(), n.wallConnector.PositionNext, Position.get());

                            if (MoveAmount > 0)
                            {
                                Vector2 MoveVector;
                                if (!n.wallConnector.LineIsVertical)
                                {
                                    if (n.wallConnector.LineSlope == 0)
                                    {
                                        MoveVector = new Vector2(0, -1);
                                        if (Position.Y() > n.wallConnector.LineSlope * Position.X() + n.wallConnector.LineIntercept)
                                        {
                                            MoveAmount = -MoveAmount;
                                        }
                                    }
                                    else
                                    {
                                        MoveVector = new Vector2(1, -1 / n.wallConnector.LineSlope);
                                        if (!(Position.Y() > n.wallConnector.LineSlope * Position.X() + n.wallConnector.LineIntercept ^ n.wallConnector.LineSlope > 0))
                                        {
                                            MoveAmount = -MoveAmount;
                                        }
                                    }

                                    MoveVector.Normalize();
                                }
                                else
                                {
                                    MoveVector = new Vector2(Position.X() > n.Position.X() ? 1 : -1, 0);
                                }

                                Position.set(Position.get() + MoveVector * MoveAmount);
                            }
                        }
                    }
                }
            }
        }
 public WallConnector(WallNode ParentNode)
 {
     this.ParentNode = ParentNode;
 }
示例#9
0
        public override void Update(GameTime gameTime, BasicController MyController)
        {
            if (!Dashing)
            {
                RechargeTime += gameTime.ElapsedGameTime.Milliseconds;
                if (MyController.LeftStick().Length() > 0.1f)
                {
                    DashVector = Vector2.Normalize(MyController.LeftStick() * new Vector2(1, -1));
                }
            }
            else
            {
                ParentShip.AddPosition(DashVector * DashSpeed * gameTime.ElapsedGameTime.Milliseconds / 1000f * 60f);
                ParentShip.InvTime = Math.Max(ParentShip.InvTime, 400);
                DashTime          += gameTime.ElapsedGameTime.Milliseconds;

                if (DashTime > MaxDashTime)
                {
                    bool PositionClear = true;
                    foreach (Basic2DObject s in ParentShip.Parent2DScene.quadGrids.First.Value.Enumerate(
                                 ParentShip.Position.get(), new Vector2(ParentShip.PlayerSize)))
                    {
                        if (s != ParentShip)
                        {
                            if (s.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
                            {
                                if (Vector2.Distance(ParentShip.getPosition(), s.getPosition()) < (ParentShip.PlayerSize + s.getSize().X) / 2)
                                {
                                    BasicShipGameObject b = (BasicShipGameObject)s;
                                    if (b.Solid)
                                    {
                                        PositionClear = false;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                WallNode n = (WallNode)s;
                                if (n.wallConnector != null)
                                {
                                    float MoveAmount = (ParentShip.PlayerSize + s.getSize().X * 0.75f) / 2 - Logic.DistanceLineSegmentToPoint(n.Position.get(), n.wallConnector.PositionNext, ParentShip.Position.get());

                                    if (MoveAmount > 0)
                                    {
                                        PositionClear = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (PositionClear && Dashing)
                    {
                        SoundManager.Play3DSound("PlayerDashReverse",
                                                 new Vector3(ParentShip.Position.X(), ParentShip.Y, ParentShip.Position.Y()), 0.2f, 300, 2);

                        Dashing = false;
                        Vector3 Position3 = new Vector3(ParentShip.Position.X(), ParentShip.Y, ParentShip.Position.Y());
                        ParticleManager.CreateParticle(Position3, Vector3.Zero, PlayerShip.TeleportColor2, ParentShip.Size.X() * 5, 4);
                        for (int i = 0; i < 30; i++)
                        {
                            ParticleManager.CreateParticle(Position3, Rand.V3() * 200, PlayerShip.TeleportColor2, 20, 5);
                        }
                    }
                }
            }

            base.Update(gameTime, MyController);
        }