Esempio n. 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;
        }
Esempio n. 2
0
        public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, bool[,] mapFog, Camera gameCamera)
        {
            int count = 0;
            foreach (AIDude e in Enemies.Where(en => (gameHero.Position - en.Position).Length() < 4000f))
            {
                count++;

                if ((gameHero.Position - e.Position).Length() < 2000f)
                {
                    e.Update(gameTime, gameMap, gameHero, mapFog, gameCamera);

                    bool alerted = false;
                    if (gameHero.HuntedLevel.Level > 0f)
                    {
                        if (!alerted && Helper.Random.Next(11000 - (int)(gameHero.HuntedLevel.Level * 100)) == 1 && e.State == AIState.Patrolling && (gameHero.Position - e.Position).Length() < 2000f)
                        {
                            //e.InvestigatePosition();
                            alerted = true;
                        }
                    }
                }
            }

            // Spawn some new enemies
            if (count < 10 + (int)(gameHero.HuntedLevel.Level / 10))
            {
                Vector2 pos = Helper.RandomPointInCircle(gameHero.Position, 2000f, 4000f);
                if (!gameMap.CheckTileCollision(pos) && pos.X > 0 && pos.X < (gameMap.Width * gameMap.TileWidth) && pos.Y > 0 && pos.Y < (gameMap.Height * gameMap.TileHeight) && !VehicleController.Instance.CheckVehicleCollision(pos))
                {
                    AIDude newDude = new AIDude(pos);
                    newDude.LoadContent(SpriteSheet, graphicsDevice, lightingEngine, gameHero);
                    newDude.Health = 10 + Helper.Random.Next(30);
                    Enemies.Add(newDude);
                }
            }

            Enemies.RemoveAll(e => !e.Active);
        }