private void SetRegister(List <PathPoint> points, int storeNumber) { float gridSize = tiles.gridSize; float gridPercentage = (1 / gridSize); List <MallSpace> stores = tiles.GetStoreSpaces; MallSpace currentStore = stores[storeNumber]; Vector2 storeCenter = currentStore.GetMiddleOfRoom; Vector2 storePosition = currentStore.GetStartPositionOfRoom; Vector2 storeSize = currentStore.GetHeightWidthofRoom; Tile[,] tilesT; tilesT = tiles.stores[storeNumber]; float x = storeSize.x - 1; float y = storeSize.y - 1; if (TestIfDoor(points, storeNumber)) { objectSpawner.SpawnObjectOnPlace(points, new Vector2(3, 3), new Vector2(x / 2, y), 180, registers[0], storeNumber); } else { objectSpawner.SpawnObjectOnPlace(points, new Vector2(3, 3), new Vector2(x / 2, 0), 0, registers[0], storeNumber); } }
private List <Vector2> GetPlazaGrid(MallSpace plaza, bool isStore, int roomNumber) { List <Vector2> list = new List <Vector2>(); for (int x = plaza.x; x < plaza.x + plaza.w; x++) { for (int y = plaza.y; y < plaza.y + plaza.h; y++) { if (x < 0 || y < 0 || x >= mallWidth || y >= mallHeight) { break; } if (isStore) { if (stores[roomNumber][x, y] == Tile.Floor && hallways[x, y] != Tile.Floor || stores[roomNumber][x, y] == Tile.Door) { list.Add(new Vector2(x, y)); } } else { if (hallways[x, y] == Tile.Floor || hallways[x, y] == Tile.Door) { list.Add(new Vector2(x, y)); } } } } return(list); }
public void SpawnObjectOnPlace(List <PathPoint> points, Vector2 dimensions, Vector2 position, float rotation, GameObject furniture, int storeNumber) { float gridSize = tiles.gridSize; float gridPercentage = (1 / gridSize); List <MallSpace> stores = tiles.GetStoreSpaces; MallSpace currentStore = stores[storeNumber]; Vector2 storeCenter = currentStore.GetMiddleOfRoom; Vector2 storePosition = currentStore.GetStartPositionOfRoom; Vector2 storeSize = currentStore.GetHeightWidthofRoom; Vector2 actuaPosiotion = new Vector2(position.x + storePosition.x, position.y + storePosition.y); allGameObjectsMall.Add(Instantiate(furniture, new Vector3(actuaPosiotion.x, 0, actuaPosiotion.y), Quaternion.Euler(0, rotation, 0), mallGenerator.gameObject.transform)); Vector2 positionCube = new Vector2(actuaPosiotion.x - gridPercentage, actuaPosiotion.y - gridPercentage); for (int z = 0; z < dimensions.x; z++) { for (int q = 0; q < dimensions.y; q++) { PathPoint temp = PathfindingNodeManager.Instance.GetPathPoint(positionCube); temp.SetNode = PathfindNode.Nonwalkable; positionCube[0] += gridPercentage; } positionCube[0] = (actuaPosiotion.x - gridPercentage); positionCube[1] += gridPercentage; } }
private void CreateMainPlaza() { //Shape of Plaza is always an odd number (3x3,5x5, ect). plazaSizeWidth = Random.Range((int)plazaSize.x, (int)plazaSize.y + 1); plazaSizeWidth = plazaSizeWidth % 2 == 0 ? plazaSizeWidth - 1 : plazaSizeWidth; plazaSizeHeight = Random.Range((int)plazaSize.x, (int)plazaSize.y + 1); plazaSizeHeight = plazaSizeHeight % 2 == 0 ? plazaSizeHeight - 1 : plazaSizeHeight; //position of Plaza is always in center of the "map" and an odd number (3x3,5x5, ect). int xPos = (mallWidth / 2) - (plazaSizeWidth / 2); xPos = xPos % 2 == 0 ? xPos - 1 : xPos; int yPos = (mallHeight / 2) - (plazaSizeHeight / 2); yPos = yPos % 2 == 0 ? yPos - 1 : yPos; DoActionForPartOfGrid(xPos, yPos, plazaSizeWidth, plazaSizeHeight, (i, j) => { hallways[i, j] = Tile.Floor; }); MallSpace plaza = new MallSpace(xPos, yPos, plazaSizeHeight, plazaSizeWidth); hallwaySpaces.Add(plaza); }
private bool TestIfDoor(List <PathPoint> points, int storeNumber) { float gridSize = tiles.gridSize; float gridPercentage = (1 / gridSize); List <MallSpace> stores = tiles.GetStoreSpaces; MallSpace currentStore = stores[storeNumber]; Vector2 storeCenter = currentStore.GetMiddleOfRoom; Vector2 storePosition = currentStore.GetStartPositionOfRoom; Vector2 storeSize = currentStore.GetHeightWidthofRoom; Tile[,] tilesT; tilesT = tiles.stores[storeNumber]; float x = storeSize.x - 1; float y = storeSize.y - 1; if (tilesT[Mathf.RoundToInt(storePosition.x + (gridPercentage * gridSize) * (storeSize.x / gridSize)), (int)storePosition.y] == Tile.Door) { return(true); } return(false); }
private void InitSettings(int storeNumber) { tiles = Tiles.Instance; objectSpawner = ObjectSpawner.Instance; pathfindingNodeManager = PathfindingNodeManager.Instance; stepsSize = (1 / tiles.gridSize); gridSize = tiles.gridSize; gridPercentage = (1 / gridSize); registers = Resources.LoadAll <GameObject>("Register"); pointsInRoom = new List <PathPoint>(); foreach (PathPoint point in pathfindingNodeManager.ReturnNavPointList()) { if (point.GetStoreNumber == storeNumber) { pointsInRoom.Add(point); } } stores = tiles.GetStoreSpaces; currentStore = stores[storeNumber]; storeSize = currentStore.GetHeightWidthofRoom; storeDecoration = Resources.LoadAll <GameObject>("StoreDecoration"); }
//Generate store tiles [NOT GAME-OBJECTS] private void GenerateStores() { //On Right top hall int xPos; int yPos; xPos = (int)hallwaySpaces[0].GetMiddleOfRoom.x + (plazaSizeWidth / 2); xPos = xPos % 2 == 0 ? xPos - 1 : xPos; yPos = (int)hallwaySpaces[0].GetMiddleOfRoom.y + (plazaSizeHeight / 2) + (hallWidht / 2); yPos = yPos % 2 == 0 ? yPos - 1 : yPos; for (int i = 0; i < storesOnHallway; i++) { int randX = Random.Range((int)storeWidth.x, (int)storeWidth.y); randX = randX % 2 == 0 ? randX - 1 : randX; int randY = Random.Range((int)storeHeight.x, (int)storeHeight.y); randY = randY % 2 == 0 ? randY - 1 : randY; Tile[,] tempStore = new Tile[mallWidth, mallHeight]; DoActionForPartOfGrid(xPos, yPos, randX, randY, (k, j) => { tempStore[k, j] = Tile.Floor; }); stores.Add(tempStore); MallSpace plaza = new MallSpace(xPos, yPos, randX, randY); storeSpaces.Add(plaza); //Set size for Hallway xPos += randX; //yPos += randY; if (hallwaysize[0] < xPos) { hallwaysize[0] = xPos; } if (hallwaysize[2] < randY) { hallwaysize[2] = randY; } } //On Right bottom; xPos = (int)hallwaySpaces[0].GetMiddleOfRoom.x + (plazaSizeWidth / 2); xPos = xPos % 2 == 0 ? xPos - 1 : xPos; yPos = (int)hallwaySpaces[0].GetMiddleOfRoom.y - (hallWidht / 2); for (int i = 0; i < storesOnHallway; i++) { int randX = Random.Range((int)storeWidth.x, (int)storeWidth.y); randX = randX % 2 == 0 ? randX - 1 : randX; int randY = Random.Range((int)storeHeight.x, (int)storeHeight.y); randY = randY % 2 == 0 ? randY - 1 : randY; Tile[,] tempStore = new Tile[mallWidth, mallHeight]; DoActionForPartOfGrid(xPos, yPos - randY, randX, randY, (k, j) => { tempStore[k, j] = Tile.Floor; }); stores.Add(tempStore); MallSpace plaza = new MallSpace(xPos, yPos - randY, randX, randY); storeSpaces.Add(plaza); //Set size forH Hallway xPos += randX; if (hallwaysize[0] < xPos) { hallwaysize[0] = xPos; } if (hallwaysize[1] < randY) { hallwaysize[1] = randY; } } //On Left top; xPos = (int)hallwaySpaces[0].GetMiddleOfRoom.x - (plazaSizeWidth / 2); xPos = xPos % 2 == 0 ? xPos - 1 : xPos; xPos += 1; hallwaysize[3] = xPos; yPos = yPos = (int)hallwaySpaces[0].GetMiddleOfRoom.y + (plazaSizeHeight / 2) + (hallWidht / 2); yPos = yPos % 2 == 0 ? yPos - 1 : yPos; for (int i = 0; i < storesOnHallway; i++) { int randX = Random.Range((int)storeWidth.x, (int)storeWidth.y); randX = randX % 2 == 0 ? randX - 1 : randX; int randY = Random.Range((int)storeHeight.x, (int)storeHeight.y); randY = randY % 2 == 0 ? randY - 1 : randY; xPos -= randX; Tile[,] tempStore = new Tile[mallWidth, mallHeight]; DoActionForPartOfGrid(xPos, yPos, randX, randY, (k, j) => { tempStore[k, j] = Tile.Floor; }); stores.Add(tempStore); MallSpace plaza = new MallSpace(xPos, yPos, randX, randY); storeSpaces.Add(plaza); if (hallwaysize[3] > xPos) { hallwaysize[3] = xPos; } if (hallwaysize[2] < randY) { hallwaysize[2] = randY; } } //On Left bottom xPos = (int)hallwaySpaces[0].GetMiddleOfRoom.x - (plazaSizeWidth / 2); xPos = xPos % 2 == 0 ? xPos - 1 : xPos; xPos += 1; yPos = yPos = (int)hallwaySpaces[0].GetMiddleOfRoom.y - (hallWidht / 2); for (int i = 0; i < storesOnHallway; i++) { int randX = Random.Range((int)storeWidth.x, (int)storeWidth.y); randX = randX % 2 == 0 ? randX - 1 : randX; int randY = Random.Range((int)storeHeight.x, (int)storeHeight.y); randY = randY % 2 == 0 ? randY - 1 : randY; xPos -= randX; Tile[,] tempStore = new Tile[mallWidth, mallHeight]; DoActionForPartOfGrid(xPos, yPos - randY, randX, randY, (k, j) => { tempStore[k, j] = Tile.Floor; }); stores.Add(tempStore); MallSpace plaza = new MallSpace(xPos, yPos - randY, randX, randY); storeSpaces.Add(plaza); if (hallwaysize[3] > xPos) { hallwaysize[3] = xPos; } if (hallwaysize[1] < randY) { hallwaysize[1] = randY; } } }