예제 #1
0
        void GenerateTerrainAsync(object si)
        {
            TerrainGeneration.GenerateTerrain(gameMap, lightingEngine, ScreenManager.GraphicsDevice);
            gameHero.Position = gameMap.HeroSpawn;
            gameCamera.Position = gameHero.Position;
            gameCamera.Target = gameCamera.Position;

            List<Compound> possibleComps = new List<Compound>();
            List<Building> possibleHelipads = new List<Building>();

            // Spawn vehicles
            foreach (Compound c in gameMap.Compounds)
            {
                foreach (Building b in c.Buildings)
                {
                    if (b.Type == BuildingType.Carpark)
                    {
                        Jeep j = new Jeep((new Vector2(b.Rect.Center.X, b.Rect.Center.Y) * new Vector2(gameMap.TileWidth, gameMap.TileHeight)) + new Vector2(50, 50));
                        j.Rotation = (float)Helper.Random.NextDouble() * MathHelper.TwoPi;
                        j.LoadContent(vehicleController.SpriteSheet, ScreenManager.GraphicsDevice, lightingEngine);
                        vehicleController.Vehicles.Add(j);
                        //gameHero.Position = j.Position + new Vector2(300, 0);
                    }

                    if (b.Type == BuildingType.Helipad)
                    {
                        possibleHelipads.Add(b);
                    }
                }
            }

            for (int i = 0; i < 5; i++)
            {
                Building b = possibleHelipads[Helper.Random.Next(possibleHelipads.Count)];

                Chopper chop = new Chopper((new Vector2(b.Rect.Center.X, b.Rect.Center.Y) * new Vector2(gameMap.TileWidth, gameMap.TileHeight)) + new Vector2(50, 50));
                chop.Rotation = (float)Helper.Random.NextDouble() * MathHelper.TwoPi;
                chop.LoadContent(vehicleController.SpriteSheet, ScreenManager.GraphicsDevice, lightingEngine);
                vehicleController.Vehicles.Add(chop);
                //gameHero.Position = chop.Position + new Vector2(300, 0);
                possibleHelipads.Remove(b);
                if (possibleHelipads.Count == 0) break;
            }

            // Spawn enemies
            foreach (Compound c in gameMap.Compounds)
            {
                if (c.Buildings.Count > 0)
                {
                    int bnum = c.Buildings.Count;
                    foreach (Building b in c.Buildings) if (b.Type != BuildingType.Building) bnum--;
                    if(bnum>0) possibleComps.Add(c);
                }

                for (int y = c.Bounds.Top; y < c.Bounds.Bottom; y++)
                {
                    for (int x = c.Bounds.Left; x < c.Bounds.Right; x++)
                    {
                        if (((TileLayer)gameMap.GetLayer("Wall")).Tiles[x, y] != null) continue;
                        Vector2 pos = new Vector2((x * gameMap.TileWidth) + 50, (y * gameMap.TileHeight) + 50);
                        bool found = false;

                        if (vehicleController.CheckVehicleCollision(pos)) found = true;
                        foreach (AIDude d in enemyController.Enemies)
                        {
                            if ((d.Position - pos).Length() < 700) found = true;
                        }

                        if (!found)
                        {
                            AIDude newDude = new AIDude(pos);
                            newDude.BelongsToCompound = true;
                            newDude.LoadContent(enemyController.SpriteSheet, ScreenManager.GraphicsDevice, lightingEngine, gameHero);
                            newDude.Health = 10 + Helper.Random.Next(30);
                            enemyController.Enemies.Add(newDude);
                        }

                    }
                }
            }

            // Spawn Generals
            for (int i = 0; i < 3; i++)
            {

                while (true)
                {
                    Compound c = possibleComps[Helper.Random.Next(possibleComps.Count)];
                    bool found = false;
                    foreach (AIDude d in enemyController.Enemies.Where(en => en.IsGeneral)) if ((d.Position - c.Position).Length() <= 20000) found = true;
                    if (!found)
                    {
                        Building b;
                        while (true)
                        {
                            b = c.Buildings[Helper.Random.Next(c.Buildings.Count)];
                            if (b.Type == BuildingType.Building) break;
                        }
                        Vector2 pos = (new Vector2(b.Rect.Center.X, b.Rect.Center.Y) * new Vector2(gameMap.TileWidth, gameMap.TileHeight)) + new Vector2(50, 50);
                        AIDude newDude = new AIDude(pos);
                        newDude.IsGeneral = true;
                        newDude.BelongsToCompound = true;
                        newDude.LoadContent(enemyController.SpriteSheet, ScreenManager.GraphicsDevice, lightingEngine, gameHero);
                        newDude.Health = 100f;
                        enemyController.Enemies.Add(newDude);
                        possibleComps.Remove(c);

                        for (int h = 0; h < 5; h++)
                        {
                            pos = (new Vector2(b.Rect.Center.X, b.Rect.Center.Y) * new Vector2(gameMap.TileWidth, gameMap.TileHeight)) + new Vector2(50, 50) + new Vector2(-200f + ((float)Helper.Random.NextDouble() * 400f), -200f + ((float)Helper.Random.NextDouble() * 400f));
                            newDude = new AIDude(pos);
                            newDude.BelongsToCompound = true;
                            newDude.LoadContent(enemyController.SpriteSheet, ScreenManager.GraphicsDevice, lightingEngine, gameHero);
                            newDude.Health = 50 + Helper.Random.Next(30);
                            enemyController.Enemies.Add(newDude);
                        }

                        break;
                    }
                }
            }

            foreach (Jetty jetty in gameMap.Jetties)
            {
                Boat b = new Boat(jetty.BoatPosition);
                b.Rotation = jetty.BoatRotation;
                b.LoadContent(vehicleController.SpriteSheet, ScreenManager.GraphicsDevice, lightingEngine);
                vehicleController.Vehicles.Add(b);
            }

            gameHud.Ticker.AddLine("> Explore area and eliminate resistance");

            TerrainGeneration.Generating = false;
        }
