コード例 #1
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;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
 public bool CheckCircle(BasicShipGameObject g, Vector2 StartPosition, Vector2 EndPosition, float LineWidth)
 {
     return(Logic.DistanceLineSegmentToPoint(StartPosition, EndPosition, g.getPosition()) < (g.getSize().X + AttackLineWidth) / 2);
 }
コード例 #3
0
        public virtual Vector2 GetPlacePosition(int FactionNumber)
        {
            float   BestScore    = -500000;
            Vector2 BestPosition = Vector2.Zero;

            float Distance = 1000;
            float JumpSize = 100;

            Vector2 MinPos = new Vector2(10000);
            Vector2 MaxPos = new Vector2(-10000);

            foreach (MiningPlatform m in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform)))
            {
                if (m.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m.Dead)
                {
                    MinPos = Vector2.Min(MinPos, m.Position.get() - new Vector2(Distance));
                    MaxPos = Vector2.Max(MaxPos, m.Position.get() + new Vector2(Distance));
                }
            }

            Basic2DScene b = (Basic2DScene)GameManager.GetLevel().getCurrentScene();

            MinPos = Vector2.Max(MinPos, b.MinBoundary.get());
            MaxPos = Vector2.Min(MaxPos, b.MaxBoundary.get());

            for (float x = MinPos.X; x < MaxPos.X; x += JumpSize)
            {
                for (float y = MinPos.Y; y < MaxPos.Y; y += JumpSize)
                {
                    if (TestFree(new Vector2(x, y), TurretSize, FactionNumber) &&
                        PathFindingManager.GetCellValue(new Vector2(x, y)) != PathFindingManager.DeadCell)
                    {
                        float score = 5000;

                        if (GetTurretFragility() != 0)
                        {
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 0, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 0, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, 1, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, -1, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }

                            if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, -1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, -1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                        }

                        foreach (NeutralSpawn spawn in NeutralManager.SpawnList)
                        {
                            if (PathFindingManager.GetCellValue(spawn.Position.get()) > PathFindingManager.StartingCell - 50 &&
                                PathFindingManager.GetCellValue(spawn.Position.get()) < PathFindingManager.StartingCell - 20 &&
                                PathFindingManager.GetAreaClear(spawn.Position.get()))
                            {
                                if (GetTurretFragility() != 0 && PathFindingManager.CollisionLine(new Vector2(x, y), spawn.Position.get()))
                                {
                                    score += 500 * GetTurretFragility();
                                }

                                if (score > BestScore)
                                {
                                    MiningPlatform NearestMiningPlatform = null;
                                    float          NearestDistance       = 10000;

                                    foreach (MiningPlatform m2 in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform)))
                                    {
                                        if (m2.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m2.Dead)
                                        {
                                            float d = Vector2.Distance(m2.Position.get(), spawn.Position.get());
                                            if (d < NearestDistance)
                                            {
                                                NearestDistance       = d;
                                                NearestMiningPlatform = m2;
                                            }
                                        }
                                    }

                                    score -= Logic.DistanceLineSegmentToPoint(spawn.Position.get(),
                                                                              NearestMiningPlatform.Position.get(), new Vector2(x, y)) * GetTurretAgression();
                                }
                            }
                        }

                        if (score > BestScore)
                        {
                            Basic2DScene Parent2DScene = (Basic2DScene)GameManager.GetLevel().getCurrentScene();
                            QuadGrid     quad          = Parent2DScene.quadGrids.First.Value;

                            foreach (Basic2DObject o in quad.Enumerate(new Vector2(x, y), new Vector2(200)))
                            {
                                if (o.GetType().IsSubclassOf(typeof(UnitBuilding)))
                                {
                                    UnitBuilding s = (UnitBuilding)o;
                                    if (s.GetTeam() == FactionManager.GetTeam(FactionNumber))
                                    {
                                        float d = Vector2.Distance(o.Position.get(), new Vector2(x, y));
                                        if (d < 2000)
                                        {
                                            score -= (2000 - d) * GetBuildingAvoidence();
                                            if (s.GetType().IsSubclassOf(typeof(MiningPlatform)))
                                            {
                                                score -= (2000 - d) * GetBaseAvoidence();
                                            }
                                            else if (s.GetType().IsSubclassOf(typeof(UnitTurret)))
                                            {
                                                UnitTurret t = (UnitTurret)s;
                                                if (t.MyCard != null)
                                                {
                                                    if (t.MyCard.StrongVs.Equals(StrongVs))
                                                    {
                                                        score -= (2000 - d) * GetTurretAvoidence();
                                                    }
                                                }
                                                else
                                                {
                                                    if (StrongVs.Equals("Heavy"))
                                                    {
                                                        score -= (2000 - d) * GetTurretAvoidence();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (score > BestScore)
                            {
                                BestScore    = score;
                                BestPosition = new Vector2(x, y);
                            }
                        }
                    }
                }
            }

            return(BestPosition);
        }
コード例 #4
0
 public bool CheckCircle(Basic2DObject g)
 {
     return(Logic.DistanceLineSegmentToPoint(getPosition(), PreviousPosition, g.getPosition()) < (g.Size.get().X + Size.get().X) / 2);
 }
コード例 #5
0
        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);
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        public override void Update2(GameTime gameTime)
        {
            base.Update2(gameTime);
            Position.set(Vector2.Clamp(Position.get(), Parent2DScene.MinBoundary.get(), Parent2DScene.MaxBoundary.get()));

            if (CrystalWall.SortedWalls.ContainsKey(WaveManager.ActiveTeam))
            {
                foreach (CrystalWall n in CrystalWall.SortedWalls[WaveManager.ActiveTeam])
                {
                    if (!n.Dead)
                    {
                        foreach (CrystalWallConnection n2 in n.ConnectedWalls)
                        {
                            if (!n2.wall.Dead)
                            {
                                float MoveAmount = (Size.X() + n.getSize().X * 0.75f) / 2 - Logic.DistanceLineSegmentToPoint(n.Position.get(), n2.wall.Position.get(), Position.get());

                                if (MoveAmount > 0)
                                {
                                    Vector2 MoveVector;

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

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

                                    Position.set(Position.get() + MoveVector * MoveAmount);


                                    float d1 = Vector2.Distance(Position.get(), n.Position.get());
                                    float d2 = 0;
                                    if (!PathFindingManager.CollisionLine(Position.get(), n.Position.get()))
                                    {
                                        Vector2.Distance(Position.get(), n2.wall.Position.get());
                                    }

                                    CurrentAttackTarget = d1 > d2 ? n : n2.wall;
                                    AngerTime           = MaxAngerTime;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #7
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);
        }