Exemple #1
0
        private void GenerateEnemy(LevelEnemy enemy, ContentManager content, GameWindow Window)
        {
            int currentBehaviour = -1;
            switch (enemy.Type)
            {
                //Case Zombie enemy
                case 1:
                    ZombieEnemy z = new ZombieEnemy();
                    currentBehaviour = enemy.EntryBehaviours[0];
                    if (enemy.EntryBehaviours.Length == 2)
                    {
                        if (random.NextDouble() > 0.5)
                        {
                            currentBehaviour = enemy.EntryBehaviours[1];
                        }
                    }
                    if (currentBehaviour == 0)
                    {
                        float x = (float)random.NextDouble() *
                            (Window.ClientBounds.Width - z.boundingRectangle.Width);
                        z.position = new Vector2(x, 0);
                        z.isFalling = true;
                        enemies.Add(z);
                    }
                    else if (currentBehaviour == 1)
                    {
                        //TODO: make it depend on the level size
                        float y = (float)random.NextDouble() *
                            (Window.ClientBounds.Height - z.boundingRectangle.Height);
                        z.position = new Vector2(Window.ClientBounds.Width - y / 2, 350);
                        z.isFalling = false;
                        enemies.Add(z);
                    }
                    z.load(content);
                    break;

                //Case Bomber enemy
                case 2:
                    Bomberia b = new Bomberia();
                    currentBehaviour = enemy.EntryBehaviours[0];
                    if (enemy.EntryBehaviours.Length == 2)
                    {
                        if (random.NextDouble() > 0.5)
                        {
                            currentBehaviour = enemy.EntryBehaviours[1];
                        }
                    }
                    if (currentBehaviour == 0)
                    {
                        float x = (float)random.NextDouble() *
                            (Window.ClientBounds.Width - b.boundingRectangle.Width);
                        b.position = new Vector2(x, 0);
                        b.isFalling = true;
                        enemies.Add(b);
                    }
                    else if (currentBehaviour == 1)
                    {
                        //TODO: make it depend on the level size
                        float y = (float)random.NextDouble() *
                            (Window.ClientBounds.Height - b.boundingRectangle.Height);
                        b.position = new Vector2(Window.ClientBounds.Width - y / 2, 350);
                        b.isFalling = false;
                        enemies.Add(b);
                    }
                    b.load(content);
                    break;

                //TODO: Add the rest of enemies types

                default:
                    break;
            }
            maxEnemiesToSpawn--;
        }
Exemple #2
0
        public void Load(ContentManager content, GameWindow Window)
        {
            background = content.Load<Texture2D>("background-800 480");

            //Load the initial enemies
            foreach (var e in initialEnemies)
            {
                switch (e.Type)
                {
                    //Case Zombie enemy
                    case 1:
                        for (int i = 0; i < e.Number; i++)
                        {
                            ZombieEnemy z = new ZombieEnemy();
                            int currentBehaviour = e.EntryBehaviours[0];
                            if (e.EntryBehaviours.Length == 2)
                            {
                                if (random.NextDouble() > 0.5)
                                {
                                    currentBehaviour = e.EntryBehaviours[1];
                                }
                            }
                            if (currentBehaviour == 0)
                            {
                                float x = (float)random.NextDouble() *
                                    (Window.ClientBounds.Width - z.boundingRectangle.Width);
                                z.position = new Vector2(x, 0);
                                z.isFalling = true;
                                enemies.Add(z);
                            }
                            else if (currentBehaviour == 1)
                            {
                                //TODO: make it depend on the level size
                                float y = (float)random.NextDouble() *
                                    (Window.ClientBounds.Height - z.boundingRectangle.Height);
                                z.position = new Vector2(Window.ClientBounds.Width - y/2, 350);
                                z.isFalling = false;
                                enemies.Add(z);
                            }
                        }
                        break;

                    //Case Bomber enemy
                    case 2:
                        for (int i = 0; i < e.Number; i++)
                        {
                            Bomberia b = new Bomberia();
                            int currentBehaviour = e.EntryBehaviours[0];
                            if (e.EntryBehaviours.Length == 2)
                            {
                                if (random.NextDouble() > 0.5)
                                {
                                    currentBehaviour = e.EntryBehaviours[1];
                                }
                            }
                            if (currentBehaviour == 0)
                            {
                                float x = (float)random.NextDouble() *
                                    (Window.ClientBounds.Width - b.boundingRectangle.Width);
                                b.position = new Vector2(x, 0);
                                b.isFalling = true;
                                enemies.Add(b);
                            }
                            else if (currentBehaviour == 1)
                            {
                                //TODO: make it depend on the level size
                                float y = (float)random.NextDouble() *
                                    (Window.ClientBounds.Height - b.boundingRectangle.Height);
                                b.position = new Vector2(Window.ClientBounds.Width - y / 2, 350);
                                b.isFalling = false;
                                enemies.Add(b);
                            }
                        }
                        break;

                    //TODO: Add the rest of enemies types

                    default:
                        break;
                }

                //Decrease level's maximum enemies count
                maxEnemiesToSpawn -= e.Number;
            }

            //Load the hot spots
            for (int i = 0; i < mapHotSpots.Count; i++)
            {
                mapHotSpots[i].load(content);
            }
            //Load player and ground
            player.load(content);
            ground.load(content);

            //Load the enemies in the list of alive enemies
            foreach (var en in enemies)
            {
                en.load(content);
            }
        }