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;
            }
        }
 private void UpdateMapPosition()
 {
     if (GetTeam() == WaveManager.ActiveTeam)
     {
         OverMap.TargetMax = Logic.Max(Position.get() + new Vector2(1000), OverMap.TargetMax);
         OverMap.TargetMin = Logic.Min(Position.get() - new Vector2(1000), OverMap.TargetMin);
     }
 }
Ejemplo n.º 3
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 Update(GameTime gameTime)
        {
            Vector2 StartPosition = Position.get();
            Vector2 EndPosition   = Position.get() + Vector2.Normalize(Speed) * 600;

            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 5);
            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 7);
            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 4);

            for (int i = 0; i < 100; i++)
            {
                ParticleManager.CreateParticle(
                    new Vector3(StartPosition.X, 0, StartPosition.Y) + (new Vector3(EndPosition.X - StartPosition.X, 0, EndPosition.Y - StartPosition.Y) * i / 100),
                    Vector3.Zero, ParticleColor, 150, 5);
            }

            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 5);
            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 7);
            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 4);

            QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value;

            Vector2 UpperLeftCorner  = Logic.Min(StartPosition, EndPosition) - new Vector2(200);
            Vector2 LowerRightCorner = Logic.Max(StartPosition, EndPosition) + new Vector2(200);

            QuadGridXMin = (int)((UpperLeftCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridXMax = (int)((LowerRightCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridYMin = (int)((UpperLeftCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);
            QuadGridYMax = (int)((LowerRightCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);

            foreach (Basic2DObject g in quadGrid.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax))
            {
                if (g.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
                {
                    BasicShipGameObject s = (BasicShipGameObject)g;
                    if (!s.IsAlly(ParentUnit) && CheckCircle(s, StartPosition, EndPosition, AttackLineWidth))
                    {
                        s = s.ReturnCollision();
                        s.Damage(Damage, 1, EndPosition - StartPosition, ParentUnit, AttackType.Red);
                    }
                }
            }

            Destroy();
        }
Ejemplo n.º 5
0
        public override void Update(GameTime gameTime)
        {
            float dist = BeamTurretCard.EngagementDistance;

            Vector2 StartPosition = Position.get();
            Vector2 EndPosition   = Position.get() + Vector2.Normalize(Speed) * dist;

            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 5);
            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, ParticleColor, 300, 4);
            for (int i = 0; i < 75; i++)
            {
                ParticleManager.CreateParticle(
                    new Vector3(StartPosition.X, 0, StartPosition.Y) + (new Vector3(EndPosition.X - StartPosition.X, 0, EndPosition.Y - StartPosition.Y) * i / 75),
                    Vector3.Zero, ParticleColor, 100, 5);
            }

            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 5);
            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, ParticleColor, 300, 4);

            QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value;

            Vector2 UpperLeftCorner  = Logic.Min(StartPosition, EndPosition) - new Vector2(200);
            Vector2 LowerRightCorner = Logic.Max(StartPosition, EndPosition) + new Vector2(200);

            QuadGridXMin = (int)((UpperLeftCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridXMax = (int)((LowerRightCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridYMin = (int)((UpperLeftCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);
            QuadGridYMax = (int)((LowerRightCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);

            if (QuadGridXMax > quadGrid.CellsX - 1)
            {
                QuadGridXMax = quadGrid.CellsX - 1;
            }
            if (QuadGridXMin > quadGrid.CellsX - 1)
            {
                QuadGridXMin = quadGrid.CellsX - 1;
            }
            if (QuadGridYMax > quadGrid.CellsY - 1)
            {
                QuadGridYMax = quadGrid.CellsY - 1;
            }
            if (QuadGridYMin > quadGrid.CellsY - 1)
            {
                QuadGridYMin = quadGrid.CellsY - 1;
            }
            if (QuadGridXMax < 0)
            {
                QuadGridXMax = 0;
            }
            if (QuadGridXMin < 0)
            {
                QuadGridXMin = 0;
            }
            if (QuadGridYMax < 0)
            {
                QuadGridYMax = 0;
            }
            if (QuadGridYMin < 0)
            {
                QuadGridYMin = 0;
            }

            foreach (Basic2DObject g in quadGrid.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax))
            {
                if (g.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
                {
                    BasicShipGameObject s = (BasicShipGameObject)g;
                    if (!s.IsAlly(ParentUnit) && CheckCircle(s, StartPosition, EndPosition, AttackLineWidth))
                    {
                        s = s.ReturnCollision();
                        if (s != null)
                        {
                            s.Damage(Damage, 4, EndPosition - StartPosition, ParentUnit, AttackType.Green);
                        }
                    }
                }
            }

            Destroy();
        }
Ejemplo n.º 6
0
        public void FireShot(Vector2 StartPosition, Vector2 EndPosition, float LineWidth)
        {
            SoundManager.Play3DSound("SiegeLaserFire", new Vector3(Position.X(), Y, Position.Y()), 0.75f, 1000, 1.5f);

            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, LaserColor, 300, 5);
            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, LaserColor, 300, 7);
            ParticleManager.CreateParticle(new Vector3(StartPosition.X, 0, StartPosition.Y), Vector3.Zero, LaserColor, 300, 4);

            int c = (int)Vector2.Distance(StartPosition, EndPosition) / 10;

            for (int i = 0; i < c; i++)
            {
                ParticleManager.CreateParticle(
                    new Vector3(StartPosition.X, 0, StartPosition.Y) + (new Vector3(EndPosition.X - StartPosition.X, 0, EndPosition.Y - StartPosition.Y) * i / c),
                    Vector3.Zero, LaserColor, 100, 5);
            }

            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, LaserColor, 300, 5);
            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, LaserColor, 300, 7);
            ParticleManager.CreateParticle(new Vector3(EndPosition.X, 0, EndPosition.Y), Vector3.Zero, LaserColor, 300, 4);

            QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value;

            Vector2 UpperLeftCorner  = Logic.Min(StartPosition, EndPosition) - new Vector2(200);
            Vector2 LowerRightCorner = Logic.Max(StartPosition, EndPosition) + new Vector2(200);

            QuadGridXMin = (int)((UpperLeftCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridXMax = (int)((LowerRightCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridYMin = (int)((UpperLeftCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);
            QuadGridYMax = (int)((LowerRightCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);

            if (QuadGridXMax > quadGrid.CellsX - 1)
            {
                QuadGridXMax = quadGrid.CellsX - 1;
            }
            if (QuadGridXMin > quadGrid.CellsX - 1)
            {
                QuadGridXMin = quadGrid.CellsX - 1;
            }
            if (QuadGridYMax > quadGrid.CellsY - 1)
            {
                QuadGridYMax = quadGrid.CellsY - 1;
            }
            if (QuadGridYMin > quadGrid.CellsY - 1)
            {
                QuadGridYMin = quadGrid.CellsY - 1;
            }
            if (QuadGridXMax < 0)
            {
                QuadGridXMax = 0;
            }
            if (QuadGridXMin < 0)
            {
                QuadGridXMin = 0;
            }
            if (QuadGridYMax < 0)
            {
                QuadGridYMax = 0;
            }
            if (QuadGridYMin < 0)
            {
                QuadGridYMin = 0;
            }

            foreach (Basic2DObject g in quadGrid.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax))
            {
                if (g.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
                {
                    BasicShipGameObject s = (BasicShipGameObject)g;
                    if (!s.IsAlly(this) && CheckCircle(s, StartPosition, EndPosition, LineWidth))
                    {
                        s = s.ReturnCollision();
                        s.Damage(LaserDamage * GetDamageMult(), 1, EndPosition - StartPosition, this, AttackType.Red);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void TestCollisions()
        {
            QuadGrid quadGrid = Parent2DScene.quadGrids.First.Value;

            Vector2 UpperLeftCorner  = Vector2.Zero;
            Vector2 LowerRightCorner = Vector2.Zero;

            if (SearchTime < MaxSearchTime)
            {
                UpperLeftCorner  = Logic.Min(PreviousPosition, getPosition());
                LowerRightCorner = Logic.Max(PreviousPosition, getPosition());
            }
            else
            {
                SearchTime       = 0;
                UpperLeftCorner  = Logic.Min(PreviousPosition, getPosition() - BulletDodgeDistance);
                LowerRightCorner = Logic.Max(PreviousPosition, getPosition() + BulletDodgeDistance);
            }

            if (UpperLeftCorner.X < quadGrid.Min.X || UpperLeftCorner.Y < quadGrid.Min.Y ||
                LowerRightCorner.X > quadGrid.Max.X || LowerRightCorner.Y > quadGrid.Max.Y)
            {
                return;
            }

            QuadGridXMin = (int)((UpperLeftCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridXMax = (int)((LowerRightCorner.X - quadGrid.Min.X) / quadGrid.CellSize.X);
            QuadGridYMin = (int)((UpperLeftCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);
            QuadGridYMax = (int)((LowerRightCorner.Y - quadGrid.Min.Y) / quadGrid.CellSize.Y);

            foreach (Basic2DObject g in quadGrid.Enumerate(QuadGridXMin, QuadGridYMin, QuadGridXMax, QuadGridYMax))
            {
                if (g.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
                {
                    if (CheckCircle(g))
                    {
                        BasicShipGameObject s = (BasicShipGameObject)g;
                        s = s.ReturnCollision();
                        if (s != null && s.StopsBullet(ParentUnit))
                        {
                            Collide(s);
                            if (Destroyed)
                            {
                                return;
                            }
                        }
                    }
                    else if (g.GetType().IsSubclassOf(typeof(UnitShip)))
                    {
                        float d = Vector2.Distance(getPosition(), g.getPosition());
                        if (d < BulletDodgeDistance.X && d - Speed.Length() / 4 > Vector2.Distance(Position.get() + Speed, g.getPosition()))
                        {
                            UnitShip u = (UnitShip)g;
                            if (u.BulletDodgeDistance > 0 && !u.IsAlly(ParentUnit))
                            {
                                u.SetBulletToDodge(this);
                            }
                        }
                    }
                }
            }
        }
 private void UpdateMapPosition()
 {
     OverMap.TargetMax = Logic.Max(Position.get() + new Vector2(500), OverMap.TargetMax);
     OverMap.TargetMin = Logic.Min(Position.get() - new Vector2(500), OverMap.TargetMin);
 }
Ejemplo n.º 9
0
 public static Vector2 Clamp(Vector2 MapPosition, Vector2 Min, Vector2 Max)
 {
     return(Logic.Max(Logic.Min(MapPosition, Max), Min));
 }