Example #1
0
    private bool TileValue(ITilemap tileMap, Vector3Int position)
    {
        TileBase tile = tileMap.GetTile(position);

        if (tile != null && tile == this)
        {
            return(true);
        }

        if (tile != null && tile.GetType() == typeof(_5x5Tile))
        {
            var _5x5tile = (_5x5Tile)tile;
            if (_5x5tile.height > height)
            {
                return(true);
            }
        }

        if (tile != null && tile.GetType() == typeof(CliffTile))
        {
            var cliffTile = (CliffTile)tile;
            if (cliffTile.height > height)
            {
                return(true);
            }
        }

        return(false);
    }
Example #2
0
        public void CreatePreset_CreateDefaultTile_HasPresetTileProperties()
        {
            Tile presetTile = TileUtility.DefaultTile(m_Sprite) as Tile;

            Assert.IsNotNull(presetTile);

            presetTile.color = Color.red;

            var preset        = new Preset(presetTile);
            var defaultPreset = new DefaultPreset(String.Empty, preset);
            var presetType    = preset.GetPresetType();

            AssetDatabase.CreateAsset(preset, kPresetAssetPath);

            Preset.SetDefaultPresetsForType(presetType, new[] { defaultPreset });

            m_Tile = TileUtility.CreateDefaultTile();
            var tile = m_Tile as Tile;

            Assert.AreEqual(typeof(Tile), m_Tile.GetType());
            Assert.IsNotNull(tile);

            Assert.AreEqual(m_Sprite, tile.sprite);
            Assert.NotNull(tile.sprite);
            Assert.AreEqual(Color.red, tile.color);
            Assert.AreNotEqual(Color.white, tile.color);

            Object.DestroyImmediate(presetTile);
            Preset.SetDefaultPresetsForType(presetType, null);
        }
    public override IEnumerator MoveToTile(Vector2 position)
    {
        yield return(base.MoveToTile(position));

        //check if they are on a space with a battleStart

        //tile checker thingy
        Tilemap map = OverworldManager.instance.tilemap;

        TileBase tile = map.GetTile(new Vector3Int((int)position.x - 1, (int)position.y - 1, 0));

        if (tile.GetType() == typeof(OverworldMonsterTile))
        {
            OverworldMonsterTile mTile = (OverworldMonsterTile)tile;
            if (Random.value < mTile.chance)
            {
                OverworldManager.instance.StartBattle(mTile.GetRandomPool());
            }
        }

        //check if they are on a space with a mapObject
        MapTransition[] mapTransitionObjects = GameObject.FindObjectsOfType <MapTransition>();
        foreach (MapTransition mtObject in mapTransitionObjects)
        {
            if (transform.position == mtObject.transform.position)
            {
                OverworldManager.instance.ChangeMap(mtObject.MapName, mtObject.moveLocation);
            }
        }

        yield break;
    }
    private Vector3Int FindRandomFreeCellNear(Vector3Int cell)
    {
        Vector3Int closestCell = cell;
        float      dist        = float.MaxValue;

        for (int i = -2; i <= 2; i += 1)
        {
            for (int j = -2; j <= 2; j += 1)
            {
                if (i == 0 && j == 0)
                {
                    continue;
                }

                var      testCell    = new Vector3Int(cell.x + i, cell.y + j, 0);
                TileBase tile        = tilemap.GetTile(testCell);
                bool     hasObstacle = tile != null && tile.GetType() == typeof(WorldTile);
                if (!hasObstacle)
                {
                    Vector3 testCellPos = tilemap.GetCellCenterWorld(testCell);
                    float   d           = UnityEngine.Random.Range(0, 100);
                    if (d <= dist)
                    {
                        dist        = d;
                        closestCell = testCell;
                    }
                }
            }
        }

        return(closestCell);
    }
    private Vector3Int FindClosestFreeCellNear(Vector3Int cell, Character character)
    {
        Vector3Int closestCell = cell;
        float      dist        = float.MaxValue;

        for (int i = -1; i <= 1; i += 2)
        {
            for (int j = -1; j <= 1; j += 2)
            {
                var      testCell    = new Vector3Int(cell.x + i, cell.y + j, 0);
                TileBase tile        = tilemap.GetTile(testCell);
                bool     hasObstacle = tile != null && tile.GetType() == typeof(WorldTile);
                if (!hasObstacle)
                {
                    Vector3 testCellPos = tilemap.GetCellCenterWorld(testCell);
                    float   d           = (character.transform.position - testCellPos).magnitude;
                    if (d <= dist)
                    {
                        dist        = d;
                        closestCell = testCell;
                    }
                }
            }
        }

        return(closestCell);
    }
    public void PlaceTilesInWorldSpace(Vector3Int position, Grid grid, Tilemap tileMap)
    {
        if (hasTile)
        {
            if (tile != null)
            {
                if (CanBePlaced(tile, position))
                {
                    gameManager.ProceedToNextGamePhase();

                    currentTileMap.SetTile(position, tile);
                    deckManager.RefreshHand(currentHandChoice.GetComponent <HandTile>().myIndex);

                    Vector3 nextPos = grid.GetCellCenterWorld(position);
                    nextPos.x += 0.0f;
                    nextPos.y += 0.5f;
                    nextPos.z  = 0;

                    boardManager.aStarGrid.SetVariables(nextPos);
                    boardManager.Pathfinding(playerIcon.transform.position, nextPos);

                    List <Vector3> path = new List <Vector3>();

                    foreach (Node n in boardManager.aStarGrid.path)
                    {
                        path.Add(n.worldPosition);
                    }

                    StartCoroutine(playerIcon.GetComponent <PartyBehaviour>().MoveParty(path.ToArray()));

                    if (tile.GetType() == typeof(VariantTiles))
                    {
                        VariantTiles vTile = tile as VariantTiles;

                        if (vTile.variantType == VariantTiles.VariantType.Enemy)
                        {
                            nextPos.y -= 0.25f;

                            Instantiate(gameManager.enemyPartyTemplate, nextPos, Quaternion.identity);

                            Instantiate(gameManager.combatPositions, nextPos, Quaternion.identity);
                        }
                        else if (vTile.variantType == VariantTiles.VariantType.Boss)
                        {
                            nextPos.y -= 0.25f;

                            Instantiate(gameManager.enemyPartyTemplate, nextPos, Quaternion.identity);
                            Instantiate(gameManager.combatPositions, nextPos, Quaternion.identity);
                        }
                    }
                }
            }

            hasTile = false;
            tile    = null;
            previewSprite.sprite = null;
        }
    }
    public virtual IEnumerator MoveToTile(Vector2 position)
    {
        //check if we can move there
        Tilemap map = OverworldManager.instance.tilemap;

        TileBase tile = map.GetTile(new Vector3Int((int)position.x - 1, (int)position.y - 1, 0));

        if (tile.GetType() == typeof(OverworldTile) || tile.GetType().BaseType == typeof(OverworldTile))
        {
            OverworldTile oTile = (OverworldTile)tile;
            if (!oTile.getPassable())
            {
                //maybe play that pokemon OOMPH sound when you walk into something

                yield break;
            }
        }
        Vector2 direction = (position - (Vector2)transform.position).normalized;

        //check if they are on a space with a mapObject
        OverworldObject[] overworldObjects = GameObject.FindObjectsOfType <OverworldObject>();
        foreach (OverworldObject oObject in overworldObjects)
        {
            if ((Vector2)transform.position + direction == (Vector2)oObject.transform.position)
            {
                //cant walk here

                yield break;
            }
        }

        isMoving = true;

        while (Vector2.Distance(transform.position, position) > 0.1f)
        {
            transform.position = (Vector2)transform.position + direction * 4f * Time.deltaTime;
            yield return(new WaitForEndOfFrame());
        }


        transform.position = position;
        isMoving           = false;

        yield break;
    }