예제 #2
0
        internal void SpawnNearestVehicles(Vector2 pos, Map gameMap)
        {
            bool jeepSpawned = false;
            foreach (Compound c in gameMap.Compounds.OrderBy(comp => (comp.Position - pos).Length()))
            {
                foreach (Building b in c.Buildings.Where(bu => bu.Type == BuildingType.Carpark))
                {
                    Vector2 spawnPos = (new Vector2(b.Rect.Center.X, b.Rect.Center.Y) * new Vector2(gameMap.TileWidth, gameMap.TileHeight)) + new Vector2(50, 50);

                    bool jeepFound = false;
                    foreach (Vehicle v in Vehicles) if ((v.Position - spawnPos).Length() < 300) jeepFound = true;

                    if (!jeepFound)
                    {
                        Jeep j = new Jeep((new Vector2(b.Rect.Center.X, b.Rect.Center.Y) * new Vector2(gameMap.TileWidth, gameMap.TileHeight)) + new Vector2(50, 50));
                        j.Rotation = (float)Helper.Random.NextDouble() * MathHelper.TwoPi;
                        j.LoadContent(SpriteSheet, graphicsDevice, lightingEngine);
                        Vehicles.Add(j);
                        jeepSpawned = true;
                        break;
                    }
                }
                if (jeepSpawned) break;
            }

            foreach (Jetty j in gameMap.Jetties.OrderBy(comp => (comp.Position - pos).Length()))
            {

                bool boatFound = false;
                foreach (Vehicle v in Vehicles) if ((v.Position - j.BoatPosition).Length() < 300) boatFound = true;

                if (!boatFound)
                {
                    Boat b = new Boat(j.BoatPosition);
                    b.Rotation = j.BoatRotation;
                    b.LoadContent(SpriteSheet, graphicsDevice, lightingEngine);
                    Vehicles.Add(b);
                    jeepSpawned = true;
                    break;
                }

            }
        }