public PathfinderTile(Tile.TILE_TYPE tileType, int[] pos)
 {
     this.tileType = tileType;
     x             = pos [0];
     y             = pos [1];
     z             = pos [2];
 }
Beispiel #2
0
 public GameObject FetchBlueprint(Tile.TILE_TYPE type)
 {
     if (type == Tile.TILE_TYPE.TILE_EMPTY)
     {
         return(null);
     }
     return(tileBlueprints[(int)type]);
 }
Beispiel #3
0
    public bool AddTile(Vector3 mousePos, GameObject blueprint)
    {
        MultiLayerTile multiTile = FetchTile(mousePos);
        Vector2        tileIndex = FetchTileIndex(mousePos);

        if (multiTile != null && multiTile.IsWalkable())
        {
            // Check if same tile exists
            foreach (GameObject tempGO in multiTile.multiLayerTile)
            {
                if (tempGO.GetComponent <Tile>().Type == blueprint.GetComponent <Tile>().Type)
                {
                    return(false);
                }
            }

            float scaleRatio = blueprint.GetComponent <Tile>().ScaleRatio;
            List <MultiLayerTile> tempList = new List <MultiLayerTile>();

            // Set other tiles walkable to false if scale ratio bigger than 0
            for (int row = (int)tileIndex.x; row < tileIndex.x + scaleRatio; ++row)
            {
                for (int col = (int)tileIndex.y; col < tileIndex.y + scaleRatio; ++col)
                {
                    MultiLayerTile tile = FetchTile(row, col);
                    if (tile != null && tile.IsWalkable())
                    {
                        tile.Walkable = blueprint.GetComponent <Tile>().IsWalkable();
                        tempList.Add(tile);
                    }
                    else
                    {
                        foreach (MultiLayerTile t in tempList)
                        {
                            t.Walkable = t.CalculateWalkable();
                        }
                        return(false);
                    }
                }
            }

            // Adding the tile
            //GameObject newTile = Instantiate(blueprint);
            Tile.TILE_TYPE type    = blueprint.GetComponent <Tile>().Type;
            Vector3        pos     = generateStartPos(RowCount, ColCount, (int)tileIndex.x, (int)tileIndex.y);// + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            Vector3        size    = new Vector3(tileSize, tileSize);
            GameObject     newTile = createTile(type, pos, size);

            /*newTile.transform.position = pos + ;
             * newTile.transform.localScale = size;
             * newTile.transform.parent = transform;*/
            tiles.Add(newTile.GetComponent <Tile>());
            multiTile.AddFront(newTile);
            return(true);
        }
        return(false);
    }
Beispiel #4
0
    protected virtual GameObject createTile(Tile.TILE_TYPE type, Vector3 pos, Vector3 size)
    {
        if (type == Tile.TILE_TYPE.TILE_EMPTY)
        {
            return(null);
        }
        if (!tileBlueprints[(int)type] && type != Tile.TILE_TYPE.TILE_FIRST_PLAYER && type != Tile.TILE_TYPE.TILE_SECOND_PLAYER && type != Tile.TILE_TYPE.TILE_ENEMY && type != Tile.TILE_TYPE.TILE_WAYPOINT)
        {
            return(null);
        }

        GameObject tile = null;

        switch (type)
        {
        default:
        {
            tile = Instantiate(tileBlueprints[(int)type]);

            if (tile.GetComponent <Item>() != null || type == Tile.TILE_TYPE.TILE_SPIKE_TRAP || type == Tile.TILE_TYPE.TILE_CANNON)
            {
                pos.z -= 1;
                tile.SetActive(true);
            }
            else if (type == Tile.TILE_TYPE.TILE_FIRST_PLAYER || type == Tile.TILE_TYPE.TILE_SECOND_PLAYER)
            {
                pos.z = 0;
                tile.SetActive(true);
            }
            else
            {
                tile.SetActive(true);
            }

            // Set data for each tile
            float scaleRatio = tile.GetComponent <Tile>().ScaleRatio;
            pos  += new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            size += new Vector3((scaleRatio - 1) * tileSize, (scaleRatio - 1) * tileSize);
            tile.transform.position   = pos;
            tile.transform.localScale = size;
            tile.transform.parent     = this.transform;
        }
        break;
        }
        return(tile);
    }
    private Tile AddTile(GameObject prefab, int[] indexPos, Tile.TILE_TYPE tileType)
    {
        finder.AddTile(tileType, indexPos);

        Vector3 position = new Vector3
                               (indexPos[0] * Tile.BLOCK_SIZE[0], indexPos[1] * Tile.BLOCK_SIZE[1], indexPos[2] + Tile.BLOCK_SIZE[2]);

        if (getTileAtIndex(indexPos) != null)
        {
            return(null);
        }
        GameObject tileObject = (GameObject)Instantiate(prefab, position, Quaternion.identity);
        Tile       aTile      = tileObject.GetComponent(typeof(Tile)) as Tile;

        aTile.setType(tileType);
        aTile.IndexPos   = indexPos;
        aTile.Controller = this;
        tileList.Add(aTile);

        return(aTile);
    }