Example #8
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.I))
        {
            ToggleInventory();
        }

        //Mining/destroying blocks
        if (Input.GetMouseButton(0))
        {
            Vector3 wP = mainCamera.ScreenToWorldPoint(Input.mousePosition);
            wP.z = 0;

            Vector3Int tilePos = new Vector3Int((int)Math.Floor(wP.x), (int)Math.Floor(wP.y), 0);

            DestructibleTile dTile;
            TileBase         tile = map.GetTile(tilePos);

            if (tile != null && tile.GetType() == typeof(DestructibleTile))
            {
                dTile = (DestructibleTile)tile;

                destroyTimer += Time.deltaTime * (mineSpeed - dTile.hardness);

                if (destroyTimer > 9)
                {
                    dTile.SpawnDrop(wP);
                    map.SetTile(tilePos, null);
                    destroyTimer = 0;
                }
                else
                {
                    if (destroySprite.transform.position == new Vector3(tilePos.x + 0.5f, tilePos.y + 0.5f, -0.5f))
                    {
                        destroySprite.GetComponent <SpriteRenderer>().sprite = destroySprites[(int)Math.Floor(destroyTimer)];
                    }
                    else
                    {
                        destroySprite.transform.position = new Vector3(tilePos.x + 0.5f, tilePos.y + 0.5f, -0.5f);
                        destroyTimer = 0f;
                        destroySprite.GetComponent <SpriteRenderer>().sprite = destroySprites[0];
                    }
                }
            }
            else
            {
                destroyTimer = 0f;
                destroySprite.GetComponent <SpriteRenderer>().sprite = destroySprites[0];
            }
        }
        else
        {
            destroyTimer = 0f;
            destroySprite.GetComponent <SpriteRenderer>().sprite = destroySprites[0];
        }
    }
Example #9
0
    public bool isWall(ITilemap tilemap, Vector3Int pos)
    {
        TileBase tile = tilemap.GetTile(pos);

        if (tile != null)
        {
            return(tile.GetType() == typeof(WallTile));
        }
        return(false);
    }
Example #10
0
        public void CreateDefaultTileWithSprite_HasDefaultTileProperties()
        {
            m_Tile = TileUtility.DefaultTile(m_Sprite);
            var tile = m_Tile as Tile;

            Assert.AreEqual(typeof(Tile), m_Tile.GetType());
            Assert.IsNotNull(tile);

            Assert.AreEqual(m_Sprite, tile.sprite);
            Assert.AreEqual(Color.white, tile.color);
        }
Example #11
0
    private bool TileValue(ITilemap tileMap, Vector3Int position)
    {
        TileBase tile = tileMap.GetTile(position);

        if (tile != null && tile == this)
        {
            return(true);
        }

        if (tile != null && tile.GetType() == typeof(_5x5Tile))
        {
            var _5x5tile = (_5x5Tile)tile;
            if (_5x5tile.height > height)
            {
                return(true);
            }
        }

        if (tile != null && tile.GetType() == typeof(CliffTile))
        {
            var cliffTile = (CliffTile)tile;
            if (cliffTile.height > height)
            {
                return(true);
            }
        }

        if (tile != null && tile.GetType() == typeof(Tile))
        {
            var tileTile = (Tile)tile;
            if (spriteSets.Any(x => x.patterns.Contains(tileTile.sprite)))
            {
                return(true);
            }
        }

        return(false);
    }
Example #12
0
    private BaseTileData GetBaseTileData(Vector3Int currentPosition)
    {
        ITilemap tilemap   = null;
        TileBase foundTile = m_baseTileMap.GetTile(currentPosition);

        if (foundTile.GetType() == typeof(PrefabTile))
        {
            PrefabTile tile = foundTile as PrefabTile;
            return(tile.GetBaseTileObject(currentPosition).GetComponent <BaseTileData>());
        }
        //foundTile.GetTileData(currentPosition, tilemap, ref m_activeTile);
        //return m_activeTile.gameObject.GetComponent<BaseTileData>();
        return(null);
    }
Example #13
0
        private bool CheckTileMapIsRoad(TileBase tile)
        {
            string titleFullName = tile.GetType().FullName;

            Debug.Log("检测道路》》》》》" + titleFullName + "------" + BaseTile + "-------" + RuleTile);
            if (titleFullName == BaseTile)
            {
                return(((Tile)tile).colliderType == Tile.ColliderType.None);
            }
            else if (titleFullName == RuleTile)
            {
                return(((RuleTile)tile).m_DefaultColliderType == Tile.ColliderType.None);
            }
            return(false);
        }
Example #14
0
    private bool CheckMine()
    {
        if (!activated)
        {
            Debug.Log("Not activated");
            return(false);
        }
        Debug.Log("Colliding");

        if (Vector2.Distance(Cursor.instance.transform.position, transform.position) > 1.75f)
        {
            Debug.Log("Too far away");
            return(false);
        }
        //Vector3Int tilePosition = GameManager.instance.grid.WorldToCell(collision.transform.position);

        Debug.Log("trying to destroy");

        Vector3Int location = GameManager.instance.wallMap.WorldToCell(Cursor.instance.transform.position);

        Debug.Log(location);
        TileBase tile = GameManager.instance.wallMap.GetTile(location);


        if (tile != null)
        {
            Debug.Log("Tile: " + tile.name);
            if (tile.name == "StoneWall")
            {
                GameManager.instance.wallMap.SetTile(location, null);
                return(true);
            }



            if (tile.GetType() == typeof(DropTile))
            {
                DropTile dropTile         = (DropTile)tile;
                Vector3  centeredLocation = new Vector2(location.x + 0.5f, location.y + 0.5f);
                Instantiate(dropTile.drop, centeredLocation, Quaternion.identity);
                GameManager.instance.wallMap.SetTile(location, null);
                return(true);
            }
        }

        return(false);
    }
Example #15
0
    private bool getTile(int x, int y, ref LevelTile tile)
    {
        TileBase baseTile = tileMap.GetTile(new Vector3Int((int)x, (int)y, 0));

        if (baseTile == null)
        {
            tile = null;
            return(false);
        }
        if (baseTile.GetType() != typeof(LevelTile))
        {
            tile = null;
            return(false);
        }
        tile = (LevelTile)baseTile;
        return(tile != null);
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Walls")
        {
            //Vector3Int tilePosition = GameManager.instance.grid.WorldToCell(collision.transform.position);

            Debug.Log("trying to destroy");

            Vector3Int location = GameManager.instance.wallMap.WorldToCell(collision.GetContact(0).point);
            TileBase   tile     = GameManager.instance.wallMap.GetTile(location);

            if (tile != null)
            {
                if (tile.name == "StoneWall")
                {
                    GameManager.instance.wallMap.SetTile(location, null);
                }



                if (tile.GetType() == typeof(DropTile))
                {
                    DropTile dropTile         = (DropTile)tile;
                    Vector3  centeredLocation = new Vector2(location.x + 0.5f, location.y + 0.5f);
                    Instantiate(dropTile.drop, centeredLocation, Quaternion.identity);
                    GameManager.instance.wallMap.SetTile(location, null);
                }
            }
        }

        if (collision.gameObject.tag == "Enemy")
        {
            collision.gameObject.GetComponent <Enemy>().Die();
            Destroy(collision.gameObject);
        }

        if (collision.gameObject.name != "Player")
        {
            Destroy(gameObject);
        }
    }
Example #17
0
    public static void SetSpriteByType(TileBase _tileBase, out Sprite _sprite)
    {
        TileUtils.TileType tileType = TileUtils.ParseTileTypeName(_tileBase.GetType().ToString());

        switch (tileType)
        {
        case TileUtils.TileType.RuleTile:
            RuleTile ruteTile = (RuleTile)_tileBase;
            _sprite = ruteTile.m_DefaultSprite;
            break;

        case TileUtils.TileType.Tile:
            Tile tile = (Tile)_tileBase;
            _sprite = tile.sprite;
            break;

        default:
            Debug.LogError("Tile type is null " + tileType);
            _sprite = null;
            break;
        }
    }
    private void InitPathfinding()
    {
        tilemap = GameObject.FindGameObjectWithTag(Tags.TILEMAP).GetComponent <Tilemap>();
        if (tilemap == null)
        {
            Debug.LogError("No game object found with tag 'TilemapObstacles'");
        }

        BoundsInt bounds = tilemap.cellBounds;

        TileBase[] allTiles = tilemap.GetTilesBlock(bounds);

        // Declare Pathfinding Array
        PathfindingMap = new PathNode[bounds.size.x, bounds.size.y];

        // Recover Wall Tiles
        for (int x = 0; x < bounds.size.x; x++)
        {
            for (int y = 0; y < bounds.size.y; y++)
            {
                TileBase tile = allTiles[x + y * bounds.size.x];

                if (tile != null && tile.GetType() == typeof(WorldTile))
                {
                    WorldTile wt = tile as WorldTile;

                    // Player can't walk in
                    PathfindingMap[x, y] = new PathNode(x, y, true);
                }
                else
                {
                    // Player can walk
                    PathfindingMap[x, y] = new PathNode(x, y, false);
                }
            }
        }

        aStar = new Pathfinder <PathNode, Character>(PathfindingMap);
    }
    public IEnumerator MoveParty(Vector3[] path)
    {
        if (path == null)
        {
            Vector3Int intPos = grid.WorldToCell(this.transform.position);
            currentTile = tilemap.GetTile(intPos);

            if (currentTile.GetType() == typeof(VariantTiles))
            {
                VariantTiles tile = currentTile as VariantTiles;

                Debug.Log("Event Tile");
                gameManager.ProceedToNextGamePhase();

                if (gameManager.currentGamePhase == GameManager.GamePhase.Event)
                {
                    if (currentTile.GetType() == typeof(VariantTiles))
                    {
                        VariantTiles currentEventTile = currentTile as VariantTiles;

                        switch (currentEventTile.variantType)
                        {
                        case VariantTiles.VariantType.Town:
                            shopManager.promptPanel.SetActive(true);
                            break;

                        case VariantTiles.VariantType.Enemy:
                            gameManager.ProceedToNextGamePhase(true);
                            break;
                        }
                    }
                }
            }
            else
            {
                gameManager.ProceedToNextGamePhase();
                gameManager.ProceedToNextGamePhase();
            }
        }
        else
        {
            heroParty[0].GetComponent <Animator>().SetBool("isWalking", true);

            for (int i = 0; i < path.Length; i++)
            {
                while (this.transform.position != path[i])
                {
                    float step = boardMovementSpeed * Time.deltaTime;

                    this.transform.position = Vector3.MoveTowards(this.transform.position, path[i], step);

                    yield return(new WaitForSeconds(step / 2));
                }

                yield return(new WaitForSeconds(Time.deltaTime));
            }

            heroParty[0].GetComponent <Animator>().SetBool("isWalking", false);

            this.transform.position = path[path.Length - 1];


            Vector3Int intPos = grid.WorldToCell(this.transform.position);
            currentTile = tilemap.GetTile(intPos);


            foreach (HeroClass hero in heroParty)
            {
                hero.XP += 1;

                if (hero.CanLevelUp())
                {
                    hero.LevelUp(hero.Level + 1);
                }
            }

            if (currentTile.GetType() == typeof(VariantTiles))
            {
                VariantTiles tile = currentTile as VariantTiles;

                Debug.Log("Event Tile");
                gameManager.ProceedToNextGamePhase();

                if (gameManager.currentGamePhase == GameManager.GamePhase.Event)
                {
                    if (currentTile.GetType() == typeof(VariantTiles))
                    {
                        VariantTiles currentEventTile = currentTile as VariantTiles;

                        switch (currentEventTile.variantType)
                        {
                        case VariantTiles.VariantType.Town:

                            foreach (HeroClass hero in heroParty)
                            {
                                hero.currentHealth = hero.Health;
                            }

                            shopManager.promptPanel.SetActive(true);
                            break;

                        case VariantTiles.VariantType.Enemy:
                        case VariantTiles.VariantType.Boss:
                            gameManager.ProceedToNextGamePhase(true);
                            break;
                        }
                    }
                }
            }
            else
            {
                gameManager.ProceedToNextGamePhase();
                gameManager.ProceedToNextGamePhase();
            }
        }
    }
Example #20
0
    private bool TileValue(ITilemap Tilemap, Vector3Int position)
    {
        TileBase tile = Tilemap.GetTile(position);

        return(tile != null && (tile.GetType() == this.GetType()));
    }
Example #21
0
    //meat and potatoes. this is where the tiles themselves are placed
    //the intMap is used to define the shape of the map
    void PopulateTileMaps()
    {
        int layerDepth = depth / layerCount;

        int currentLayer = 1;

        if (intMap != null)
        {
            float[] weights = generateWeights(fillTiles.list[0].list.Length);//generate inital weights
            for (int y = 0; y < depth + 21; y++)
            {
                if ((y / currentLayer) == layerDepth && currentLayer <= layerCount)//if at layer transition
                {
                    //Debug.Log(currentLayer);
                    currentLayer++;
                    weights = generateWeights(fillTiles.list[currentLayer - 1].list.Length);//regenerate weights for next layer
                }

                for (int x = 0; x < 16; x++)
                {
                    if (y < depth)
                    {
                        background.SetTile(new Vector3Int(x - (16 / 2), -y, 0), backGroundTile);
                        if (intMap[x, y] > 0)
                        {
                            if (y == 0)
                            {
                                stoneMap.SetTile(new Vector3Int(x - (16 / 2), 0, 0), topTile);
                            }
                            else if (y < depth - 1)
                            {
                                //iterate debug vars
                                cycles++;
                                tiles++;

                                //place tile
                                int tile = IsXYOnEdge(x, y) ? 0 : GetRandomWeightedIndex(weights);

                                TileBase currentTile = fillTiles.list[currentLayer - 1].list[tile];
                                TileBase initialTile = fillTiles.list[currentLayer - 1].list[0];
                                if (currentTile.GetType() == typeof(OreTile))
                                {
                                    oreMap.SetTile(new Vector3Int(x - (16 / 2), -y, 0), currentTile);
                                    if (tile > 0)
                                    {
                                        oreCount[currentLayer - 1]++;
                                    }
                                    stoneMap.SetTile(new Vector3Int(x - (16 / 2), -y, 0), initialTile);
                                }
                                else
                                {
                                    stoneMap.SetTile(new Vector3Int(x - (16 / 2), -y, 0), currentTile);
                                }
                            }
                            else
                            {
                                stoneMap.SetTile(new Vector3Int(x - (16 / 2), -y, 0), fillTiles.list[currentLayer].list[0]);
                            }
                        }
                    }
                    else
                    {
                        background.SetTile(new Vector3Int(x - (16 / 2), -y, 0), coreBackTile);
                    }
                }
            }

            Instantiate(endRoomPrefab, new Vector3(0, -depth, 0), Quaternion.identity);
        }
    }
Example #22
0
 public void CreateDefaultTile_IsATile()
 {
     m_Tile = TileUtility.CreateDefaultTile();
     Assert.AreEqual(typeof(Tile), m_Tile.GetType());
 }