public GravityMap(int map_width, int map_height) { w = map_width; h = map_height; nodes = new MapBlock[map_height, map_width]; RandomSeed(); }
/// <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); }
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; }
/// <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); }
/// <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); }
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); }
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; }
public Map(int mapSize = 20) { _mapSize = mapSize; _map = new MapBlock[mapSize, mapSize]; initMapArray(); BuildWalls(); PlaceButtCrack(); }
//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 (); }
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); }
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); } } }
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(); }
/// <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); } } }
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!"); } } } }
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>(); }
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>(); }
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(); } } }
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(); }
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(); } }
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!"); } } }
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; } } }
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!"); } } }
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(); } } }
/// <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>(); }
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); }
public virtual void Dispose() { mMapBlocks = null; mMapCells = null; }
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(); }
public void SetBlockData(MapBlock[,] blocks) { mMapBlocks = blocks; }
public virtual void Dispose() { mMapBlocks = null; mMapCells = null; }
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 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(); }