MazeBlock NewBlock(int cellNum, bool top, bool left, bool bottom, bool right, int positionX, int positionY) { MazeBlock MB = gameObject.AddComponent(typeof(MazeBlock)) as MazeBlock; MB.CreateBlock(top, left, bottom, right, positionX, positionY, cellNum); return(MB); }
public static List <MazeBlock> ShortestPath(MazeBlock Start, MazeBlock End) { List <MazeBlock> path = new List <MazeBlock>(); List <MazeBlock> frontier = new List <MazeBlock>(); List <MazeBlock> explored = new List <MazeBlock>(); return(path); }
private void OnTriggerStay2D(Collider2D collision) { if (collision.tag == "MazeDecorationTilemap") { Tilemap map = collision.GetComponentInParent <Tilemap>(); Vector3Int removePos = new Vector3Int((int)Math.Ceiling(transform.position.x) - (int)Math.Ceiling(map.transform.position.x), (int)Math.Ceiling(transform.position.y) + (int)Math.Ceiling(map.transform.position.y), 0); MazeBlock block = MazeBuilder.GetSingleTon().GetBlockAt(removePos); if (block != null && block is MB_DoorSwitch) { Debug.Log("Activate"); ((MB_DoorSwitch)block).Activate(); } } }
void BuildMaze(int MazeSizeX, int MazeSizeY) { AddMazeEdges(); MazeBlock[] cells = new MazeBlock[MazeSizeX * MazeSizeY]; for (int i = 1; i < (MazeSizeX * MazeSizeY); i++) { bool t; if (Random.Range(0.0f, 10.0f) > 9.33f) { t = true; } else { t = false; } bool r; if (Random.Range(0.0f, 10.0f) > 9.33f) { r = true; } else { r = false; } bool b; if (Random.Range(0.0f, 10.0f) > 9.33f) { b = true; } else { b = false; } bool l; if (Random.Range(0.0f, 10.0f) > 9.33f) { l = true; } else { l = false; } cells[i] = NewBlock(i, t, r, b, l, (i % MazeSizeY) * 10, (i / MazeSizeX) * 10); cells[i].name = "Cell" + i; } }
// Start is called before the first frame update void Start() { GameState.AddListener("MazeBuilder_" + SOURCE.GetMapName(), this); if (tilemap == null) { tilemap = transform.Find("Tilemap").GetComponent <Tilemap>(); } if (colliderTilemap == null) { colliderTilemap = transform.Find("Collider").GetComponent <Tilemap>(); } if (decorTilemap == null) { decorTilemap = transform.Find("Decoration").GetComponent <Tilemap>(); } map = new MazeBlock[SampleMap.W, SampleMap.H]; int rowIndex = 0; foreach (var row in SOURCE.GetMap()) { int colIndex = 0; foreach (var col in row) { MazeBlock block = BuildTileByChar(col, new Vector3Int(rowIndex, colIndex, 0)); map[rowIndex, colIndex] = block; colIndex++; } rowIndex++; } transform.Find("Collider").gameObject.AddComponent <TilemapCollider2D>(); transform.Find("Decoration").gameObject.AddComponent <TilemapCollider2D>(); transform.Find("Decoration").gameObject.GetComponent <TilemapCollider2D>().isTrigger = true; Invalidate(); }
private void Invalidate() { printMap(); tilemap.ClearAllTiles(); colliderTilemap.ClearAllTiles(); decorTilemap.ClearAllTiles(); for (int row = 0; row < SampleMap.H; row++) { for (int col = 0; col < SampleMap.W; col++) { map[col, row].Invalidate(); } } for (int row = 0; row < SampleMap.H; row++) { for (int col = 0; col < SampleMap.W; col++) { MazeBlock block = map[row, col]; if (block != null) { Vector3Int pos = new Vector3Int(col - pivot.x, SampleMap.H - row - pivot.y, 0); if (block.HasCollision()) { colliderTilemap.SetTile(pos, block.GetTileBase(map, SampleMap.W, SampleMap.H)); } else if (block.HasTrigger() && block.IsDecoration()) { tilemap.SetTile(pos, BuildTileByType(MazeBlockType.UNDER_ITEM, pos).GetTileBase()); decorTilemap.SetTile(pos, block.GetTileBase(map, SampleMap.W, SampleMap.H)); } else { tilemap.SetTile(pos, block.GetTileBase()); } } } } }
private MazeBlock BuildTileByType(MazeBlockType type, Vector3Int pos) { MazeBlock origin = Array.Find(sourceTiles, el => el.type == type); if (origin != null) { switch (origin.type) { case MazeBlockType.OUTSIDE: return(new MB_Outside(origin, pos)); case MazeBlockType.DOOR_YELLOW: return(new MB_Door(origin, pos, GetYellowDoorKey())); case MazeBlockType.DOOR_RED: return(new MB_Door(origin, pos, GetRedDoorKey())); case MazeBlockType.DOOR_GREEN: return(new MB_Door(origin, pos, GetGreenDoorKey())); case MazeBlockType.DOOR_BUTTON_GREEN: return(new MB_DoorSwitch(origin, pos, GetGreenDoorKey())); case MazeBlockType.DOOR_BUTTON_RED: return(new MB_DoorSwitch(origin, pos, GetRedDoorKey())); case MazeBlockType.DOOR_BUTTON_YELLOW: return(new MB_DoorSwitch(origin, pos, GetYellowDoorKey())); case MazeBlockType.UNDER_ITEM: return(new MB_UnderItem(origin, pos)); default: return(new MazeBlock(origin, pos)); } } return(null); }
public MazeBlock(MazeBlock origin, Vector3Int _pos) { this.tileBases = origin.tileBases; this.type = origin.type; this.position = _pos; }
public MB_Door(MazeBlock origin, Vector3Int _pos, string key) : base(origin, _pos) { _key = key; }
public MB_DoorSwitch(MazeBlock origin, Vector3Int _pos, string _key) : base(origin, _pos) { key = _key; Debug.Log("Create with " + key); }
public MB_UnderItem(MazeBlock origin, Vector3Int _pos) : base(origin, _pos) { }
private bool Same(MazeBlock b) { return(b == null || b.type == type); }
public MB_Outside(MazeBlock origin, Vector3Int _pos) : base(origin, _pos) { }
private bool SameNeighbours8(MazeBlock tl, MazeBlock t, MazeBlock tr, MazeBlock l, MazeBlock r, MazeBlock bl, MazeBlock b, MazeBlock br) { return(SameNeighbours4(t, l, b, r) && SameNeighbours4(tl, tr, bl, br)); }
private bool SameNeighbours4(MazeBlock top, MazeBlock left, MazeBlock bottom, MazeBlock right) { return(Same(top) && Same(left) && Same(bottom) && Same(right)); }
private bool SameNeighboursExceptFirst4(MazeBlock notEqual, MazeBlock n, MazeBlock n1, MazeBlock n2) { return(!Same(notEqual) && Same(n) && Same(n1) && Same(n2)); }