Beispiel #6
0
    protected override GameObject createTile(Tile.TILE_TYPE type, Vector3 pos, Vector3 size)
    {
        if (type == Tile.TILE_TYPE.TILE_EMPTY || type >= Tile.TILE_TYPE.NUM_TILE)
        {
            return(null);
        }
        if (!tileBlueprints[(int)type])
        {
            return(null);
        }

        GameObject      tile               = null;
        float           scaleRatio         = tileBlueprints[(int)type].GetComponent <Tile>().ScaleRatio;
        WaypointManager refWaypointManager = this.transform.root.gameObject.GetComponentInChildren <WaypointManager>();
        EnemyManager    enemyManager       = RefEnemyManager.GetComponent <EnemyManager>();

        switch (type)
        {
        // TODO: Add special case for tile creation like enemy
        case Tile.TILE_TYPE.TILE_ENEMY:
        {
            // Create enemy
            GameObject enemy = RefEnemyManager.Fetch();
            if (enemy)
            {
                // Set enemy data
                Vector3 enemyPos = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
                enemyPos.z = 1.0f;
                Vector3 enemySize = size * scaleRatio;
                enemy.SetActive(true);

                // Get a handle to the Enemy component
                var enemyComponent = enemy.GetComponent <Enemy.Enemy>();
                if (enemyComponent)
                {
                    enemyComponent.Init(enemyPos, refWaypointManager, playerList, enemyManager);
                }
                enemy.transform.localScale = enemySize;
            }
        }
        break;

        case Tile.TILE_TYPE.TILE_WAYPOINT:
        {
            if (refWaypointManager)
            {
                // Create waypoint
                GameObject waypoint    = Instantiate(tileBlueprints[(int)type]);
                Vector3    waypointPos = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
                waypointPos.z = 1.5f;
                Vector3 waypointSize = size * scaleRatio;
                waypoint.transform.position   = waypointPos;
                waypoint.transform.localScale = waypointSize;
                refWaypointManager.Add(waypoint.GetComponent <Waypoint>());
            }
        }
        break;

        case Tile.TILE_TYPE.TILE_FIRST_PLAYER:
        {
            Vector3 playerPos  = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            Vector3 playerSize = size * scaleRatio;
            playerPos.z = 0.0f;
            RefPlayer1.transform.position   = playerPos;
            RefPlayer1.transform.localScale = playerSize;
        }
        break;

        case Tile.TILE_TYPE.TILE_SECOND_PLAYER:
        {
            Vector3 playerPos  = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            Vector3 playerSize = size * scaleRatio;
            playerPos.z = 0.0f;
            RefPlayer2.transform.position   = playerPos;
            RefPlayer2.transform.localScale = playerSize;
        }
        break;

        case Tile.TILE_TYPE.TILE_COIN:
        {
            tile = Instantiate(tileBlueprints[(int)type]);

            if (tile.GetComponent <Item>() != null || type == Tile.TILE_TYPE.TILE_SPIKE_TRAP || type == Tile.TILE_TYPE.TILE_CANNON)
            {
                pos.z -= 1;
                tile.SetActive(true);
            }
            else
            {
                tile.SetActive(true);
            }

            // Set data for each tile
            tile.transform.position            = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            tile.transform.localScale          = size * scaleRatio;
            tile.transform.parent              = this.transform;
            tile.GetComponent <Coin>().Manager = transform.root.gameObject.GetComponent <GameManager>();
        }
        break;

        case Tile.TILE_TYPE.TILE_EXIT:
        {
            tile = Instantiate(tileBlueprints[(int)type]);

            if (tile.GetComponent <Item>() != null || type == Tile.TILE_TYPE.TILE_SPIKE_TRAP || type == Tile.TILE_TYPE.TILE_CANNON)
            {
                pos.z -= 1;
                tile.SetActive(true);
            }
            else
            {
                tile.SetActive(true);
            }

            // Set data for each tile
            tile.transform.position            = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            tile.transform.localScale          = size * scaleRatio;
            tile.transform.parent              = this.transform;
            tile.GetComponent <Exit>().Manager = transform.root.gameObject.GetComponent <GameManager>();
        }
        break;

        default:
        {
            tile = Instantiate(tileBlueprints[(int)type]);

            if (tile.GetComponent <Item>() != null || type == Tile.TILE_TYPE.TILE_SPIKE_TRAP || type == Tile.TILE_TYPE.TILE_CANNON)
            {
                pos.z -= 1;
                tile.SetActive(true);
            }
            else
            {
                tile.SetActive(true);
            }

            // Set data for each tile
            tile.transform.position   = pos + new Vector3((scaleRatio - 1) * tileSize * 0.5f, -((scaleRatio - 1) * tileSize * 0.5f));
            tile.transform.localScale = size * scaleRatio;
            tile.transform.parent     = this.transform;
        }
        break;
        }
        return(tile);
    }
Beispiel #7
0
 public void AddTile(Tile.TILE_TYPE tileType, int[] pos)
 {
     map [pos [0], pos [1], pos [2]] = new PathfinderTile(tileType, pos);
 }