Esempio n. 1
0
        /// <summary>
        /// Takes a Room and creates everything that is not a floor tile
        /// </summary>
        /// <param name="enemyTexture">Texture of enemies in this room</param>
        /// <param name="wallTexture">Texture of walls in this room</param>
        public void initRoom(Texture2D wallTextures, Texture2D floorTextures, Graph.Graph graph)
        {
            //Init room's textures
            this.wallTextures  = wallTextures;
            this.floorTextures = floorTextures;

            //Should change this later
            int tileSize          = 64;
            int roomSize          = 10;
            int enemySpriteWidth  = 39;
            int enemySpriteHeight = 38;
            Pod pod = new Pod();

            for (int i = 0; i < roomSize; i++)
            {
                for (int j = 0; j < roomSize; j++)
                {
                    Vector2 currPos =
                        new Vector2(
                            position.X + tileSize * i,
                            position.Y + tileSize * j);
                    Vector2 midPos =
                        new Vector2(
                            currPos.X + (tileSize / 4),
                            currPos.Y + (tileSize / 4));
                    switch (tileLayout[i, j])
                    {
                    //Create walls
                    case TileType.WALL:
                        ChunkManager.Instance.Add(
                            new Wall(
                                floorTextures,
                                currPos,
                                new Rectangle(
                                    (int)currPos.X,
                                    (int)currPos.Y,
                                    tileSize,
                                    tileSize)));
                        break;

                    //Move player
                    case TileType.PLAYER:
                        Player.Instance.Position = currPos;
                        Player.Instance.ResetPlayerNewMap();
                        Player.Instance.CurrWeapon.ResetWeapon();

                        Weapons.Weapon temp = Player.Instance.CurrWeapon;
                        temp.X = currPos.X + Player.Instance.BoundingBox.Width / 2;
                        temp.Y = currPos.Y + Player.Instance.BoundingBox.Height / 2;
                        Camera.Instance.resetPosition(Player.Instance.Position);

                        //Add this position to the graph
                        graph.Add(new Graph.GraphNode(midPos));
                        spawnroom = true;
                        break;

                    //Create Melee Enemies
                    case TileType.MELEEENEMY:

                        graph.Add(new Graph.GraphNode(midPos));

                        //Create new enemy
                        MeleeEnemy newEnemy =
                            new MeleeEnemy(
                                TextureManager.Instance.GetEnemyTexture("EnemyTexture"),
                                midPos,
                                new Rectangle(
                                    (int)midPos.X,
                                    (int)midPos.Y,
                                    enemySpriteWidth,
                                    enemySpriteHeight));

                        //Add Enemy to game
                        EntityManager.Instance.Add(newEnemy);
                        ChunkManager.Instance.Add(newEnemy);
                        pod.Add(newEnemy);
                        break;

                    //Create Turret Enemies
                    case TileType.TURRET:
                        //Create new enemy
                        TurretEnemy turret =
                            new TurretEnemy(
                                TextureManager.Instance.GetEnemyTexture("EnemyTexture"),
                                midPos,
                                new Rectangle(
                                    (int)midPos.X,
                                    (int)midPos.Y,
                                    enemySpriteWidth,
                                    enemySpriteHeight));

                        //Add Enemy to game
                        EntityManager.Instance.Add(turret);
                        ChunkManager.Instance.Add(turret);
                        pod.Add(turret);
                        break;

                    case TileType.DASHENEMY:
                        graph.Add(new Graph.GraphNode(midPos));

                        //Create new enemy
                        DashEnemy dash =
                            new DashEnemy(
                                TextureManager.Instance.GetEnemyTexture("EnemyTexture"),
                                midPos,
                                new Rectangle(
                                    (int)midPos.X,
                                    (int)midPos.Y,
                                    enemySpriteWidth,
                                    enemySpriteHeight));

                        //Add Enemy to game
                        EntityManager.Instance.Add(dash);
                        ChunkManager.Instance.Add(dash);
                        pod.Add(dash);
                        break;

                    default:
                        //Add this position to the graph
                        graph.Add(new Graph.GraphNode(midPos));
                        break;
                    }
                }
            }
            PodManager.Instance.Add(pod);

            InitTextureMap();
        }