예제 #1
0
    /// <summary>
    /// Posiciona e liga a bomba
    /// </summary>
    /// <param name="b"> Boneco que criou a bomba. </param>
    public void setup(Boneco b)
    {
        gc    = GridCalculator.Instance;
        owner = b;
        power = b.FirePower;
        transform.position = gc.centerPosition(b.transform.position);
        GetComponent <Renderer>().sortingOrder = Layer;
        state = Ticking;
        GetComponent <AudioSource>().clip = (AudioClip)Resources.Load(sfxPath + "PlaceBomb");
        GetComponent <AudioSource>().Play();
        tickCR = StartCoroutine(tick());

        // anim = GetComponent<Animator>();
    }
예제 #2
0
 /// <summary>
 /// Retorna a posição central da tile atual da bomba.
 /// </summary>
 public Vector2 curTileCenter()
 {
     return(gc.centerPosition(transform.position));
 }
예제 #3
0
    /// <summary>
    /// Prepara o tabuleiro. Posiciona os blocos destrutíveis no mapa e os jogadores.
    /// </summary>
    void setupBoard()
    {
        // Verifica se o mapa está corretamente posicionado
        Vector2 curPos = gc.centerPosition(new Vector2(0, 0));

        if (curPos != new Vector2(0, 0) || !gc.tileContent(new Vector2(-1, 0)).CompareTag("Border") ||
            !gc.tileContent(new Vector2(0, -1)).CompareTag("Border"))
        {
            Debug.Log("Deu ruim. Tabuleiro mal formado"); // PutaVida.exception
            return;
        }

        // Pegando tamanho da parte jogável do mapa
        do
        {
            GameObject content = gc.tileContent(curPos + Vector2.up);
            if (content != null && content.CompareTag("Border"))
            {
                break;
            }
            curPos += Vector2.up;
            ySize++;
        } while (ySize < 100); // Limite arbitrário pra impedir loop infinito :P

        do
        {
            GameObject content = gc.tileContent(curPos + Vector2.right);
            if (content != null && content.CompareTag("Border"))
            {
                break;
            }
            curPos += Vector2.right;
            xSize++;
        } while (xSize < 100);

        // População da boardInfo
        boardInfo = new TileInfo[xSize * ySize];
        for (int i = 0; i < xSize; i++)
        {
            for (int j = 0; j < ySize; j++)
            {
                boardInfo[index(i, j)] = new TileInfo(gc.centerPosition(new Vector2(i, j)));
                GameObject content = gc.tileContent(new Vector2(i, j));
                if (content != null)
                {
                    boardInfo[index(i, j)].Block = content.tag;
                }
            }
        }

        // Spawn dos jogadores
        boardInfo[index(0, ySize - 1)].Spawn = true;
        boardInfo[index(1, ySize - 1)].Spawn = true;
        boardInfo[index(0, ySize - 2)].Spawn = true;
        if (playersAmount == 2)
        {
            boardInfo[index(xSize - 1, 0)].Spawn = true;
            boardInfo[index(xSize - 2, 0)].Spawn = true;
            boardInfo[index(xSize - 1, 1)].Spawn = true;
        }

        Boneco player1 = Instantiate <Boneco>(Resources.Load <Boneco>("Prefabs/Boneco 1"));

        player1.transform.position = gc.centerPosition(new Vector2(0, ySize - 1)); // Ajusta o boneco pro centro da tile.
        player1.setup(sandboxMode);
        if (playersAmount == 2)
        {
            Boneco player2 = Instantiate <Boneco>(Resources.Load <Boneco>("Prefabs/Boneco 2"));
            player2.transform.position = gc.centerPosition(new Vector2(xSize - 1, 0)); // Ajusta o boneco pro centro da tile.
            player2.setup(sandboxMode);
        }

        // Criação dos blocos destrutíveis aleatórios e itens (WIP)
        // Atenção (14/06/2018): Tem que gerar os blocos em locais "igualmente" aleatórios e garantindo que exatamente 80 blocos serão criados.

        // Embaralho a array, ou os numeros correspondentes?
        // Aproveitar o futuro loop pra já setupar os itens
        if (!sandboxMode)
        {
            List <SoftBlock> rbs = new List <SoftBlock>();
            foreach (TileInfo t in boardInfo)
            {
                if (!t.Spawn && t.Block == "")
                {
                    if (UnityEngine.Random.Range(0, 100) < 70)
                    {
                        t.Block = "SoftBlock";
                        rbs.Add(Instantiate(Resources.Load <SoftBlock>("Prefabs/SoftBlock"), t.Center, Quaternion.identity));
                    }
                }
            }
            randomizeItems(rbs);
        }
    }