Beispiel #1
0
        public MapLayer(int width, int height)
        {
            layer = new Tile[height, width];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    layer[y, x] = new Tile(0, 0);
                }
            }
        }
Beispiel #2
0
        private void CreateWorld()
        {
            var tilesets = new List<Tileset>() { new Tileset(_mapTexture, 64, 32, 32, 32) };

            var collisionLayer = new bool[Config.MapSize.X, Config.MapSize.Y];
            var mapPlayersPosition = new int[Config.MapSize.X, Config.MapSize.Y];
            var map = new IEntity[Config.MapSize.X, Config.MapSize.Y];
            var layer = new MapLayer(Config.MapSize.X, Config.MapSize.Y);
            var voidPosition = new List<Point>();

            // Item Map
            IEntity entity;

            // List of player position
            var playerPositions = new Dictionary<int, Point>();

            // We don't put wall around the players
            for (int i = 0; i < Config.PlayersNumber; i++)
            {
                Point playerPosition = Config.PlayersPositions[i];
                playerPositions[i + 1] = playerPosition;

                mapPlayersPosition[playerPosition.X, playerPosition.Y] = 2;
                mapPlayersPosition[playerPosition.X + 1, playerPosition.Y] = 1;
                mapPlayersPosition[playerPosition.X, playerPosition.Y + 1] = 1;
                mapPlayersPosition[playerPosition.X, playerPosition.Y - 1] = 1;
                mapPlayersPosition[playerPosition.X - 1, playerPosition.Y] = 1;

                mapPlayersPosition[playerPosition.X - 1, playerPosition.Y - 1] = 1;
                mapPlayersPosition[playerPosition.X - 1, playerPosition.Y + 1] = 1;
                mapPlayersPosition[playerPosition.X + 1, playerPosition.Y - 1] = 1;
                mapPlayersPosition[playerPosition.X + 1, playerPosition.Y + 1] = 1;
            }

            /*
            entity = new Teleporter(FinalBomber.Instance, new Vector2(
                        5 * Engine.TileWidth,
                        1 * Engine.TileHeight));
            teleporterList.Add((Teleporter)entity);
            map[5,1] = entity;

            entity = new Teleporter(FinalBomber.Instance, new Vector2(
                        10 * Engine.TileWidth,
                        1 * Engine.TileHeight));
            teleporterList.Add((Teleporter)entity);
            map[10, 1] = entity;
            */

            for (int x = 0; x < Config.MapSize.X; x++)
            {
                for (int y = 0; y < Config.MapSize.Y; y++)
                {
                    if (!(x == 0 || y == 0 || x == (Config.MapSize.X - 1) || y == (Config.MapSize.Y - 1) ||
                        (x % 2 == 0 && y % 2 == 0)) && (mapPlayersPosition[x, y] != 1 && mapPlayersPosition[x, y] != 2))
                        voidPosition.Add(new Point(x, y));
                }
            }

            #region Teleporter
            if (Config.ActiveTeleporters)
            {
                if (Config.TeleporterPositionType == TeleporterPositionTypeEnum.Randomly)
                {
                    int randomVoid = 0;
                    for (int i = 0; i < MathHelper.Clamp(Config.TeleporterNumber, 0, voidPosition.Count - 1); i++)
                    {
                        randomVoid = Random.Next(voidPosition.Count);
                        entity = new Teleporter(new Point(
                            voidPosition[randomVoid].X,
                            voidPosition[randomVoid].Y));
                        TeleporterList.Add((Teleporter)entity);
                        map[voidPosition[randomVoid].X, voidPosition[randomVoid].Y] = entity;
                        voidPosition.Remove(voidPosition[randomVoid]);
                    }
                }
                else if (Config.TeleporterPositionType == TeleporterPositionTypeEnum.PlusForm)
                {
                    var teleporterPositions = new Point[]
                    {
                        new Point((int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)2), 1),
                        new Point(1, (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)2)),
                        new Point((int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)2), Config.MapSize.Y - 2),
                        new Point(Config.MapSize.X - 2, (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)2))
                    };

                    for (int i = 0; i < teleporterPositions.Length; i++)
                    {
                        entity = new Teleporter(new Point(
                            teleporterPositions[i].X,
                            teleporterPositions[i].Y));
                        TeleporterList.Add((Teleporter)entity);
                        map[teleporterPositions[i].X, teleporterPositions[i].Y] = entity;
                    }
                }
            }
            #endregion

            #region Arrow
            if (Config.ActiveArrows)
            {
                if (Config.ArrowPositionType == ArrowPositionTypeEnum.Randomly)
                {
                    var lookDirectionArray = new LookDirection[] { LookDirection.Up, LookDirection.Down, LookDirection.Left, LookDirection.Right };
                    for (int i = 0; i < MathHelper.Clamp(Config.ArrowNumber, 0, voidPosition.Count - 1); i++)
                    {
                        int randomVoid = Random.Next(voidPosition.Count);
                        entity = new Arrow(new Point(
                            voidPosition[randomVoid].X,
                            voidPosition[randomVoid].Y),
                            lookDirectionArray[Random.Next(lookDirectionArray.Length)]);
                        ArrowList.Add((Arrow)entity);
                        map[voidPosition[randomVoid].X, voidPosition[randomVoid].Y] = entity;
                        voidPosition.Remove(voidPosition[randomVoid]);
                    }
                }
                else if (Config.ArrowPositionType == ArrowPositionTypeEnum.SquareForm)
                {
                    int outsideArrowsLag = 0;
                    var ratio = (int)Math.Ceiling((double)(4 * (Config.MapSize.X - 2)) / (double)5);
                    if (ratio % 2 == 0)
                        outsideArrowsLag = 1;

                    var arrowPositions = new Point[]
                    {
                        // ~~ Inside ~~ //
                        // Top left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)4) + 1,
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)4) + 1),

                        // Top right
                        new Point(
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.X - 2))/(double)4) - 1,
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)4) + 1),

                        // Bottom left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)4) + 1,
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.Y - 2))/(double)4) - 1),

                        // Bottom right
                        new Point(
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.X - 2))/(double)4) - 1,
                            (int)Math.Ceiling((double)(3 * (Config.MapSize.Y - 2))/(double)4) - 1),

                        // ~~ Outside ~~ //
                        // Top left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)5),
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)5)),

                        // Top right
                        new Point(
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.X - 2))/(double)5) + outsideArrowsLag,
                            (int)Math.Ceiling((double)(Config.MapSize.Y - 2)/(double)5)),

                        // Bottom left
                        new Point(
                            (int)Math.Ceiling((double)(Config.MapSize.X - 2)/(double)5),
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.Y - 2))/(double)5) + outsideArrowsLag),

                        // Bottom right
                        new Point(
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.X - 2))/(double)5 + outsideArrowsLag),
                            (int)Math.Ceiling((double)(4 * (Config.MapSize.Y - 2))/(double)5) + outsideArrowsLag)
                    };

                    for (int i = 0; i < arrowPositions.Length; i++)
                    {
                        entity = new Arrow(new Point(
                            arrowPositions[i].X,
                            arrowPositions[i].Y),
                            Config.ArrowLookDirection[i % 4]);
                        ArrowList.Add((Arrow)entity);
                        map[arrowPositions[i].X, arrowPositions[i].Y] = entity;
                    }
                }
            }
            #endregion

            int counter = 0;
            for (int x = 0; x < Config.MapSize.X; x++)
            {
                for (int y = 0; y < Config.MapSize.Y; y++)
                {
                    var tile = new Tile(0, 0);
                    if (x == 0 || y == 0 || x == (Config.MapSize.X - 1) || y == (Config.MapSize.Y - 1) ||
                        (x % 2 == 0 && y % 2 == 0))
                    {
                        // Inside wallList
                        if ((x % 2 == 0 && y % 2 == 0 && !(x == 0 || y == 0 || x == (Config.MapSize.X - 1) || y == (Config.MapSize.Y - 1))) && mapPlayersPosition[x, y] != 2)
                        {
                            entity = new UnbreakableWall(new Point(x, y));
                            this.UnbreakableWallList.Add((UnbreakableWall)entity);
                            map[x, y] = entity;
                            collisionLayer[x, y] = true;
                        }
                        // Outside wallList
                        else if (mapPlayersPosition[x, y] != 2)
                        {
                            entity = new EdgeWall(new Point(x, y));
                            this._edgeWallList.Add((EdgeWall)entity);
                            counter++;
                            map[x, y] = entity;
                            collisionLayer[x, y] = true;
                        }
                    }
                    else
                    {
                        // Wall
                        if ((mapPlayersPosition[x, y] != 1 && mapPlayersPosition[x, y] != 2) && map[x, y] == null &&
                            Random.Next(0, 100) < GameConfiguration.WallPercentage)
                        {
                            collisionLayer[x, y] = true;
                            entity = new Wall(new Point(x, y));
                            _wallList.Add((Wall)entity);
                            map[x, y] = entity;
                        }
                        //tile = new Tile(0, 0);
                    }
                    layer.SetTile(x, y, tile);
                }
            }

            var mapLayers = new List<MapLayer> { layer };

            var tileMap = new TileMap(tilesets, mapLayers);
            Map level = null;//new Map(Config.MapSize, tileMap, map, collisionLayer);

            World = new World(FinalBomber.Instance, FinalBomber.Instance.ScreenRectangle);
            World.Levels.Add(level);
            World.CurrentLevel = 0;

            foreach (int playerID in playerPositions.Keys)
            {
                if (Config.AIPlayers[playerID - 1])
                {
                    var player = new AIPlayer(Math.Abs(playerID));
                    PlayerList.Add(player);
                    map[playerPositions[playerID].X, playerPositions[playerID].Y] = player;
                }
                else
                {
                    var player = new HumanPlayer(Math.Abs(playerID), playerID);
                    PlayerList.Add(player);
                    map[playerPositions[playerID].X, playerPositions[playerID].Y] = player;
                }
            }
        }
Beispiel #3
0
 public void SetTile(int x, int y, int tileIndex, int tileset)
 {
     layer[y, x] = new Tile(tileIndex, tileset);
 }
Beispiel #4
0
 public void SetTile(int x, int y, Tile tile)
 {
     layer[y, x] = tile;
 }
Beispiel #5
0
 public MapLayer(Tile[,] map)
 {
     this.layer = (Tile[,])map.Clone();
 }