Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This code is far from done and has tons of issues. All I currently want is suggestions on how to clean up the repetitive code for
- * each direction. This is just a snippet from a larger script that will generate a maze.
- *
- * Variable descriptions:
- * dungeon = 2D array of Tiles (either Hallway or Wall)
- * currentPos = Vector2Int (properties x and y) declaring the cursors current position in the dungeon
- */
- var currentTile = dungeon[currentPos.x, currentPos.y] as HallwayTile;
- var leftTile = currentPos.x > 0 ? dungeon[currentPos.x - 1, currentPos.y] : null;
- var upTile = currentPos.y > 0 ? dungeon[currentPos.x, currentPos.y + 1] : null;
- var rightTile = currentPos.x < dungeonArea.x - 1
- ? dungeon[currentPos.x + 1, currentPos.y]
- : null;
- var bottomTile = currentPos.y < dungeonArea.y - 1
- ? dungeon[currentPos.x, currentPos.y - 1]
- : null;
- // Calculate backtracking
- var numberOfWalls = 0;
- if (leftTile is WallTile lwt1 && lwt1.IsBorderingMultiple())
- {
- numberOfWalls++;
- }
- else if (leftTile is WallTile)
- {
- canStartDigging = true;
- currentPos.x--;
- dungeon[currentPos.x - 1, currentPos.y] =
- new WallTile(new Vector2Int(currentPos.x - 1, currentPos.y));
- }
- else if (leftTile is HallwayTile leftHall1 && leftHall1.Backtracked)
- {
- numberOfWalls++;
- }
- else if (leftTile is HallwayTile leftHall2)
- {
- currentPos.x--;
- }
- if (upTile is WallTile uwt1 && uwt1.IsBorderingMultiple())
- {
- numberOfWalls++;
- }
- else if (upTile is WallTile uwt2)
- {
- canStartDigging = true;
- currentPos.y++;
- dungeon[currentPos.x, currentPos.y + 1] =
- new WallTile(new Vector2Int(currentPos.x, currentPos.y + 1));
- }
- else if (upTile is HallwayTile upHall1 && upHall1.Backtracked)
- {
- numberOfWalls++;
- }
- else if (upTile is HallwayTile upHall2)
- {
- currentPos.y++;
- }
- if (rightTile is WallTile rwt1 && rwt1.IsBorderingMultiple())
- {
- numberOfWalls++;
- }
- else if (rightTile is WallTile rwt2)
- {
- canStartDigging = true;
- currentPos.x++;
- dungeon[currentPos.x + 1, currentPos.y] =
- new WallTile(new Vector2Int(currentPos.x + 1, currentPos.y));
- }
- else if (rightTile is HallwayTile rightHall1 && rightHall1.Backtracked)
- {
- numberOfWalls++;
- }
- else if (rightTile is HallwayTile rightHall2)
- {
- currentPos.x++;
- }
- if (bottomTile is WallTile bwt1 && bwt1.IsBorderingMultiple())
- {
- numberOfWalls++;
- }
- else if (bottomTile is WallTile bwt2)
- {
- canStartDigging = true;
- currentPos.y--;
- dungeon[currentPos.x, currentPos.y - 1] =
- new WallTile(new Vector2Int(currentPos.x, currentPos.y - 1));
- }
- else if (bottomTile is HallwayTile bottomHall1 && bottomHall1.Backtracked)
- {
- numberOfWalls++;
- }
- else if (bottomTile is HallwayTile bottomHall2)
- {
- currentPos.y--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement