Ejemplo n.º 1
0
        public void SetupTilemapGeneration()
        {
            // Create tilemap if it does not exist
            tilemap = GetComponent <Tilemap>();
            if (tilemap == null)
            {
                tilemap = transform.gameObject.AddComponent <Tilemap>();
                transform.gameObject.AddComponent <TilemapRenderer>();
            }

            // Set tilemap bounds object to the value of sideSize x  sideSize x 0
            tilemapBounds = new BoundsInt(Vector3Int.zero, new Vector3Int(sideSize, sideSize, 0));

            // Initialize and fill the rules dictionary
            rules.Add(TransformRule.WALL_FROM_BOUNDS, new TransformToTileFromBounds(TileType.WALL));
            rules.Add(TransformRule.WALL_FROM_ADJACENTS, new TransformToWallFromAdjacents());
            rules.Add(TransformRule.WALL_FOR_ROOM, new TransformToWallForRoom());
            rules.Add(TransformRule.ROOM_FROM_ADJACENTS, new TransformToRoomFromAdjacents());
            rules.Add(TransformRule.FLOOR_FROM_BOUNDS, new TransformToTileFromBounds(TileType.CORRIDOR));

            defaultTile = TilemapHelper.GetDefaultTile();

            // Create DataParser object
            fileParser = new DataParser();
        }
Ejemplo n.º 2
0
        public static List <BoundsInt> FindRooms(Tilemap Tilemap)
        {
            List <BoundsInt> roomAreas = new List <BoundsInt>();
            // Evaluate the area for rooms
            int corridorsXMin  = Tilemap.cellBounds.xMin + 2;
            int corridorsYMin  = Tilemap.cellBounds.yMin + 2;
            int sizeX          = Tilemap.cellBounds.xMax - corridorsXMin - 2;
            int sizeY          = Tilemap.cellBounds.yMax - corridorsYMin - 2;
            var roomAreaBounds = new BoundsInt(corridorsXMin, corridorsYMin, Tilemap.cellBounds.zMin, sizeX, sizeY, 0);

            int        nextPositionToCheck = 0;
            Vector3Int position            = new Vector3Int(0, 0, 0);

            for (int x = roomAreaBounds.xMin; x < roomAreaBounds.xMax; x++)
            {
                position.x = x;
                for (int y = roomAreaBounds.yMin; y < roomAreaBounds.yMax; y++)
                {
                    position.y = y;

                    var tile = Tilemap.GetTile(position);
                    if (TilemapHelper.IsTileOfType(tile.name, TileType.WALL))
                    {
                        if (IsRoom(Tilemap, position, roomAreaBounds, out BoundsInt roomBounds, out nextPositionToCheck))
                        {
                            roomAreas.Add(roomBounds);
                        }
                    }
                }
            }

            return(roomAreas);
        }
Ejemplo n.º 3
0
        public void FindRooms()
        {
            var position = Vector3Int.zero;

            var bounds = tilemap.cellBounds;

            searchedTiles = new Hashtable();

            for (int y = bounds.yMin; y < bounds.yMax; y++)

            {
                position.y = y;
                for (int x = bounds.xMin; x < bounds.xMax; x++)
                {
                    position.x = x;

                    if (!searchedTiles.ContainsKey(position))
                    {
                        var currentTileType = TilemapHelper.GetTileTypeFromPosition(position, tilemap);
                        if (currentTileType == TileType.ROOM)
                        {
                            var room = FindRoomArea(position);
                            if (room.tiles.Any())
                            {
                                rooms.Add(room);
                            }
                        }
                    }
                }
            }

            Debug.Log($"Number of room areas for this tilemap: {rooms.Count}");
        }
Ejemplo n.º 4
0
        public void AddRoomsToMap(List <RoomsList> rooms)
        {
            // Get tilebase tiles for the room and the corridor
            TileBase roomTile     = TilemapHelper.GetTileByType(TileType.ROOM);
            TileBase corridorTile = TilemapHelper.GetTileByType(TileType.CORRIDOR);

            BoundsInt corridorBounds;

            int roomY = 2;

            foreach (var roomList in rooms)
            {
                int roomX = 2;
                foreach (var room in roomList.Rooms)
                {
                    var roomBounds = new BoundsInt(roomX, roomY, 0, room.Width, room.Height, 1);
                    FillAreaWithTile(roomBounds, roomTile);

                    corridorBounds = new BoundsInt(roomX + room.Width, roomY, 0, 1, roomList.MaxHeight, 1);
                    FillAreaWithTile(corridorBounds, corridorTile);

                    roomX += room.Width + 1;
                }
                roomY += roomList.MaxHeight;

                corridorBounds = new BoundsInt(2, roomY, 0, roomList.MaxWidth, 1, 0);
                roomY++;
                FillAreaWithTile(corridorBounds, corridorTile);
            }
        }
Ejemplo n.º 5
0
        public RoomArea FindRoomArea(Vector3Int startPosition)
        {
            Queue <Vector3Int> tilesToCheck = new Queue <Vector3Int>();

            tilesToCheck.Enqueue(startPosition);

            RoomArea room = new RoomArea();

            while (tilesToCheck.Any())
            {
                var position = tilesToCheck.Dequeue();

                if (!searchedTiles.ContainsKey(position))
                {
                    searchedTiles.Add(position, position);

                    var tileType = TilemapHelper.GetTileTypeFromPosition(position, tilemap);

                    if (tileType == TileType.ROOM)
                    {
                        // Add current tile to room
                        room.tiles.Add(new TileObject(position, tileType));

                        tilesToCheck = AddNeighborsInQueue(tilesToCheck, position);
                    }
                }
            }

            return(room);
        }
Ejemplo n.º 6
0
    /// <summary>
    /// This will set <see cref="Doors"/> and it will modify tilemap and set doors into correct places
    /// </summary>
    /// <param name="doorLocations"></param>
    public void SetDoors(DoorLocation doorLocations)
    {
        Doors = doorLocations;
        var floorTile = TilemapHelper.GetTile(TilemapHelper.TileType.TilemapGround);
        var wallTile  = TilemapHelper.GetTile(TilemapHelper.TileType.TilemapWall);

        // TODO: There might be more efficient method to do this
        // Clear doors
        Tilemap.SetTile(new Vector3Int(9, 9, 0), wallTile);
        Tilemap.SetTile(new Vector3Int(17, 5, 0), wallTile);
        Tilemap.SetTile(new Vector3Int(9, 0, 0), wallTile);
        Tilemap.SetTile(new Vector3Int(0, 5, 0), wallTile);
        // If room has top door
        if (Doors.HasFlag(Room.DoorLocation.Top))
        {
            Tilemap.SetTile(new Vector3Int(9, 9, 0), floorTile);
        }
        // If room has right door
        if (Doors.HasFlag(Room.DoorLocation.Right))
        {
            Tilemap.SetTile(new Vector3Int(17, 5, 0), floorTile);
        }
        // If room has bottom door
        if (Doors.HasFlag(Room.DoorLocation.Bottom))
        {
            Tilemap.SetTile(new Vector3Int(9, 0, 0), floorTile);
        }
        // If room has left door
        if (Doors.HasFlag(Room.DoorLocation.Left))
        {
            Tilemap.SetTile(new Vector3Int(0, 5, 0), floorTile);
        }
    }
Ejemplo n.º 7
0
    void UsePowder()
    {
        var targetPosInt = (this.transform.position - this.transform.localPosition)
                           + TilemapHelper.TilePosInFrontOfObj(this.gameObject, movement.lastDirection);
        Bounds bounds = new Bounds(targetPosInt, Vector2.one * 0.5f);
        var    hits   = Physics2D.OverlapAreaAll(bounds.min, bounds.max);

        foreach (var hit in hits)
        {
            if (hit.GetComponentInChildren <ChemPowder>() != null)
            {
                return;
            }
        }

        var obj = Instantiate(
            powderPrefab,
            Vector2.zero,
            Quaternion.identity,
            this.transform.parent);

        obj.transform.position = targetPosInt;
        inventory.Change(ItemsEnum.POWDER, -1);
        putPowder.Invoke();
    }
Ejemplo n.º 8
0
    IEnumerator Idle()
    {
        var duration = Random.Range(0.5f, 0.7f);

        yield return(new WaitForSeconds(duration));

        var dir = HushPuppy.GenerateValidPosition(
            () => new Vector3(
                Random.Range(-distance, distance),
                Random.Range(-distance, distance)),
            (vec) => {
            var hit = Physics2D.BoxCast(
                this.transform.position,
                Vector2.one,
                0f,
                vec.normalized,
                vec.magnitude,
                1 << LayerMask.NameToLayer("Walls")
                    | (1 << LayerMask.NameToLayer("Stairs"))
                    | TilemapHelper.GetLayerMaskCreatureCollision(this.currFloorLevel)
                );
            var outOfBounds = !TilemapHelper.InsideSameRoom(
                this.transform.position,
                this.transform.position + vec,
                RoomManager.Get().dimensions
                );
            return(!hit && !outOfBounds);
        });

        this.target = this.transform.position + dir;
    }
Ejemplo n.º 9
0
        private void SetTile(NVector pos, TileBase tile = null)
        {
            //set it?
            if (tileMap == null)
            {
                return;
            }

            TilemapHelper.SetTile(tileMap[pos.level].GetComponent <Tilemap>(), pos.x, pos.y, tile);
        }
Ejemplo n.º 10
0
        public void Remove()
        {
            //clear tiles
            foreach (PPoint p in Points)
            {
                TilemapHelper.SetTile(tileMap, p.x, p.y, null);
            }

            RemoveAfter();
        }
Ejemplo n.º 11
0
        public void WriteTilemap(Tilemap tilemap)
        {
            var bounds = tilemap.cellBounds;

            // Create filename for this csv file
            var path = BaseOutputPath
                       + BaseFilename
                       + string.Format("{0:yyyy_MM_ddTHH_mm_ss}", DateTime.Now)
                       + $"_{bounds.xMax}x{bounds.yMax}"
                       + BaseFilenameSuffix;

            string line;

            // Write tilemap content into file
            StreamWriter streamWriter = File.CreateText(path);

            // Write tilemap dimensions
            line = string.Format("{0}, {1}", bounds.xMax - bounds.xMin, bounds.yMax - bounds.yMin);
            streamWriter.WriteLine(line);
            streamWriter.Flush();

            // Write column names
            line = string.Format("{0},{1},{2}", "Tile X", "Tile Y", "Tile Type");
            streamWriter.WriteLine(line);
            streamWriter.Flush();

            int        typeId;
            TileBase   tile;
            Vector3Int position = Vector3Int.zero;

            for (int x = bounds.xMin; x < bounds.xMax; x++)
            {
                for (int y = bounds.yMin; y < bounds.yMax; y++)
                {
                    position.x = x;
                    position.y = y;
                    tile       = tilemap.GetTile(position);
                    if (tile != null)
                    {
                        typeId = (int)TilemapHelper.GetTileTypeFromSpriteName(tile.name);
                        line   = string.Format("{0},{1},{2}", x, y, typeId);
                    }
                    else
                    {
                        line = string.Format("{0},{1},{2}", x, y, NullTile);
                    }
                    streamWriter.WriteLine(line);
                    streamWriter.Flush();
                }
            }

            streamWriter.Close();
            streamWriter.Dispose();
        }
        public override void Apply(TilemapStructure tilemap)
        {
            _random = new System.Random(tilemap.Grid.Seed);

            // Re-create the heightmap from our tilemap
            var heightmap = Noise.GenerateNoiseMap(tilemap.Width, tilemap.Height, tilemap.Grid.Seed, GroundHeightmap.NoiseScale, GroundHeightmap.Octaves, GroundHeightmap.Persistance, GroundHeightmap.Lacunarity, GroundHeightmap.Offset);

            if (GroundHeightmap.ApplyIslandGradient)
            {
                var islandGradient = Noise.GenerateIslandGradientMap(tilemap.Width, tilemap.Height);
                for (int x = 0, y; x < tilemap.Width; x++)
                {
                    for (y = 0; y < tilemap.Height; y++)
                    {
                        // Subtract the islandGradient value from the noiseMap value
                        float subtractedValue = heightmap[y * tilemap.Width + x] - islandGradient[y * tilemap.Width + x];

                        // Apply it into the map, but make sure we clamp it between 0f and 1f
                        heightmap[y * tilemap.Width + x] = Mathf.Clamp01(subtractedValue);
                    }
                }
            }

            // Get all start positions
            var validStartPositions = TilemapHelper.GetTilesByType(tilemap, StartingTileTypes.Select(a => (int)a));
            var amountOfRivers      = _random.Next(MinRiverQuota, MaxRiverQuota + 1);

            var rivers = new List <DownstreamRiver>();

            for (int i = 0; i < amountOfRivers; i++)
            {
                // Get valid startPoint with respect to distance between existing rivers
                var startPoint = GetValidStartPosition(validStartPositions, rivers);
                if (!startPoint.HasValue)
                {
                    break;
                }

                // Build river from start based on heightmap
                var river = new DownstreamRiver(startPoint.Value);
                if (river.Build(tilemap, heightmap))
                {
                    rivers.Add(river);
                }
            }

            // Set river tiles into tilemap
            int riverTileId = (int)GroundTileType.River;

            foreach (var riverPosition in rivers.SelectMany(a => a.RiverPositions))
            {
                tilemap.SetTile(riverPosition.x, riverPosition.y, riverTileId);
            }
        }
Ejemplo n.º 13
0
    public static bool InPlayerRoom(GameObject obj)
    {
        var player = GameObject.FindGameObjectWithTag("Player");

        if (player == null)
        {
            return(false);
        }
        return(TilemapHelper.InsideSameRoom(
                   obj.transform.position,
                   player.transform.position,
                   RoomManager.Get().dimensions));
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Update the tilemap according to specific rules (e.g. firespread)
    /// </summary>
    public void UpdateTiles()
    {
        var tiles = TilemapHelper.GetTileDictionary(tilemap);

        if (!levelIsComplete && !isGameOver)
        {
            Debug.Log("Starting next round");
            StartCoroutine(SpreadFire(tiles, dynamicFireSpread));
            ResetActionPoints();

            isGameOver = IsGameOver(TilemapHelper.GetTileDictionary(tilemap));
        }
    }
Ejemplo n.º 15
0
    IEnumerator RespawnTimer()
    {
        yield return(new WaitForSeconds(respawnInterval));

        yield return(new WaitWhile(() => TilemapHelper.InPlayerRoom(this.gameObject)));

        yield return(new WaitForSeconds(0.5f));

        Vector3 position = FindVacantPosition();
        var     obj      = Instantiate(whitePowderPrefab, position, Quaternion.identity, this.transform.parent);

        RegisterPowder(obj.GetComponent <WhitePowder>());
    }
Ejemplo n.º 16
0
    private void CreateRandomTileProps()
    {
        // remove objects that have changed tile type
        for (int i = grassPropsList.Count - 1; i >= 0; i--)
        {
            if (!((AbstractGameTile)tilemap.GetTile(grassPropsList[i].Item1) is GrassTile))
            {
                Destroy(grassPropsList[i].Item2);
                grassPropsList.RemoveAll(item => item.Item1 == grassPropsList[i].Item1);
            }
        }

        var tileDic = TilemapHelper.GetTileDictionary(tilemap);

        foreach (var tileType in tileDic.Keys)
        {
            var tilesWithType = tileDic[tileType];
            if (tileType == typeof(GrassTile))
            {
                foreach (var tile in tilesWithType)
                {
                    if (grassPropsList.Count == 0 || !grassPropsList.Any(i => i.Item1 == tile))
                    {
                        var randomProp = UnityEngine.Random.Range(1, 4); // random prop 1-4 (4 is excluded)
                        var newProp    = Instantiate(Resources.Load("Forest/ForestProps" + randomProp), GrassProps.transform) as GameObject;
                        var cellPos    = tilemap.CellToWorld(tile);
                        newProp.transform.position    = new Vector3(cellPos.x, newProp.transform.position.y, cellPos.z);
                        newProp.transform.eulerAngles = new Vector3(newProp.transform.rotation.x, UnityEngine.Random.Range(0f, 360f), newProp.transform.rotation.z);

                        grassPropsList.Add(new Tuple <Vector3Int, GameObject>(tile, newProp));
                    }
                }
            }
            else if (tileType == typeof(BurntTile))
            {
                foreach (var tile in tilesWithType)
                {
                    if (burnedPropsList.Count == 0 || !burnedPropsList.Any(i => i.Item1 == tile))
                    {
                        var randomProp = UnityEngine.Random.Range(1, 3); // random prop 1-3 (3 is excluded)
                        var newProp    = Instantiate(Resources.Load("Burned/BurnedProps" + randomProp), BurnedProps.transform) as GameObject;
                        var cellPos    = tilemap.CellToWorld(tile);
                        newProp.transform.position    = new Vector3(cellPos.x, newProp.transform.position.y, cellPos.z);
                        newProp.transform.eulerAngles = new Vector3(newProp.transform.rotation.x, UnityEngine.Random.Range(0f, 360f), newProp.transform.rotation.z);

                        burnedPropsList.Add(new Tuple <Vector3Int, GameObject>(tile, newProp));
                    }
                }
            }
        }
    }
Ejemplo n.º 17
0
    void ClearPath()
    {
        var walls  = TilemapHelper.GetWallsTilemap();
        var posInt = HushPuppy.GetVecAsTileVec(this.transform.position);

        var tile = walls.GetTile(posInt);

        if (tile != null)
        {
            var sprite = ((Tile)tile).sprite;
            fakeWall.sprite = sprite;
            walls.SetTile(posInt, null);
        }
    }
Ejemplo n.º 18
0
    void Start()
    {
        foreach (var powder in GameObject.FindObjectsOfType <WhitePowder>())
        {
            if (TilemapHelper.InsideSameRoom(this.transform.position, powder.transform.position, RoomManager.Get().dimensions))
            {
                RegisterPowder(powder);
            }
        }

        if (spawnPoints.Count == 0)
        {
            Debug.LogError("This shouldn't be happening.");
            Debug.Break();
        }
    }
Ejemplo n.º 19
0
        public void CreateTilemapFromLeafs(Tilemap tilemap)
        {
            if (Children.Count == 0)
            {
                TileBase tile = TilemapHelper.GetTileByType(Type);

                TilemapHelper.FillAreaWithTile(this.LeafBounds, tile, tilemap);
            }
            else
            {
                foreach (var child in Children)
                {
                    child.CreateTilemapFromLeafs(tilemap);
                }
            }
        }
Ejemplo n.º 20
0
    void LeaveSlime()
    {
        Vector3Int currentInt = GetCurrentPosInt();
        Vector3Int belowInt   = currentInt + Vector3Int.down;

        if (tilesToSlime.Contains(belowInt))
        {
            tilesToSlime.Remove(belowInt);
            if (TilemapHelper.IsWall(belowInt))
            {
                Instantiate(
                    slorgSlimePrefab,
                    belowInt + new Vector3(0.5f, 0.5f, 0),
                    Quaternion.identity,
                    this.transform.parent);
            }
        }
    }
Ejemplo n.º 21
0
    IEnumerator Loop()
    {
        while (true)
        {
            var food = sensors.observations.Find((f) => f.CompareTag("MoleRatFood"));
            if (state != State.DIGGING && food != null &&
                TilemapHelper.InPlayerRoom(this.gameObject))
            {
                targetObj = food;
                target    = food.transform.position;
                state     = State.MOVING;
                // yield return ShowExclamation();
            }

            switch (state)
            {
            case State.IDLE:
                yield return(Idle());

                state = State.MOVING;
                break;

            case State.MOVING:
                yield return(Move(food != null));

                if (food != null &&
                    Vector3.Distance(this.transform.position, food.transform.position) < 0.1f)
                {
                    state = State.DIGGING;
                }
                else
                {
                    state = State.IDLE;
                }
                break;

            case State.DIGGING:
                yield return(Dig());

                state = State.IDLE;
                break;
            }
        }
    }
Ejemplo n.º 22
0
 /// <summary>
 /// Apply a specific transformation rule to a specific tile
 /// </summary>
 /// <param name="rule">The TRANFROM_RULE to be applied to this tile</param>
 /// <param name="position">The position of the tile on the tilemap</param>
 /// <param name="neighbors">the tile's neighborhood, the 3x3 area around the tile as a 1D array</param>
 /// <returns></returns>
 public TileBase ApplyRule(TransformRule rule, Vector3Int position, TileBase[] neighbors, BoundsInt bounds)
 {
     if (rule == TransformRule.WALL_FROM_BOUNDS)
     {
         var newTileType = rules[TransformRule.WALL_FROM_BOUNDS].Apply(position, bounds);
         if (newTileType != null)
         {
             return(TilemapHelper.GetTileByType(newTileType));
         }
     }
     if (rule == TransformRule.WALL_FROM_ADJACENTS)
     {
         var newTileType = rules[TransformRule.WALL_FROM_ADJACENTS].Apply(neighbors);
         if (newTileType != null)
         {
             return(TilemapHelper.GetTileByType(newTileType));
         }
     }
     if (rule == TransformRule.WALL_FOR_ROOM)
     {
         var newTileType = rules[TransformRule.WALL_FOR_ROOM].Apply(neighbors);
         if (newTileType != null)
         {
             return(TilemapHelper.GetTileByType(newTileType));
         }
     }
     if (rule == TransformRule.ROOM_FROM_ADJACENTS)
     {
         var newTileType = rules[TransformRule.ROOM_FROM_ADJACENTS].Apply(neighbors);
         if (newTileType != null)
         {
             return(TilemapHelper.GetTileByType(newTileType));
         }
     }
     if (rule == TransformRule.FLOOR_FROM_BOUNDS)
     {
         var newTileType = rules[TransformRule.FLOOR_FROM_BOUNDS].Apply(position, bounds);
         if (newTileType != null)
         {
             return(TilemapHelper.GetTileByType(newTileType));
         }
     }
     return(null);
 }
Ejemplo n.º 23
0
    void HandleRoomChange()
    {
        var roomCenter = TilemapHelper.GetRoomCenter(
            this.cameraFocus.transform.position,
            roomManager.dimensions);

        if (lastRoomCenter != roomCenter)
        {
            var roomDistance = RoomManager.RoomDistance(lastRoomCenter, roomCenter, roomManager.dimensions);

            float dur = roomDistance == 1 ? transitionDuration : 0f;

            this.transform.DOMove(roomCenter + offset, dur);
            letterboxTilemap.transform.DOMove(roomCenter, dur);
            lastRoomCenter = roomCenter;

            roomManager.RegisterChange(roomCenter);
        }
    }
Ejemplo n.º 24
0
        public TileType?Apply(TileBase[] neighbors)
        {
            if (neighbors.Length < 9)
            {
                return(null);
            }
            // Get middle tile
            var tile = neighbors[(int)TilePositions.MIDDLE];

            var tileType = TilemapHelper.GetTileTypeFromSpriteName(tile.name);

            // Check if the tile is already a wall
            if (tileType == TileType.WALL)
            {
                return(null);
            }
            // Check if the tile is not floor
            if (tileType != TileType.ROOM)
            {
                return(null);
            }

            var neighborTypes = new TileType[8];
            int index         = 0;
            int count         = 0;

            foreach (var neighbor in neighbors)
            {
                if (count != (int)TilePositions.MIDDLE)
                {
                    neighborTypes[index] = TilemapHelper.GetTileTypeFromSpriteName(neighbor.name);
                    index++;
                }
                count++;
            }

            if (TilemapHelper.IsNextToType(neighborTypes, TileType.CORRIDOR))
            {
                return(TileType.WALL);
            }

            return(null);
        }
Ejemplo n.º 25
0
        public TileType?Apply(TileBase[] neighbors)
        {
            if (neighbors.Length < 9)
            {
                return(null);
            }
            // Get middle tile
            var tile = neighbors[(int)TilePositions.MIDDLE];

            // Check if the tile is already a wall
            if (TilemapHelper.GetTileTypeFromSpriteName(tile.name) == TileType.WALL)
            {
                return(null);
            }

            // Get horizontal and vertical adjacent tiles
            var adjacents = new TileBase[4] {
                neighbors[(int)TilePositions.MIDDLE_LEFT],
                neighbors[(int)TilePositions.MIDDLE_RIGHT],
                neighbors[(int)TilePositions.TOP_MIDDLE],
                neighbors[(int)TilePositions.DOWN_MIDDLE]
            };

            int count = 0;

            foreach (var adjacentTile in adjacents)
            {
                if (adjacentTile != null)
                {
                    count += TilemapHelper.GetTileTypeFromSpriteName(adjacentTile.name) == TileType.WALL ?
                             1 : 0;
                }
            }

            if (count >= 2)
            {
                return(TileType.WALL);
            }

            return(null);
        }
Ejemplo n.º 26
0
        // Update is called once per frame
        public void Update()
        {
            var fireTiles = TilemapHelper.GetTileCoordinates(Tilemap).Where(t => Tilemap.GetTile(t) is FireTile).ToList();

            if (fireTiles.Contains(TilePosition))
            {
                audioController.PlayUnitDeathSound();
                Destroy(gameObject);

                // Choose next unit
                var nextUnit = levelController.playerUnits.Where(unit => unit != null && unit.ActionPoints > 0).ToList();
                if (nextUnit.Count > 0)
                {
                    levelController.currentlySelectedUnit = levelController.playerUnits.IndexOf(nextUnit.First());
                }
                else
                {
                    levelController.currentlySelectedUnit = -1;
                }
            }
        }
Ejemplo n.º 27
0
        public override void Apply(TilemapStructure tilemap)
        {
            _random = new System.Random(tilemap.Grid.Seed);
            var rivers = new List <DrunkenRiver>();

            var validStartPositions = TilemapHelper.GetTilesByType(tilemap, StartingTileTypes.Select(a => (int)a));
            var amountOfRivers      = _random.Next(MinRiverQuota, MaxRiverQuota + 1);

            for (int i = 0; i < amountOfRivers; i++)
            {
                // Get valid startPoint with respect to distance between existing rivers
                var startPoint = GetValidStartPosition(validStartPositions, rivers);
                if (!startPoint.HasValue)
                {
                    break;
                }

                // Find valid endPos (closest deep water tile to startPos)
                var endPos = TilemapHelper.FindClosestTileByType(tilemap, startPoint.Value, (int)GroundTileType.DeepWater);
                if (!endPos.HasValue)
                {
                    break;
                }

                // Build river from start to end position
                var river = new DrunkenRiver(_random, RiverDriftChance, startPoint.Value, endPos.Value);
                if (river.Build())
                {
                    rivers.Add(river);
                }
            }

            // Set river tiles into tilemap
            int riverTileId = (int)GroundTileType.River;

            foreach (var riverPosition in rivers.SelectMany(a => a.RiverPositions))
            {
                tilemap.SetTile(riverPosition.x, riverPosition.y, riverTileId);
            }
        }
Ejemplo n.º 28
0
    void ClimbWall()
    {
        Vector3Int currentInt = GetCurrentPosInt();
        Vector3Int aboveInt   = currentInt + Vector3Int.up;
        Vector3Int belowInt   = currentInt + Vector3Int.down;

        if (TilemapHelper.IsWall(currentInt) ||
            TilemapHelper.IsWall(aboveInt) ||
            TilemapHelper.IsWall(belowInt))
        {
            this.rb.velocity = Vector2.up * speed;

            if (!tilesToSlime.Contains(currentInt))
            {
                tilesToSlime.Add(currentInt);
            }
        }
        else
        {
            this.rb.velocity = Vector2.zero;
        }
    }
Ejemplo n.º 29
0
    public void DisplayReachableTilesForCurrentUnit()
    {
        DestroyReachableTilesDisplayHelp();

        if (currentlySelectedUnit != -1)
        {
            var currentUnit    = playerUnits[currentlySelectedUnit];
            var reachableTiles = TilemapHelper.FindReachableTiles(currentUnit.TilePosition, currentUnit.ActionPoints, tilemap);
            foreach (var fringe in reachableTiles)
            {
                foreach (var tile in fringe)
                {
                    if (tile.Item2 <= currentUnit.ActionPoints)
                    {
                        var newHelper = Instantiate(Resources.Load("RangeHexagon"), RangeDisplayHelper.transform) as GameObject;
                        var cellPos   = tilemap.CellToWorld(tile.Item1);
                        newHelper.transform.position = new Vector3(cellPos.x, newHelper.transform.position.y, cellPos.z);
                    }
                }
            }
        }
    }
Ejemplo n.º 30
0
        public void CreatePaths()
        {
            var rooms = evaluator.rooms;

            RoomArea currentRoom;
            RoomArea nextRoom;

            TileBase roomTile = TilemapHelper.GetTileByType(TileType.ROOM);

            for (int i = 0; i < rooms.Count; i++)
            {
                currentRoom = rooms[i];
                if (i + 1 < rooms.Count)
                {
                    nextRoom = rooms[i + 1];
                    var path = CalculatePathBetweenRooms(currentRoom, nextRoom);
                    foreach (var position in path)
                    {
                        tilemap.SetTile(position, roomTile);
                    }
                }
            }
        }