Inheritance: FBLibrary.Core.BaseEntities.BaseWall
Exemplo n.º 1
0
        protected override void RemoveWall(Wall wall)
        {
            if (GameConfiguration.Random.Next(0, 100) < MathHelper.Clamp(GameConfiguration.PowerUpPercentage, 0, 100))
            {
                AddPowerUp(wall.CellPosition);
            }

            base.RemoveWall(wall);
        }
Exemplo n.º 2
0
        protected virtual void RemoveWall(Wall wall)
        {
            WallList.Remove(wall);

            base.RemoveWall(wall);
        }
Exemplo n.º 3
0
        public override void AddWall(Point position)
        {
            var wall = new Wall(position);
            WallList.Add(wall);

            base.AddWall(wall);
        }
Exemplo n.º 4
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;
                }
            }
        }
Exemplo n.º 5
0
        private void ParseMap(string file)
        {
            try
            {
                var streamReader = new StreamReader("Content/Maps/" + file);
                string line = streamReader.ReadLine();
                string[] lineSplit = line.Split(' ');
                var parsedMapSize = new int[] { int.Parse(lineSplit[0]), int.Parse(lineSplit[1]) };

                var mapSize = new Point(parsedMapSize[0], parsedMapSize[1]);
                var tilesets = new List<Tileset>() { new Tileset(_mapTexture, 64, 32, 32, 32) };

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

                int j = 0;
                while (!streamReader.EndOfStream)
                {
                    line = streamReader.ReadLine();
                    Debug.Assert(line != null, "line != null");
                    lineSplit = line.Split(' ');
                    for (int i = 0; i < lineSplit.Length; i++)
                    {
                        int id = int.Parse(lineSplit[i]);
                        switch (id)
                        {
                            case 1:
                                var unbreakableWall = new UnbreakableWall(new Point(i, j));
                                map[i, j] = unbreakableWall;
                                UnbreakableWallList.Add(unbreakableWall);
                                collisionLayer[i, j] = true;
                                break;
                            case 2:
                                var edgeWall = new EdgeWall(new Point(i, j));
                                map[i, j] = edgeWall;
                                _edgeWallList.Add(edgeWall);
                                collisionLayer[i, j] = true;
                                break;
                            case 3:
                                var wall = new Wall(new Point(i, j));
                                _wallList.Add(wall);
                                map[i, j] = wall;
                                collisionLayer[i, j] = true;
                                break;
                            case 6:
                                var teleporter = new Teleporter(new Point(i, j));
                                map[i, j] = teleporter;
                                TeleporterList.Add(teleporter);
                                break;
                            case 7:
                                var arrow = new Arrow(new Point(i, j), LookDirection.Down);
                                ArrowList.Add(arrow);
                                map[i, j] = arrow;
                                break;
                            default:
                                if (id < 0 && Math.Abs(id) <= Config.PlayersNumber)
                                {
                                    playerPositions[Math.Abs(id)] = new Point(i, j);
                                }
                                break;
                        }
                    }
                    j++;
                }

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

                var tileMap = new TileMap(tilesets, mapLayers);
                Map level = null;//new Map(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])
                    {
                        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;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }