Ejemplo n.º 1
0
 public GravityMap(int map_width, int map_height)
 {
     w     = map_width;
     h     = map_height;
     nodes = new MapBlock[map_height, map_width];
     RandomSeed();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns vertical boundaries for rendering map blocks around center block.
        /// [minY,maxY].
        /// </summary>
        /// <param name="map">Map.</param>
        /// <param name="centerBlock">Center block.</param>
        /// <param name="verticalBlockCount">NUmber of blocks to be rendered in vertical direction.</param>
        /// <returns>Array with two items. First is the Y coordinate of the top block to be rendered, second is the Y coordinate of the bottom block to be rendered.</returns>
        private int[] GetYBoundaries(MapBlock[,] map, MapBlock centerBlock, int verticalBlockCount)
        {
            int[] boundaries = new int[2];

            // number of blocks on each side from center block
            int numOfTopBlocks    = verticalBlockCount / 2;
            int numOfBottomBlocks = (int)Math.Ceiling(verticalBlockCount / 2.0) - 1;

            // too close to the top border
            if (centerBlock.Y - numOfTopBlocks < 0)
            {
                boundaries[0] = 0;
                boundaries[1] = verticalBlockCount - 1;


                // too close to the bottom border
            }
            else if (centerBlock.Y + numOfBottomBlocks >= map.GetLength(1))
            {
                boundaries[0] = map.GetLength(1) - verticalBlockCount;
                boundaries[1] = map.GetLength(1) - 1;


                // ok, somewhere in the middle
            }
            else
            {
                boundaries[0] = centerBlock.Y - numOfTopBlocks;
                boundaries[1] = centerBlock.Y + numOfBottomBlocks;
            }

            return(boundaries);
        }
Ejemplo n.º 3
0
        public void updatePlayer(MapBlock[,] map)
        {
            Position newPosition = new Position(position.x + velocity.x, position.y + velocity.y);

            if (map[newPosition.x, newPosition.y].isFloor && !map[newPosition.x, newPosition.y].isOccupied)
            {
                map[position.x, position.y].isOccupied = false;
                if (isRedPlayer)
                {
                    map[position.x, position.y].isOccRed = false;
                }
                else
                {
                    map[position.x, position.y].isOccBlue = false;
                }
                position.x = newPosition.x;
                position.y = newPosition.y;
                map[position.x, position.y].isOccupied = true;
                if (isRedPlayer)
                {
                    map[position.x, position.y].isOccRed = true;
                }
                else
                {
                    map[position.x, position.y].isOccBlue = true;
                }
            }

            velocity.x = 0;
            velocity.y = 0;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns horizontal boundaries for rendering map blocks around center block.
        /// [minX,maxX].
        /// </summary>
        /// <param name="map">Map.</param>
        /// <param name="centerBlock">Center blocks.</param>
        /// <param name="horizontalBlockCount">Number of blocks to be rendered in horizontal direction.</param>
        /// <returns>Array with two items. First is the X coordinate of the leftmost block to be rendered, second is the X coordinate of the rightmost block to be rendered.</returns>
        private int[] GetXBoundaries(MapBlock[,] map, MapBlock centerBlock, int horizontalBlockCount)
        {
            int[] boundaries = new int[2];

            // number of blocks on each side from center block
            int numOfLeftBlocks  = horizontalBlockCount / 2;
            int numOfRightBlocks = (int)Math.Ceiling(horizontalBlockCount / 2.0) - 1;

            // too close to the right border
            if (centerBlock.X + numOfRightBlocks >= map.GetLength(0))
            {
                boundaries[1] = map.GetLength(0) - 1;
                boundaries[0] = map.GetLength(0) - horizontalBlockCount;

                // too close to the left border
            }
            else if (centerBlock.X - numOfLeftBlocks < 0)
            {
                boundaries[0] = 0;
                boundaries[1] = horizontalBlockCount - 1;

                // ok, somewhere in the middle
            }
            else
            {
                boundaries[0] = centerBlock.X - numOfLeftBlocks;
                boundaries[1] = centerBlock.X + numOfRightBlocks;
            }

            return(boundaries);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Render map (with background) and returns it as a set of shapes.
        /// </summary>
        /// <param name="mapGrid">Map to be rendered.</param>
        /// <param name="centerBlock">Center block to render map around.</param>
        /// <param name="canvasW">Width of target canvas.</param>
        /// <param name="canvasH">Height of target canvas.</param>
        /// <returns>Map rendered as a list of shapes.</returns>
        public List <UIElement> RenderMap(Map map, MapBlock centerBlock, double canvasW, double canvasH)
        {
            List <UIElement> renderedMap = new List <UIElement>();

            // target area is too small to render anything
            if (canvasW < this.blockSize || canvasH < this.blockSize)
            {
                return(renderedMap);
            }

            MapBlock[,] mapGrid = map.Grid;
            int verticalBlockCount   = (int)Math.Min((double)map.Height, canvasH / blockSize);
            int horizontalBlockCount = (int)Math.Min((double)map.Width, canvasW / blockSize);

            renderedMap.Add(new Rectangle()
            {
                Height = verticalBlockCount * blockSize, Width = horizontalBlockCount * blockSize, Fill = new SolidColorBrush(Color.FromRgb(255, 204, 102))
            });

            int[] xBoundaries = GetXBoundaries(mapGrid, centerBlock, horizontalBlockCount);
            int[] yBoundaries = GetYBoundaries(mapGrid, centerBlock, verticalBlockCount);
            for (int i = xBoundaries[0]; i <= xBoundaries[1]; i++)
            {
                for (int j = yBoundaries[0]; j <= yBoundaries[1]; j++)
                {
                    List <Shape> renderedMapBlock = RenderMapBlock(mapGrid[i, j], (i - xBoundaries[0]) * blockSize, (j - yBoundaries[0]) * blockSize, blockSize, map.WinningBlock.X, map.WinningBlock.Y);
                    renderedMap.AddRange(renderedMapBlock);
                }
            }

            return(renderedMap);
        }
Ejemplo n.º 6
0
 public LandGeneratorController(ref MapBlock[,] map, LandGeneratorArguments args, int seed)
     : this(ref map, seed)
 {
     LandSourcePointsDensity           = args.LandSourcePointsDensity;
     DistanceFromSourceLandBlockImpact = args.DistanceFromSourceBlockImpact;
     LandGenerationPower = args.LandGenerationPower;
     MinMaxLandSize      = new Vector2i(args.MinSize, args.MaxSize);
 }
Ejemplo n.º 7
0
 public static void renderPlayer(MapBlock[,] map, int width, int height)
 {
     //Determine and assign the Pixel:GameTile ratio and assign it to
     //the static Player and Missile class variables xScale and yScale.
     Player.xScale  = width / Game.WIDTH_IN_TILES;
     Player.yScale  = height / Game.HEIGHT_IN_TILES;
     Missile.xScale = Player.xScale;
     Missile.yScale = Player.yScale;
 }
Ejemplo n.º 8
0
        public Map(int mapSize = 20)
        {
            _mapSize = mapSize;
            _map     = new MapBlock[mapSize, mapSize];

            initMapArray();
            BuildWalls();
            PlaceButtCrack();
        }
Ejemplo n.º 9
0
    //void Start()
    //{
    //    initMap(3, 3);
    //}

    // Init Map and Create all cubeMap
    public void initMap(int X, int Y)
    {
        size = new Vector2(Y, X);
        map = new MapBlock[Y, X];
        Build();
        status = true;
		GetComponent<InfinitMove> ().StartTerrain (size);
		GetComponent<InfinitMove> ().Init ();
    }
Ejemplo n.º 10
0
        private LandGeneratorController(ref MapBlock[,] map, int seed)
        {
            _map         = map;
            _landSources = new List <GeneratedLandBlock>();
            _visited     = new int[TileMapGeneratorController.TileMapWidth, TileMapGeneratorController.TileMapHeight];

            _seed = seed;
            _rand = new Random(seed);
        }
Ejemplo n.º 11
0
		public Map(string name, int width, int height) {
			mMapID = mInstances++;
			mName = name;
			Width = width;
			Height = height;
			mMapBlocks = new MapBlock[Width / Global.BLOCK_SIZE, Height / Global.BLOCK_SIZE];
			mMapCells = new ECollisionType[Width * Height];

			InitializeBlocks();
		}
 private static void MakeBlocks(ref MapBlock[,] map)
 {
     for (int i = 0; i < TileMapWidth; i++)
     {
         for (int j = 0; j < TileMapHeight; j++)
         {
             map[i, j] = new MapBlock(i, j, SquareBlockSize);
         }
     }
 }
Ejemplo n.º 13
0
        public Map(string name, int width, int height)
        {
            mMapID     = mInstances++;
            mName      = name;
            Width      = width;
            Height     = height;
            mMapBlocks = new MapBlock[Width / Global.BLOCK_SIZE, Height / Global.BLOCK_SIZE];
            mMapCells  = new ECollisionType[Width * Height];

            InitializeBlocks();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes this map with given values and assigns parentMap to each MapBlock.
        /// </summary>
        /// <param name="grid">Map, dimensions should match with width and height.</param>
        public void InitializeMap(MapBlock[,] grid)
        {
            Width  = grid.GetLength(0);
            Height = grid.GetLength(1);
            Grid   = grid;

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    grid[i, j].AssignToMap(this);
                }
            }
        }
Ejemplo n.º 15
0
        public void TestOpenMapGenerator()
        {
            IMapGenerator openMapGenerator = MapGeneratorFactory.CreateOpenMapGenerator();
            int           w = 10;
            int           h = 15;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid = openMapGenerator.GenerateGrid(w, h, 0);
            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }

            Map map = openMapGenerator.GenerateMap(w, h, 0);

            Assert.IsNotNull(map, "Null map returned!");
            Assert.AreEqual(w, map.Width, "Wrong map width!");
            Assert.AreEqual(h, map.Height, "Wrong map height!");
            MapBlock[,] grid2 = map.Grid;
            Assert.AreEqual(grid.GetLength(0), grid.GetLength(0), "Widths of grids don't match!");
            Assert.AreEqual(grid.GetLength(1), grid.GetLength(1), "Widths of grids don't match!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid2[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }
        }
Ejemplo n.º 16
0
 public Map(int _width, int _height)
 {
     width = _width;
     height = _height;
     lights = new List<Light>();
     mapBlocks = new MapBlock[_width, _height];
     lightMap = new Color[_width, _height];
     for (int i = 0; i < _width; i++)
     {
         for (int j = 0; j < _height; j++)
         {
             mapBlocks[i, j] = new MapBlock(this);
             mapBlocks[i, j].Coordinates = new Coord(i, j);
             lightMap[i, j] = Color.Gray;
         }
     }
     mapZombies = new List<Creature>();
 }
Ejemplo n.º 17
0
 public Map(int _width, int _height)
 {
     width     = _width;
     height    = _height;
     lights    = new List <Light>();
     mapBlocks = new MapBlock[_width, _height];
     lightMap  = new Color[_width, _height];
     for (int i = 0; i < _width; i++)
     {
         for (int j = 0; j < _height; j++)
         {
             mapBlocks[i, j]             = new MapBlock(this);
             mapBlocks[i, j].Coordinates = new Coord(i, j);
             lightMap[i, j] = Color.Gray;
         }
     }
     mapZombies = new List <Creature>();
 }
Ejemplo n.º 18
0
        public void Load(string zonPath, string zscBuildingPath, string zscDecorationPath, string mapFolder, int minSizeX, int minSizeY, int maxSizeX, int maxSizeY)
        {
            ZON zON  = ContentManager.Instance().GetZON(zonPath);
            ZSC zSC  = ContentManager.Instance().GetZSC(zscBuildingPath);
            ZSC zSC2 = ContentManager.Instance().GetZSC(zscDecorationPath);

            this.decorationBlocks = new DecorationBlock[maxSizeX - minSizeX + 1, maxSizeY - minSizeY + 1];
            this.mapBlocks        = new MapBlock[maxSizeX - minSizeX + 1, maxSizeY - minSizeY + 1];
            this.isView           = new bool[maxSizeX - minSizeX + 1, maxSizeY - minSizeY + 1];
            for (int i = minSizeX; i <= maxSizeX; i++)
            {
                for (int j = minSizeY; j <= maxSizeY; j++)
                {
                    string himName = string.Concat(new object[]
                    {
                        i,
                        "_",
                        j,
                        ".HIM"
                    });
                    string tilName = string.Concat(new object[]
                    {
                        i,
                        "_",
                        j,
                        ".TIL"
                    });
                    MapBlock mapBlock = new MapBlock(this.graphics);
                    mapBlock.Load(zON, mapFolder, himName, tilName, new Vector2((float)i, (float)j));
                    this.mapBlocks[i - minSizeX, j - minSizeY] = mapBlock;
                    string ifoName = string.Concat(new object[]
                    {
                        i,
                        "_",
                        j,
                        ".IFO"
                    });
                    DecorationBlock decorationBlock = new DecorationBlock(this.graphics);
                    decorationBlock.Load(ifoName, mapFolder, zSC2, zSC, new Vector2((float)i, (float)j));
                    this.decorationBlocks[i - minSizeX, j - minSizeY] = decorationBlock;
                }
            }
            this.GenerateIndice();
        }
        private static void UpdateReferences(ref MapBlock[,] map)
        {
            for (int i = 0; i < TileMapWidth; i++)
            {
                for (int j = 0; j < TileMapHeight; j++)
                {
                    map[i, j].BBlock  = ReturnBlockOrNull(i, j + 1, ref map);
                    map[i, j].BrBlock = ReturnBlockOrNull(i + 1, j + 1, ref map);
                    map[i, j].LBlock  = ReturnBlockOrNull(i - 1, j, ref map);
                    map[i, j].LbBlock = ReturnBlockOrNull(i - 1, j + 1, ref map);
                    map[i, j].LtBlock = ReturnBlockOrNull(i - 1, j - 1, ref map);
                    map[i, j].RBlock  = ReturnBlockOrNull(i + 1, j, ref map);
                    map[i, j].TBlock  = ReturnBlockOrNull(i, j - 1, ref map);
                    map[i, j].TrBlock = ReturnBlockOrNull(i + 1, j - 1, ref map);

                    map[i, j].UpdateNearBlocksList();
                }
            }
        }
Ejemplo n.º 20
0
        public Map()
        {
            _blockPool         = new ObjectPool <MapBlock>();
            _loaderPool        = new ObjectPool <MapLoader>();
            _blocks            = new MapBlock[MapSetting.maxTileX, MapSetting.maxTileY];
            _renderTiles       = new Dictionary <MapTile, MapLoaderItem>();
            _loadList          = new List <MapLoaderItem>(30);
            _loadDict          = new HashSet <MapTile>();
            _loadingDict       = new Dictionary <string, MapLoader>();
            _textureDict       = new Dictionary <MapTile, TextureAsset>();
            _globalMapTileList = new List <MapTile>(10);

            //if (MapSetting.assetBundleMode)
            //    _thumbnailLoader = new TextureAssetBundleLoader();
            //else
            //    _thumbnailLoader = new TextureLoader();
            _thumbnailLoader = new TextureLoader();

            _control = new MapControl();
        }
Ejemplo n.º 21
0
        public void ShowWindow(LandGeneratorArguments args, int seed)
        {
            _tileMap = TileMapGeneratorController.GenerateTileMap();

            var landGenerator = new LandGeneratorController(ref _tileMap, args, seed);

            landGenerator.GenerateLand();

            _mainWindow         = new RenderWindow(new VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Square Tiles terrain generator");
            _mainWindow.Closed += mainWindow_Closed;

            _drawingTileMapManager = new DrawingTileMapController(ref _tileMap);

            while (_mainWindow.IsOpen)
            {
                _mainWindow.DispatchEvents();

                _mainWindow.Clear(Color.Black);
                _mainWindow.Draw(_drawingTileMapManager);
                _mainWindow.Display();
            }
        }
Ejemplo n.º 22
0
        public void TestSimpleMapGeneratorSeed()
        {
            IMapGenerator simpleMapGenerator = MapGeneratorFactory.CreateSimpleMapGenerator();
            int           w    = 5;
            int           h    = 10;
            int           seed = 87452;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid  = simpleMapGenerator.GenerateGrid(w, h, seed);
            MapBlock[,] grid2 = simpleMapGenerator.GenerateGrid(w, h, seed);

            Assert.IsNotNull(grid, "Grid 1 is null!");
            Assert.IsNotNull(grid2, "Grid 2 is null!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            Assert.AreEqual(w, grid2.GetLength(0), "Wrong width of map grid 2!");
            Assert.AreEqual(h, grid2.GetLength(1), "Wrong height of map grid 2!");

            // all map block should be same
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int entrances = 0;
                    foreach (Direction dir in allDirections)
                    {
                        Assert.AreEqual(grid[i, j].EntranceInDirection(dir).Exists(), grid2[i, j].EntranceInDirection(dir).Exists(), $"Map block at position [{i},{j}] has different entrance in direction {dir}.");
                        if (grid[i, j].EntranceInDirection(dir).Exists())
                        {
                            entrances++;
                        }
                    }

                    Assert.IsTrue(entrances > 0, $"Block at [{i},{j}] has no entrance!");
                }
            }
        }
Ejemplo n.º 23
0
        public void updateMissile(MapBlock[,] map, ref WorldState worldState)
        {
            if (isActive)
            {
                Position newPosition = new Position(position.x + velocity.x, position.y + velocity.y);

                map[position.x, position.y].isOccupied   = false;
                map[position.x, position.y].isOccMissile = false;
                if (!map[newPosition.x, newPosition.y].isWall)
                {
                    position.x = newPosition.x;
                    position.y = newPosition.y;
                    if (map[position.x, position.y].isOccupied)
                    {
                        isActive  = false;
                        isContact = true;
                        if (map[position.x, position.y].isOccBlue)
                        {
                            worldState = WorldState.GameOverRedWin;
                        }
                        else if (map[position.x, position.y].isOccRed)
                        {
                            worldState = WorldState.GameOverBlueWin;
                        }
                    }
                }
                else
                {
                    isActive  = false;
                    isContact = true;
                }
                if (isActive)
                {
                    map[newPosition.x, newPosition.y].isOccupied   = true;
                    map[newPosition.x, newPosition.y].isOccMissile = true;
                }
            }
        }
Ejemplo n.º 24
0
        public void TestSimpleMapGenerator()
        {
            IMapGenerator simpleMapGenerator = MapGeneratorFactory.CreateSimpleMapGenerator();
            int           w = 5;
            int           h = 10;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            Map map = simpleMapGenerator.GenerateMap(w, h, IMapGeneratorConstants.NO_SEED);

            MapBlock[,] grid = map.Grid;

            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            // test that no map block has all entrances closed
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int entrances = 0;
                    foreach (Direction dir in allDirections)
                    {
                        if (grid[i, j].EntranceInDirection(dir).Exists())
                        {
                            entrances++;
                        }
                    }

                    Assert.IsTrue(entrances > 0, $"Block at [{i},{j}] has no entrance!");
                }
            }
        }
Ejemplo n.º 25
0
    private void GenerateRoomLayout()
    {
        m_Map = new MapBlock[m_Width, m_Height];
        m_PathRoomDescriptors = new List <BlockDescriptor>();

        // Spawn the rooms according to descriptors on the main path
        for (int i = 0; i < m_Path.Count; i++)
        {
            BlockDescriptor blockDescriptor = new BlockDescriptor();

            if (i > 0)
            {
                blockDescriptor.ConnectPathPositions(m_Path[i], m_Path[i - 1]);
            }

            if (i < m_Path.Count - 1)
            {
                blockDescriptor.ConnectPathPositions(m_Path[i], m_Path[i + 1]);
            }

            m_PathRoomDescriptors.Add(blockDescriptor);

            GameObject mapBlockPrefab = GetRandomMapBlockFromDescriptor(blockDescriptor);
            if (mapBlockPrefab == null)
            {
                continue;
            }

            MapBlock mapBlock = SpawnBlockAtPosition(mapBlockPrefab, m_Path[i].x, m_Path[i].y)
                                .GetComponentInChildren <MapBlock>();

            if (i == 0)
            {
                mapBlock.StartingBlock = true;
            }
            else if (i == m_Path.Count - 1)
            {
                mapBlock.GetComponentInChildren <MapBlock>().FinishBlock = true;
            }

            mapBlock.MainPathBlock = true;

            // Spawn direction signs and position to point at the next room
            mapBlock.SpawnDirectionSign();
            mapBlock.DirectionSign?.RotateTowards(m_Path[i + 1] - m_Path[i]);

            m_Map[m_Path[i].x, m_Path[i].y] = mapBlock;
        }

        // Fill in the non-crucial (outside of the main path) blocks
        for (int x = 0; x < m_Width; x++)
        {
            for (int y = 0; y < m_Height; y++)
            {
                if (m_Map[x, y] == null)
                {
                    m_Map[x, y] = SpawnBlockAtPosition(m_MapBlockPrefabs[Random.Range(0, m_MapBlockPrefabs.Count)], x,
                                                       y).GetComponentInChildren <MapBlock>();
                }

                m_Map[x, y].PopulateBlock();
            }
        }
    }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates a new global map of a particular size
 /// </summary>
 /// <param name="size"></param>
 public GlobalMap(int size)
 {
     this.worldSize = size;
     this.globalGameMap = new MapBlock[size,size];
     this.parties = new List<Actor>();
 }
Ejemplo n.º 27
0
 public void SetBlockData(MapBlock[,] blocks)
 {
     mMapBlocks = blocks;
 }
 private static MapBlock ReturnBlockOrNull(int i, int j, ref MapBlock[,] map)
 {
     return((i >= 0 && i < TileMapWidth && j >= 0 && j < TileMapHeight) ? map[i, j] : null);
 }
Ejemplo n.º 29
0
 public virtual void Dispose()
 {
     mMapBlocks = null;
     mMapCells  = null;
 }
Ejemplo n.º 30
0
    void Start()
    {
        // If m already exists, make sure its active
        if (m != null)
        {
            m.gameObject.SetActive(true);
            Destroy(this);
            return;
        }

        int[] fights_per_diff = new int[Map.max_difficulty + 1];
        for (int i = 0; i < Map.max_difficulty + 1; i++)
        {
            fights_per_diff[i] = 0;
        }
        foreach (Fight f in fights)
        {
            fights_per_diff[Mathf.Clamp(f.difficulty, 0, Map.max_difficulty)]++;
        }
        fight_ids = new int[Map.max_difficulty + 1][];
        for (int i = 0; i < Map.max_difficulty + 1; i++)
        {
            fight_ids[i] = new int[fights_per_diff[i]];
        }
        for (int i = 0; i < fights.Length; i++)
        {
            fight_ids[fights[i].difficulty][--fights_per_diff[fights[i].difficulty]] = i;
        }
        num_fights = new int[fights.Length];
        for (int i = 0; i < num_fights.Length; i++)
        {
            num_fights[i] = 0;
        }

        string output_info = "{\n";

        for (int i = 0; i < Map.max_difficulty + 1; i++)
        {
            output_info += "\t{ ";
            for (int j = 0; j < fight_ids[i].Length; j++)
            {
                output_info += fight_ids[i][j];
                if (j < fight_ids[i].Length - 1)
                {
                    output_info += ", ";
                }
            }
            output_info += " }\n";
        }
        output_info += "}";
        Debug.Log(output_info);

        // Otherwise, set this to m and generate the map
        DontDestroyOnLoad(this);
        m       = this;
        blocks  = new MapBlock[map_width, map_width];
        sectors = new Sector[num_sectors + 1 + tower_fabs.Length];
        for (int i = 0; i < sectors.Length; i++)
        {
            sectors[i] = NewSector();
        }

        // Create tower blocks
        // Determine player start location
        // Create tower and player start sectors
        _GenerateTowersAndStart();

        // Create all blocks
        _GenerateBlocks();

        // Add a single random block to each sector
        _SectorFirstBlocks();

        // As long as it can, add a block to each sector which is adjacent to another block in that sector
        _SectorExpansion();

        // For each block, check what sectors neighbor it. Any sectors that aren't it's
        // own sector get added to it's sector's adj list
        _GenerateNeighborhoods();

        // For each block generate the wall object for it
        ConvertSector(sectors[0]);

        // Create distances
        _GenerateDistances();

        // Generate sector difficulties
        _GenerateDifficulties();

        // Generate sector weapon spawn chances
        max_chance_top = 0f;
        foreach (Sector s in sectors)
        {
            s.dist_to_weapon = max_dist_to_start;
            float wsc = GetSpawnWeaponChanceTop(s);
            if (wsc > max_chance_top)
            {
                max_chance_top = wsc;
            }
        }
        foreach (Sector s in sectors)
        {
            Debug.Log(s.name + " has a " + Mathf.Round(GetSpawnWeaponChance(s) * 100) + "% chance of spawning a weapon.",
                      s);
        }

        // Set that no weapons have been spawned
        weapons_spawned = new bool[GarageController.weapons.Length];
        for (int i = 0; i < weapons_spawned.Length; i++)
        {
            weapons_spawned[i] = false;
        }

        // Generate sector fights for all sectors that don't have fights which are adjacent to a cyan sector.
        // Must pick a fight of the correct difficulty
        // Pick applicable fight with lowest number of unencountered things
        // More common fights on the map are rarer to spawn
        _GenerateNextTier();
    }
 public DrawingTileMapController(ref MapBlock[,] map)
 {
     _map = map;
     _tileMapVertexArray = new VertexArray(PrimitiveType.Quads, TileMapGeneratorController.TileMapHeight * TileMapGeneratorController.TileMapWidth * 4);
     PrepareTileMap();
 }
Ejemplo n.º 32
0
		public void SetBlockData(MapBlock[,] blocks) {
			mMapBlocks = blocks;
		}
Ejemplo n.º 33
0
		public virtual void Dispose() {
			mMapBlocks = null;
			mMapCells = null;
		}
Ejemplo n.º 34
0
	void Start()
	{
		// If m already exists, make sure its active
		if (m != null)
		{
			m.gameObject.SetActive(true);
			Destroy(this);
			return;
		}

		int[] fights_per_diff = new int[Map.max_difficulty + 1];
		for (int i = 0; i < Map.max_difficulty + 1; i++)
			fights_per_diff[i] = 0;
		foreach (Fight f in fights)
			fights_per_diff[Mathf.Clamp(f.difficulty, 0, Map.max_difficulty)]++;
		fight_ids = new int[Map.max_difficulty + 1][];
		for (int i = 0; i < Map.max_difficulty + 1; i++)
			fight_ids[i] = new int[fights_per_diff[i]];
		for (int i = 0; i < fights.Length; i++)
			fight_ids[fights[i].difficulty][--fights_per_diff[fights[i].difficulty]] = i;
		num_fights = new int[fights.Length];
		for (int i = 0; i < num_fights.Length; i++)
			num_fights[i] = 0;

		string output_info = "{\n";
		for (int i = 0; i < Map.max_difficulty + 1; i++)
		{
			output_info += "\t{ ";
			for (int j = 0; j < fight_ids[i].Length; j++)
			{
				output_info += fight_ids[i][j];
				if (j < fight_ids[i].Length - 1)
					output_info += ", ";
			}
			output_info += " }\n";
		}
		output_info += "}";
		Debug.Log(output_info);

		// Otherwise, set this to m and generate the map
		DontDestroyOnLoad(this);
		m = this;
		blocks = new MapBlock[map_width, map_width];
		sectors = new Sector[num_sectors + 1 + tower_fabs.Length];
		for (int i = 0; i < sectors.Length; i++)
			sectors[i] = NewSector();
		
		// Create tower blocks
		// Determine player start location
		// Create tower and player start sectors
		_GenerateTowersAndStart();
		
		// Create all blocks
		_GenerateBlocks();
		
		// Add a single random block to each sector
		_SectorFirstBlocks();
		
		// As long as it can, add a block to each sector which is adjacent to another block in that sector
		_SectorExpansion();
		
		// For each block, check what sectors neighbor it. Any sectors that aren't it's
			// own sector get added to it's sector's adj list
		_GenerateNeighborhoods();
		
		// For each block generate the wall object for it
		ConvertSector(sectors[0]);

		// Create distances
		_GenerateDistances();

		// Generate sector difficulties
		_GenerateDifficulties();

		// Generate sector weapon spawn chances
		max_chance_top = 0f;
		foreach (Sector s in sectors)
		{
			s.dist_to_weapon = max_dist_to_start;
			float wsc = GetSpawnWeaponChanceTop(s);
			if (wsc > max_chance_top)
				max_chance_top = wsc;
		}
		foreach (Sector s in sectors)
			Debug.Log(s.name + " has a " + Mathf.Round(GetSpawnWeaponChance(s) * 100) + "% chance of spawning a weapon.",
			          s);

		// Set that no weapons have been spawned
		weapons_spawned = new bool[GarageController.weapons.Length];
		for (int i = 0; i < weapons_spawned.Length; i++)
			weapons_spawned[i] = false;

		// Generate sector fights for all sectors that don't have fights which are adjacent to a cyan sector.
		// Must pick a fight of the correct difficulty
		// Pick applicable fight with lowest number of unencountered things
		// More common fights on the map are rarer to spawn
		_GenerateNextTier();
	}
Ejemplo n.º 35
0
 public void Load(string zonPath, string zscBuildingPath, string zscDecorationPath, string mapFolder, int minSizeX, int minSizeY, int maxSizeX, int maxSizeY)
 {
     ZON zON = ContentManager.Instance().GetZON(zonPath);
     ZSC zSC = ContentManager.Instance().GetZSC(zscBuildingPath);
     ZSC zSC2 = ContentManager.Instance().GetZSC(zscDecorationPath);
     this.decorationBlocks = new DecorationBlock[maxSizeX - minSizeX + 1, maxSizeY - minSizeY + 1];
     this.mapBlocks = new MapBlock[maxSizeX - minSizeX + 1, maxSizeY - minSizeY + 1];
     this.isView = new bool[maxSizeX - minSizeX + 1, maxSizeY - minSizeY + 1];
     for (int i = minSizeX; i <= maxSizeX; i++)
     {
         for (int j = minSizeY; j <= maxSizeY; j++)
         {
             string himName = string.Concat(new object[]
             {
                 i,
                 "_",
                 j,
                 ".HIM"
             });
             string tilName = string.Concat(new object[]
             {
                 i,
                 "_",
                 j,
                 ".TIL"
             });
             MapBlock mapBlock = new MapBlock(this.graphics);
             mapBlock.Load(zON, mapFolder, himName, tilName, new Vector2((float)i, (float)j));
             this.mapBlocks[i - minSizeX, j - minSizeY] = mapBlock;
             string ifoName = string.Concat(new object[]
             {
                 i,
                 "_",
                 j,
                 ".IFO"
             });
             DecorationBlock decorationBlock = new DecorationBlock(this.graphics);
             decorationBlock.Load(ifoName, mapFolder, zSC2, zSC, new Vector2((float)i, (float)j));
             this.decorationBlocks[i - minSizeX, j - minSizeY] = decorationBlock;
         }
     }
     this.GenerateIndice();
 }