private void PlaceTeleporter(ref GameTile tile) { tile.SetIsOccupied(true); tile.GetObject().GetComponent <SpriteRenderer>().sprite = teleporterSprite; tile.GetObject().GetComponent <SpriteRenderer>().color = Color.cyan; tile.SetIsWalkAble(true); }
public void init(GameTile spawnPoint) { playerObject = Resources.Load("Prefabs/PlayerPrefab") as GameObject; //TODO:use scriptable object settings instead of loading prefab playerTile = spawnPoint; playerSprite = playerObject.GetComponent <SpriteRenderer>().sprite; playerColor = playerObject.GetComponent <SpriteRenderer>().color; playerTile.GetObject().GetComponent <SpriteRenderer>().sprite = playerSprite; playerTile.GetObject().GetComponent <SpriteRenderer>().color = playerColor; updateNewPlayerTile(playerTile); }
private void ConnectDisconnectedCaves() { //connect all disconnected caves with "teleporters" in order to ensure the player can reach all caves UnMarkAllTiles(); List <List <GameTile> > FloodFilledAreas = new List <List <GameTile> >(); Vector2 randomPoint; bool atLeastOneOpen; int randomIndexX, randomIndexY; randomPoint = GetRandomOpenUnMarkedPoint(); do { randomPoint = new Vector2((int)Random.Range(0, cols - 1), (int)Random.Range(0, rows - 1)); } while (!grid[(int)randomPoint.x][(int)randomPoint.y].OpenForPlacement() || grid[(int)randomPoint.x][(int)randomPoint.y].IsMarked()); GameTile randomTile = grid[(int)randomPoint.x][(int)randomPoint.y]; FloodFill(ref randomTile, ref FloodFilledAreas); if (HasUnmarkedTiles()) //if we have unreachable caves then we need to make teleporters to access them { do { randomPoint = GetRandomOpenUnMarkedPoint(); randomTile = grid[(int)randomPoint.x][(int)randomPoint.y]; //switch randomTile to the new unmarked tile randomTile.SetIsMarked(true); FloodFill(ref randomTile, ref FloodFilledAreas); PlaceTeleporter(ref randomTile); atLeastOneOpen = false; do { randomIndexX = (int)(Random.Range(0.0f, (float)FloodFilledAreas.Count - 2)); //place a corresponding exit point randomly in an area already flood filled for (int x = 0; x < FloodFilledAreas[randomIndexX].Count; x++) { if (FloodFilledAreas[randomIndexX][x].OpenForPlacement()) { atLeastOneOpen = true; } } } while (!atLeastOneOpen); do { randomIndexY = (int)(Random.Range(0.0f, (float)FloodFilledAreas[randomIndexX].Count - 1)); } while (!FloodFilledAreas[randomIndexX][randomIndexY].OpenForPlacement()); GameTile previouslyMarkedTileToUseAsExit = FloodFilledAreas[randomIndexX][randomIndexY]; randomTile.GetObject().AddComponent <TeleporterTile>().exitPointObject = previouslyMarkedTileToUseAsExit.GetObject(); randomTile.GetObject().GetComponent <TeleporterTile>().exitPoint = previouslyMarkedTileToUseAsExit; GameTile previous_tile = randomTile; randomTile = previouslyMarkedTileToUseAsExit; randomTile.GetObject().AddComponent <TeleporterTile>().exitPointObject = previous_tile.GetObject(); randomTile.GetObject().GetComponent <TeleporterTile>().exitPoint = previous_tile; PlaceTeleporter(ref randomTile); } while (HasUnmarkedTiles()); } FloodFilledAreas.Clear(); }
public void updateNewPlayerTile(GameTile newPlayerTile) { playerTile.SetIsOccupied(false); playerTile.SetIsWalkAble(true); playerTile.GetObject().GetComponent <SpriteRenderer>().sprite = playerTile.GetOriginalSprite(); playerTile.GetObject().GetComponent <SpriteRenderer>().color = playerTile.GetOriginalColor(); playerTile = newPlayerTile; playerTile.GetObject().GetComponent <SpriteRenderer>().sprite = playerSprite; playerTile.GetObject().GetComponent <SpriteRenderer>().color = playerColor; playerTile.SetIsOccupied(true); playerTile.SetIsWalkAble(false); playerTile.SetIsVisible(true); vision.UpdateVision(ref playerTile, ref map, 5); //TODO:Make max view (5) publicly changeable vision.PostProcessingForPlayerView(ref playerTile, ref map); }
private void SetUpWaterTileSettings(GameTile tile) { //Throws all the flags for water tiles, adds the water tile component and sets the proper sprite //precondition: tile must have a unity gameobject //todo:add color settings tile.SetIsDestroyed(false); tile.SetIsWall(false); tile.SetIsMarked(false); tile.SetIsWalkAble(false); tile.SetIsOccupied(true); tile.GetObject().AddComponent <WaterTile>(); tile.SetColor(new Color32(129, 169, 255, 255)); tile.SetSprite(waterSprite); }