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();
        }
Example #2
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();
        }
Example #3
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);
                    }
                }
            }
        }
Example #4
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);
                            }
                        }
                    }
                }
            }
        }
        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);
                            }
                        }
                    }
                }
            }
        }