//Flip the block based on vertical axis. public void Flip() { //for block with current width 1, flip does nothing if (width >= 2) { //If width is odd, then midCol is the middle; //otherwhise it is the middle-right column. int midCol = width / 2; TileData[,] newTileData = new TileData[height, width]; for (int c = 0; c < width; c++) { for (int r = 0; r < height; r++) { if (width % 2 == 1 && c == midCol) { newTileData[r, midCol] = new TileData(tiles[r, midCol]); } else { newTileData[r, c] = new TileData(tiles[r, width - 1 - c]); } } } tiles = newTileData; } else { //Do nothing for now return; } }
// Set up connections between adjacent nodes private void setUpConnections(TileData[,] tileMap) { for (int i = 0; i < worldSize; i++) { for (int j = 0; j < worldSize; j++) { TileData tile = tileMap[i, j]; tile.connections = new List <TileData>(); // Check tile above if (IsInBounds(i, j + 1) && (tileMap[i, j + 1].type == TileType.None || tileMap[i, j + 1].type == TileType.Ground)) { tile.connections.Add(tileMap[i, j + 1]); } // Check tile below if (IsInBounds(i, j - 1) && (tileMap[i, j - 1].type == TileType.None || tileMap[i, j - 1].type == TileType.Ground)) { tile.connections.Add(tileMap[i, j - 1]); } // Check tile left if (IsInBounds(i - 1, j) && (tileMap[i - 1, j].type == TileType.None || tileMap[i - 1, j].type == TileType.Ground)) { tile.connections.Add(tileMap[i - 1, j]); } // Check tile right if (IsInBounds(i + 1, j) && (tileMap[i + 1, j].type == TileType.None || tileMap[i + 1, j].type == TileType.Ground)) { tile.connections.Add(tileMap[i + 1, j]); } } } }
public void DrawTiles(TileData[,] tileData) { foreach (TileData td in tileData) { Tiles[td.X, td.Y] = td.DrawTile(this); } }
// Use this for initialization void Start() { if (mines < length * height && mines > 0) { field = new TileData[length, height]; for (int i = 0; i < length; i++) { for (int j = 0; j < height; j++) { field[i, j] = Instantiate(tile, canvas.transform).GetComponent <TileData>(); field[i, j].gameObject.transform.position = new Vector2(canvas.transform.position.x - length * 25 + i * 50, canvas.transform.position.y + height * 24 - j * 50); } } for (int i = 0; i < mines; i++) { int x = Random.Range(0, length - 1); int y = Random.Range(0, height - 1); if (!field[x, y].GetMine()) { field[x, y].ChangeMine(true); //conditions.AddMines(field[x, y]); } else { i--; } } } }
public void Setup() { _tileMapData = new TileMapData(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE); TileData[,] tileData = _tileMapData.GetTileData(); for (int x = 0; x < MAP_SQUARE_SIZE; x++) { for (int z = 0; z < MAP_SQUARE_SIZE; z++) { tileData [x, z] = GetGrassTileData(); } } // Add un-walkable tiles in middle of tilemap tileData [4, 4] = GetWaterTileData(); tileData [5, 4] = GetWaterTileData(); tileData [6, 4] = GetWaterTileData(); Graph graph = new Graph(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE); graph.Generate4WayGraph(); _nodeGrapth = graph.GetGraph(); _validStraightPathfinder = new Pathfinder(_tileMapData, _nodeGrapth); _validStraightPathfinder.GeneratePath(0, 0, 5, 0); _invalidPathfinder = new Pathfinder(_tileMapData, _nodeGrapth); _invalidPathfinder.GeneratePath(0, 0, 0, 0); _validIgnoreUnWalkablePathfinder = new Pathfinder(_tileMapData, _nodeGrapth); _validIgnoreUnWalkablePathfinder.GeneratePath(new Vector3(3, 0, 4), new Vector3(7, 0, 4)); }
public void TestGetTileDataArray() { TileData[,] tileDataArray = _tileMapData.GetTileData(); Assert.AreEqual(MAP_SQUARE_SIZE, tileDataArray.GetLength(0)); Assert.AreEqual(MAP_SQUARE_SIZE, tileDataArray.GetLength(1)); }
//Generates a randomized 2D int Array, containing numbers 1-5. private static int[,] generateWeight(int seed, TileData[,] tiles) { int length = tiles.GetLength(0); int height = tiles.GetLength(1); System.Random random = new System.Random(seed); int[,] weights = new int[length, height]; for (int i = 0; i < length; i++) { for (int j = 0; j < height; j++) { if (tiles[i, j] == null) { weights[i, j] = random.Next(2, 8); } else if (tiles[i, j].isBorder) { //Don't go through borders, if possible. weights[i, j] = 5; } else { //If this is part of a Room, then set its weight to one, to prefer already existing paths. weights[i, j] = 1; } } } return(weights); }
public void Load() { isLoad = false; if (File.Exists(Application.dataPath + "/Planet.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.dataPath + "/Planet.dat", FileMode.Open); PlanetData planetData = (PlanetData)bf.Deserialize(file); file.Close(); width = planetData.width; height = planetData.height; data = new TileData[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { data[i, j] = new TileData(); data[i, j].type = planetData.type[i, j]; data[i, j].amount = planetData.amount[i, j]; data[i, j].endurance = planetData.endurance[i, j]; } } } isLoad = true; }
void SetTileType(TileData[,] tileArrData, float mapWidth, float mapHeight) { // because we added elevation ? float elevation; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { elevation = tileArrData[i, j].Elevation; if (elevation < _tolerance) { tileArrData[i, j].TerrainType = TileData.TERRAIN_TYPE.SEA; } else if (elevation < _tolerance + (2) * _shoreSize) { tileArrData[i, j].TerrainType = TileData.TERRAIN_TYPE.SHORE; } else { tileArrData[i, j].TerrainType = TileData.TERRAIN_TYPE.LAND; } } } }
public TileMap(Game game, int Seed = -1) { RND = new Random(); //position = new Vector2(-576); ///position = new Vector2(-128); position = new Vector2(); //tilesize = 48; tilesize = 16; //rows = 16; /*columns = 52;*/ rows = (int)Math.Ceiling(((-position.Y * 2) + game.stageBounds.bottom) / tilesize); columns = (int)Math.Ceiling(((-position.X * 2) + game.stageBounds.right) / tilesize); data = new TileData[columns, rows]; tiles = AnimationLoader.Get("images/land/brick"); cracks = AnimationLoader.Get("images/land/cracks"); this.game = game; buffer = new HTMLCanvasElement(); bg = buffer.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D); if (Seed < 0) { this.Seed = RND.Next(); } else { this.Seed = Seed; } //Randomize(); Generate(); }
public SerializedTilemap(string tilemapName, TileData[,] tiles, int width, int height, List <LiquidBody> liquidBodies) { this.TilemapName = tilemapName; // figure out a way to parse all the tilemap information here List <SerializedTileData> serializedTileDataList = new List <SerializedTileData>(); // read first tile for reference TileData tileData = tiles[0, 0]; GameTile gameTile = tileData.currentTile; bool placeable = tileData.isTilePlaceable; int repetitions = 1; // loop through tilemap to parse information for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { // ignore first tile because already read if (!(i == 0 && j == 0)) { tileData = tiles[i, j]; // if tile does not match current if (gameTile != tileData.currentTile || placeable != tileData.isTilePlaceable) { // create and add a new serialized tile data SerializedTileData serializedTileData = new SerializedTileData(gameTile, LiquidbodyController.Instance.GetBodyID(tileData.tilePosition), placeable, repetitions); serializedTileDataList.Add(serializedTileData); // update other values for future matching gameTile = tileData.currentTile; placeable = tileData.isTilePlaceable; repetitions = 1; } else { ++repetitions; } } } } // add in the last set of tile data SerializedTileData lastSerializedTileData = new SerializedTileData(gameTile, LiquidbodyController.Instance.GetBodyID(tileData.tilePosition), placeable, repetitions); serializedTileDataList.Add(lastSerializedTileData); // turn list into array SerializedTileDatas = serializedTileDataList.ToArray(); int index = 0; this.SerializedLiquidBodies = new SerializedLiquidBody[liquidBodies.Count]; foreach (LiquidBody liquidBody in liquidBodies) { this.SerializedLiquidBodies[index] = liquidBody.Serialize(); index++; } }
public MapData(Offset mapOffset, int maxWidth, int maxHeight, TileData[,] tileArrData) { _mapOffset = mapOffset; _maxWidth = maxWidth; _maxHeight = maxHeight; _tileArrData = tileArrData; }
public WorldLoader(TileData[,] tileMap, bool[,] walkMap, int width, int height) { this.tileMap = tileMap; this.walkMap = walkMap; this.width = width; this.height = height; }
public LevelData(int tileDepthInVertices, int tileWidthInVertices, int levelDepthInTiles, int levelWidthInTiles) { tilesData = new TileData[tileDepthInVertices * levelDepthInTiles, tileWidthInVertices *levelWidthInTiles]; this.tileDepthInVertices = tileDepthInVertices; this.tileWidthInVertices = tileWidthInVertices; }
void Start() { width = 32; height = 32; player = GameObject.Find("Player"); this.pathLimit = 45; map = new TileData[width, height]; this.walkMap = new bool[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { map[i, j] = new TileData(); walkMap[i, j] = true; } } Debug.Log("Creating wolrd?"); this.worldLoader = GetComponent <WorldLoader>(); worldLoader.intializeWorldData(map, walkMap, width, height); worldLoader.loadWorld(); this.heightMap = GameObject.Find("Terrain").GetComponent <TerrainGenerator>().getHeightMap(); Debug.Log(this.heightMap[1, 1]); Debug.Log(this.heightMap.Length); }
public static TileData[,] Rotate(this TileData[,] matrix, int rotation) { rotation = rotation % 360; int width = matrix.GetLength(0); int height = matrix.GetLength(1); switch (rotation) { case 0: break; case 90: matrix = Apply(matrix, height, false, width, true, (mat, y, x) => mat[x, y]); break; case 180: matrix = Apply(matrix, width, true, height, true, (mat, x, y) => mat[x, y]); break; case 270: matrix = Apply(matrix, height, true, width, false, (mat, y, x) => mat[x, y]); break; default: Debug.LogError("The rotation should be at a right angle"); break; } return(matrix); }
public LevelData(int tileDepthInVertices, int tileWidthInVertices, int mapDepthInTiles, int mapWidthInTiles) { // build the tilesData matrix based on the level depth and width tilesData = new TileData[tileDepthInVertices * mapDepthInTiles, tileWidthInVertices *mapWidthInTiles]; this.tileDepthInVertices = tileDepthInVertices; this.tileWidthInVertices = tileWidthInVertices; }
public PlannerSettings(short Width, short Height) { TileMap = new TileData[Width, Height]; MainBackground = BackgroundData.MainBackgroundType.Forest; hasMainBackground = true; this.WorldWidth = Width; this.WorldHeight = Height; }
public BoardData(int w, int h) { width = w; height = h; Tiles = new TileData[w, h]; Player1Hand = new TileData[3]; Player2Hand = new TileData[3]; }
public TileMap(int width, int height, TileSet set) { this.mapTiles = new TileData[width, height]; this.tileSet = set; this.w = width; this.h = height; clearMap(); }
public LevelData() { tileData = new TileData[1, 1]; levelName = null; levelNumber = 0; gridSizeX = 1; gridSizeY = 1; }
void Start() { tiles = new TileData[mapSizeX, mapSizeY]; spawnedTiles = new GameObject[mapSizeX, mapSizeY]; InitGrid(); InitVisualGrid(); InitPathFindingGraph(); }
public TileMapData(int width, int height, float tileSize, int tileResolution, string tileSet, TileData[,] tileData) { Width = width; Height = height; TileSize = tileSize; TileResolution = tileResolution; TileSet = tileSet; TileData = tileData; }
// ----------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------- public LevelData(int tileDepthInVertices, int levelDepthInTiles, float scale) { // build the tilesData matrix based on the level depth and width tilesData = new TileData[tileDepthInVertices * levelDepthInTiles, tileDepthInVertices *levelDepthInTiles]; this.tileDepthInVertices = tileDepthInVertices; this.scale = scale; }
public static void InitMapSize(int xSize, int ySize) { mapSizeX = xSize; mapSizeY = ySize; mapData = new TileData[mapSizeX, mapSizeY]; buildingData = new StructureData[mapSizeX, mapSizeY]; resourceData = new ResourceData[mapSizeX, mapSizeY]; }
public void intializeWorldData(TileData[,] tileMap, bool[,] walkMap, int width, int height) { this.tileMap = tileMap; this.walkMap = walkMap; this.width = width; this.height = height; this.heightMap = GameObject.Find("Terrain").GetComponent <TerrainGenerator>().getHeightMap(); Debug.Log(this.treePrefab.ToString()); }
void CalculatePerlinNoise() { _tiles = new TileData[width, height]; // Calculate "raw" perlin noise for all the tiles float zMin = 1f; float zMax = 0f; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { _tiles[x, y] = new TileData(x, y); //Vector3Int pos = new Vector3Int(centerMap ? x - width / 2 : x, centerMap ? y - height / 2 : y, 0); //Vector3 worldPos = grid.CellToWorld(pos); Vector3 worldPos = grid.CellToWorld(MapToCell(x, y)); _tiles[x, y].worldX = worldPos.x; _tiles[x, y].worldY = worldPos.y; float z = Mathf.PerlinNoise((x + seed) / width / scale, (y + seed) / height / scale); _tiles[x, y].z = z; if (z < zMin) { zMin = z; } else if (z > zMax) { zMax = z; } } } // Normalize perlin noise _zLayers = _tilemaps.Length > 1 ? _tilemaps.Length : 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float z = (_tiles[x, y].z - zMin) / (zMax - zMin); _tiles[x, y].z = z; if (_zLayers > 0) { float amount = 0f; int zLayer = 0; float weight = zLayer < weights.Length ? weights[zLayer] : 1f; while (amount + weight < z * _totalWeight) { amount += weight; zLayer++; weight = zLayer < weights.Length ? weights[zLayer] : 1f; } _tiles[x, y].zLayer = zLayer < ruleTiles.Length ? zLayer : ruleTiles.Length - 1; } } } }
public void AddModifiedTiles(TileData[,] tile) { for (int x = 0; x < tile.GetLength(0); x++) { for (int y = 0; y < tile.GetLength(1); y++) { myModifiedTiles.Add(new Tuple <float, float, float>(tile[x, y].GetPosition().X, tile[x, y].GetPosition().Y, tile[x, y].GetPosition().Z), tile[x, y]); } } }
public void CreateData() { TMData = new TileMapData(); TDHolder = TMData.BuildTileMapData(height, width); //TMData.ShowTileDataHolderData(); //TMData.ChangeTextureAt(2, 5, TileData.TEXTURE_DATA.WATER); Debug.Log("DONE Map Data"); }
public LevelData(TileData[,] td, string name, int num, int x, int y, int pX, int pY) { tileData = td; levelName = name; levelNumber = num; gridSizeX = x; gridSizeY = y; pStartX = pX; pStartY = pY; }
public LayerData(Int32 sizex, Int32 sizey) { this.Name = String.Empty; this.BelowPlayer = true; this.Tiles = new TileData[sizex, sizey]; for (var x = 0; x < sizex; x++) { for (var y = 0; y < sizey; y++) { this.Tiles[x, y] = new TileData(); } } }
public Tileset(string id, SpriteSheet sheet, int width, int height) { this.id = id; this.sheet = sheet; this.size = new Point2I(width, height); this.defaultTile = Point2I.Zero; this.tileData = new TileData[width, height]; // Create default tiledata. for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { tileData[x, y] = new TileData(); tileData[x, y].Tileset = this; tileData[x, y].SheetLocation = new Point2I(x, y); tileData[x, y].Sprite = new Sprite(sheet, x, y); } } }
public Zone(Area area) { Random r = new Random(); this.Grass = new TileData(); this.Water = new TileData(); Grass.Sprite = new Graphics.Sprite("grass"); Water.Sprite = new Graphics.Sprite("water"); this.area = area; this.World = area.World; tileMap = new TileData[(int)area.ZoneSize.X, (int)area.ZoneSize.Y]; for (int y = 0; y < tileMap.GetLength(0); ++y) { for (int x = 0; x < tileMap.GetLength(1); ++x) { tileMap[y, x] = (x == 0) ? this.Grass : this.Water; } } }
private void SetupTiles() { tiles = new List<SpriteRenderer>(cols * rows); tileData = new TileData[cols, rows]; var pos = new Vector3(tileArea.xMin, tileArea.yMin); pos.x += TileWidth * 0.5f; pos.y += TileHeight * 0.5f; for(int x=0; x < cols; ++x) { for(int y=0; y < rows; ++y) { var gObj = Instantiate(tilePrefab, pos, Quaternion.identity) as GameObject; gObj.name = tilePrefab.name + x + y; gObj.transform.parent = transform; tiles.Add(gObj.GetComponent<SpriteRenderer>()); tileData[x, y] = new TileData(1, (y > groundLevel? 0 : 1)); pos.y += TileHeight; } pos.x += TileWidth; pos.y = tileArea.yMin + TileHeight * 0.5f; } UpdateTiles(); }
/// <summary> /// Initialization procedures when first making the agent. /// </summary> private static void InitializeAgent() { // If first learning trial, zero the Qtables if (Game.Instance.GameCounter == 0) { boardSize = Game.Instance.BoardX; map = new TileData[boardSize, boardSize]; ResetAllQTables(); } }
void CopyTileIntoTileData() { this.TileDataMap = new TileData[width,height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { this.TileDataMap[i,j] = tileMap[i,j].TileData; } } this.TileDataList = tileList.ConvertAll(t => t.TileData); }
public TileCollection(int X, int Y) { ProgramLog.Log("{3} {0}x{1}, {2}MB", X, Y, Marshal.SizeOf(typeof(TileData)) * X * Y / 1024 / 1024, Language.Languages.CreatingTileArrayOf); data = new TileData [X, Y]; }
public TileCollection(int X, int Y) { ProgramLog.Log ("Creating tile array of {0}x{1}, {2}MB", X, Y, Marshal.SizeOf (typeof(TileData)) * X * Y / 1024 / 1024); data = new TileData [X, Y]; }
private void InitializeMapData() { this.MapTileData = new TileData[this.ScenarioMap.MapDimensions.X, this.ScenarioMap.MapDimensions.Y]; this.PenalizedMapData = new int[this.ScenarioMap.MapDimensions.X, this.ScenarioMap.MapDimensions.Y]; }
public TileCollection(int X, int Y) { Console.WriteLine ("Creating tile array of {0}x{1}", X, Y); data = new TileData [X, Y]; }
internal void SetSize(int x, int y) { this.Datas = new TileData[x, y]; }
private void Init() { tileMap = new TileData[ mapWidth , mapHeight ]; InitTileMap(); }