private void CreateAttribute(IntPair position, Tile tile) { if (tile.HasAttribute(Type.ENGING_POINT)) { CreateEndingAttribute(position); } if (tile.HasAttribute(Type.ENEMY_SPAWNING_POINT)) { CreateEnemy(position); } }
private Tile CreateOrUpdateTileIn(IntPair position, Dictionary<IntPair, Tile> allTiles) { Tile tile; allTiles.TryGetValue(position, out tile); if (tile == null) { tile = new Tile(); allTiles.Add(position, tile); } foreach (Direction direction in Utils.GetAllDirections()) { IntPair neighbourPosition = position.Move(direction); Tile neighbour; allTiles.TryGetValue(neighbourPosition, out neighbour); if (neighbour != null) { tile.BindNeighbours(neighbour, direction); } } return tile; }
private void CreateGameObject(GameObject what, IntPair where, float y) { Vector3 gameObjectPosition = new Vector3(where.x, y, where.y) + transform.position; GameObject gameObjectInstance = Instantiate(what, gameObjectPosition, Quaternion.identity) as GameObject; gameObjectInstance.transform.parent = boardHolder.transform; }
private void CreateFloor(IntPair position) { CreateGameObject(prefabHolder.floor, position, 0.0f); }
private void CreateEnemy(IntPair position) { CreateGameObject(prefabHolder.enemy, position, 0.0f); }
private void CreateEndingAttribute(IntPair position) { CreateGameObject(prefabHolder.endingPoint, position, 0.5f); }
private void CreateCeiling(IntPair position) { CreateGameObject(prefabHolder.ceiling, position, 2.0f); }
private void CreateWalls(IntPair position, Tile tile) { foreach (Direction direciton in Model.Utils.GetAllDirections()) { if (tile.GetNeighbour(direciton) == null) { CreateWall(position.Move(direciton)); } } }
private void CreateWall(IntPair position) { CreateGameObject(prefabHolder.wall, position, 1.0f); }
public bool Equals(IntPair other) { return this == other; }
public IntPair(IntPair other) { this.x = other.x; this.y = other.y; }
public Room(IntRange widthRange, IntRange heightRange) { this.size = new IntPair(widthRange.Random, heightRange.Random); }
// Assumes position is in top-left corner of room private IntPair MovePositionToBorderOfRoomInGivenDirection(IntPair position, Room room, Direction direction) { int offset; // TODO: Add some randomized factor so that rooms are not linked always from top-left corner switch (direction) { case Direction.EAST: offset = room.size.x - 1; break; case Direction.NORTH: offset = room.size.y - 1; break; default: offset = 0; break; } return position.Move(direction, offset); }
// Assumes positon is at the end of the corridor private IntPair MovePositionFromCorridorBeginningToBottomLeftEndRoom(IntPair position, Corridor corridor) { int offset; switch (corridor.direction) { case Direction.WEST: offset = corridor.exitRoom.size.x; break; case Direction.SOUTH: offset = corridor.exitRoom.size.y; break; default: offset = 1; break; } return position.Move(corridor.direction, offset); }
private void GenerateTilesForRoom(Room room, IntPair topLeftCorner, Dictionary<IntPair, Tile> allTiles) { // Start filling up tiles from top left corner using width/height int width = room.size.x; int height = room.size.y; Tile tile; for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { tile = CreateOrUpdateTileIn(new IntPair(i + topLeftCorner.x, j + topLeftCorner.y), allTiles); if (UnityEngine.Random.Range(0.0f, 100.0f) <= enemyDensity) { tile.AddAttribute(new global::Map.Model.TileAttribute.EnemySpawningPoint()); } } } }
// Assumes position is at end of starting room // Returns the position where the corridor ends private IntPair GenerateTilesForCorridor(Corridor corridor, IntPair position, Dictionary<IntPair, Tile> allTiles) { for (int i = 0; i < corridor.length; ++i) { position = position.Move(corridor.direction); CreateOrUpdateTileIn(position, allTiles); } return position; }