Beispiel #1
0
    public override void Spread()
    {
        Queue <Vector2Int> openSet   = new Queue <Vector2Int>();
        List <Vector2Int>  closedSet = new List <Vector2Int>();

        openSet.Enqueue(gridPos);

        Direction  wireDirection;
        Vector2Int currPos;

        while (openSet.Count > 0)
        {
            currPos       = openSet.Dequeue();
            wireDirection = SlotGrid.GetWireDirection(currPos.x, currPos.y);
            closedSet.Add(currPos);

            foreach (Vector2Int position in GetConnectedSlotPositions(currPos, wireDirection))
            {
                if (!closedSet.Contains(position))
                {
                    openSet.Enqueue(position);
                }
            }
        }

        foreach (Vector2Int position in closedSet)
        {
            EnergyTrail newTrail = new EnergyTrail(position, energyType, Direction.None, this);
            trails.Add(newTrail);
        }

        SlotGrid.AddEnergyTrails(trails);
    }
Beispiel #2
0
    public override void Spread()
    {
        int moveX = 0;
        int moveY = 0;

        if (spreadDirection == Direction.Right)
        {
            moveX = 1;
        }
        else if (spreadDirection == Direction.Left)
        {
            moveX = -1;
        }
        else if (spreadDirection == Direction.Down)
        {
            moveY = 1;
        }
        else if (spreadDirection == Direction.Up)
        {
            moveY = -1;
        }

        Vector2Int trailPos = new Vector2Int(gridPos.x, gridPos.y);

        do
        {
            trailPos.x += moveX;
            trailPos.y += moveY;

            EnergyTrail trail = new EnergyTrail(trailPos, EnType.Laser, spreadDirection, this);
            trails.Add(trail);
        } while (!SlotGrid.IsSlotOccupied(trailPos.x, trailPos.y));

        SlotGrid.AddEnergyTrails(trails);
    }
 private void Awake()
 {
     if (instance != null)
     {
         Debug.LogWarning("More than one instance of the infentory found");
     }
     instance = this;
 }
Beispiel #4
0
 public void SetInventoryItem(Item _item, Transform _parent)
 {
     ContainingItem = _item;
     slotGrid       = SlotGrid.instance;
     slotSize       = slotGrid.SlotWidthAndHeight;
     transform.SetParent(_parent);
     ScaleInventoryItem(_item);
     itemIcon.sprite = _item.ItemIcon;
 }
Beispiel #5
0
    public void MoveStartPos()
    {
        Vector2Int newGridPosStart = gridPosStart + movement;

        if (!SlotGrid.IsSlotOccupied(newGridPosStart.x, newGridPosStart.y))
        {
            EnergyTrail trail = new EnergyTrail(newGridPosStart, creator.energyType, CalculateDirection(gridPosStart, newGridPosStart), creator);
            path.Enqueue(trail);
            SlotGrid.AddEnergyTrail(trail);
            gridPosStart.Set(newGridPosStart.x, newGridPosStart.y);
        }
    }
Beispiel #6
0
    public void MoveEndPos(ref bool vanished)
    {
        Vector2Int newGridPosEnd = gridPosEnd + movement;

        EnergyTrail s = path.Dequeue();

        SlotGrid.RemoveEnergyTrail(s);

        if (gridPosStart == newGridPosEnd)
        {
            vanished = true;
            return;
        }

        gridPosEnd = newGridPosEnd;
    }
    void ReiniciarProcura()
    {
        PrimeiraProcura = false;
        List <GameObject> ListPonto = new List <GameObject>();

        // Nao chegou no destino
        foreach (GameObject SlotGrid in ArrayGrid)
        {
            if (SlotGrid.GetComponent <SlotGrid>().Custo == 49)
            {
                ListPonto.Add(SlotGrid.gameObject);
            }
        }
        int indice = 0;

        Valores_ASTAR(ListPonto[indice].gameObject.GetComponent <SlotGrid>().pos_x, ListPonto[indice].gameObject.GetComponent <SlotGrid>().pos_y, ListPonto[indice].gameObject.GetComponent <SlotGrid>().Custo, ListPonto[indice].gameObject.GetComponent <SlotGrid>().Custo + 50);
    }
Beispiel #8
0
    public override void Spread()
    {
        List <EnergyTrail> trails = new List <EnergyTrail>();

        int xPos, yPos;

        for (int i = -power; i <= power; i++)
        {
            for (int j = -power; j <= power; j++)
            {
                xPos = gridPos.x + i;
                yPos = gridPos.y + j;
                if (SlotGrid.PositionInsideGrid(xPos, yPos))
                {
                    EnergyTrail trail = new EnergyTrail(new Vector2Int(xPos, yPos), EnType.Heat, Direction.None, this);
                    this.trails.Add(trail);
                    trails.Add(trail);
                }
            }
        }

        SlotGrid.AddEnergyTrails(trails);
    }
    void Valores_ASTAR(int Slotx, int Sloty, int IncioIndex, int limiteindex)
    {
        Chegou    = false;
        MenorDist = -1;
        ListaSquare.Clear();

        foreach (GameObject SlotGrid in ArrayGrid)
        {
            if (PrimeiraProcura)
            {
                SlotGrid.gameObject.GetComponent <SlotGrid>().Custo = -1;
                SlotGrid.gameObject.GetComponent <SlotGrid>().Alvo  = false;
            }
            SlotGrid.gameObject.GetComponent <SlotGrid>().Marcado = 0;
        }


        //Custo do local final =0
        hit.collider.gameObject.GetComponent <SlotGrid>().Alvo = true;

        for (int index = IncioIndex; index < limiteindex; index++)
        {
            //Diagonais

            /*
             * if(!ArrayGrid[Slotx+1,Sloty+1].gameObject.GetComponent<SlotGrid>().Alvo && ArrayGrid[Slotx+1,Sloty+1].gameObject.GetComponent<SlotGrid>().Custo!=100){
             *  ArrayGrid[Slotx+1,Sloty+1].gameObject.GetComponent<SlotGrid>().Custo = index;
             *  ArrayGrid[Slotx+1,Sloty+1].gameObject.GetComponent<SpriteRenderer>().color = Color.red;
             *  Dist1 = ArrayGrid[Slotx+1,Sloty+1].gameObject.GetComponent<SlotGrid>().DistanciaJogador;
             * }
             *
             * if(!ArrayGrid[Slotx-1,Sloty+1].gameObject.GetComponent<SlotGrid>().Alvo && ArrayGrid[Slotx-1,Sloty+1].gameObject.GetComponent<SlotGrid>().Custo!=100){
             *  ArrayGrid[Slotx-1,Sloty+1].gameObject.GetComponent<SlotGrid>().Custo = index;
             *  ArrayGrid[Slotx-1,Sloty+1].gameObject.GetComponent<SpriteRenderer>().color = Color.red;
             *  Dist2 = ArrayGrid[Slotx-1,Sloty+1].gameObject.GetComponent<SlotGrid>().DistanciaJogador;
             * }
             *
             * if(!ArrayGrid[Slotx-1,Sloty-1].gameObject.GetComponent<SlotGrid>().Alvo && ArrayGrid[Slotx-1,Sloty-1].gameObject.GetComponent<SlotGrid>().Custo !=100){
             *  ArrayGrid[Slotx-1,Sloty-1].gameObject.GetComponent<SlotGrid>().Custo = index;
             *  ArrayGrid[Slotx-1,Sloty-1].gameObject.GetComponent<SpriteRenderer>().color = Color.red;
             *  Dist3 = ArrayGrid[Slotx-1,Sloty-1].gameObject.GetComponent<SlotGrid>().DistanciaJogador;
             * }
             *
             * if(!ArrayGrid[Slotx+1,Sloty-1].gameObject.GetComponent<SlotGrid>().Alvo && ArrayGrid[Slotx+1,Sloty-1].gameObject.GetComponent<SlotGrid>().Custo!=100){
             *  ArrayGrid[Slotx+1,Sloty-1].gameObject.GetComponent<SlotGrid>().Custo = index;
             *  ArrayGrid[Slotx+1,Sloty-1].gameObject.GetComponent<SpriteRenderer>().color = Color.red;
             *  Dist4 = ArrayGrid[Slotx+1,Sloty-1].gameObject.GetComponent<SlotGrid>().DistanciaJogador;
             * }
             */

            //HORTOGONAIS
            if (Sloty - 1 != ProfundidadeGrid)
            {
                if (!ArrayGrid[Slotx, Sloty + 1].gameObject.GetComponent <SlotGrid>().Alvo&& ArrayGrid[Slotx, Sloty + 1].gameObject.GetComponent <SlotGrid>().Custo != 100)
                {
                    ArrayGrid[Slotx, Sloty + 1].gameObject.GetComponent <SlotGrid>().Custo       = index;
                    ArrayGrid[Slotx, Sloty + 1].gameObject.GetComponent <SpriteRenderer>().color = Color.red;
                    ArrayGrid[Slotx, Sloty + 1].gameObject.GetComponent <SlotGrid>().Marcado    += 1;
                    Dist5 = ArrayGrid[Slotx, Sloty + 1].gameObject.GetComponent <SlotGrid>().DistanciaJogador;
                }
            }


            if (Sloty != 0)
            {
                if (!ArrayGrid[Slotx, Sloty - 1].gameObject.GetComponent <SlotGrid>().Alvo&& ArrayGrid[Slotx, Sloty - 1].gameObject.GetComponent <SlotGrid>().Custo != 100)
                {
                    ArrayGrid[Slotx, Sloty - 1].gameObject.GetComponent <SlotGrid>().Custo       = index;
                    ArrayGrid[Slotx, Sloty - 1].gameObject.GetComponent <SpriteRenderer>().color = Color.red;
                    ArrayGrid[Slotx, Sloty - 1].gameObject.GetComponent <SlotGrid>().Marcado    += 1;
                    Dist6 = ArrayGrid[Slotx, Sloty - 1].gameObject.GetComponent <SlotGrid>().DistanciaJogador;
                }
            }

            if (Slotx != 0)
            {
                if (!ArrayGrid[Slotx - 1, Sloty].gameObject.GetComponent <SlotGrid>().Alvo&& ArrayGrid[Slotx - 1, Sloty].gameObject.GetComponent <SlotGrid>().Custo != 100)
                {
                    ArrayGrid[Slotx - 1, Sloty].gameObject.GetComponent <SlotGrid>().Custo       = index;
                    ArrayGrid[Slotx - 1, Sloty].gameObject.GetComponent <SpriteRenderer>().color = Color.red;
                    ArrayGrid[Slotx - 1, Sloty].gameObject.GetComponent <SlotGrid>().Marcado    += 1;
                    Dist7 = ArrayGrid[Slotx - 1, Sloty].gameObject.GetComponent <SlotGrid>().DistanciaJogador;
                }
            }

            if (Slotx - 1 != LarguraGrid)
            {
                if (!ArrayGrid[Slotx + 1, Sloty].gameObject.GetComponent <SlotGrid>().Alvo&& ArrayGrid[Slotx + 1, Sloty].gameObject.GetComponent <SlotGrid>().Custo != 100)
                {
                    ArrayGrid[Slotx + 1, Sloty].gameObject.GetComponent <SlotGrid>().Custo       = index;
                    ArrayGrid[Slotx + 1, Sloty].gameObject.GetComponent <SpriteRenderer>().color = Color.red;
                    ArrayGrid[Slotx + 1, Sloty].gameObject.GetComponent <SlotGrid>().Marcado    += 1;
                    Dist8 = ArrayGrid[Slotx + 1, Sloty].gameObject.GetComponent <SlotGrid>().DistanciaJogador;
                }
            }


            foreach (GameObject SlotGrid in ArrayGrid)
            {
                if (
                    !SlotGrid.GetComponent <SlotGrid>().Cheio&&
                    SlotGrid.GetComponent <SlotGrid>().Custo == index &&
                    SlotGrid.GetComponent <SlotGrid>().Custo != 100 &&
                    SlotGrid.GetComponent <SlotGrid>().Marcado == 1 &&
                    !SlotGrid.GetComponent <SlotGrid>().Alvo
                    )
                {
                    ListaSquare.Add(SlotGrid.GetComponent <SlotGrid>().DistanciaJogador);
                }
            }

            if (ListaSquare.Count == 4)
            {
                MenorDist = Mathf.Min(ListaSquare[0], ListaSquare[1], ListaSquare[2], ListaSquare[3]);
            }
            else if (ListaSquare.Count == 3)
            {
                MenorDist = Mathf.Min(ListaSquare[0], ListaSquare[1], ListaSquare[2]);
            }
            else if (ListaSquare.Count == 2)
            {
                MenorDist = Mathf.Min(ListaSquare[0], ListaSquare[1]);
            }
            else if (ListaSquare.Count == 1)
            {
                MenorDist = ListaSquare[0];
            }

            foreach (GameObject SlotGrid in ArrayGrid)
            {
                if (SlotGrid.GetComponent <SlotGrid>().DistanciaJogador == MenorDist &&
                    SlotGrid.GetComponent <SlotGrid>().Custo == index &&
                    SlotGrid.GetComponent <SlotGrid>().Custo != 100 &&
                    !SlotGrid.GetComponent <SlotGrid>().Cheio&&
                    SlotGrid.GetComponent <SlotGrid>().Marcado == 1 &&
                    !SlotGrid.GetComponent <SlotGrid>().Alvo)
                {
                    Slotx = SlotGrid.GetComponent <SlotGrid>().pos_x;
                    Sloty = SlotGrid.GetComponent <SlotGrid>().pos_y;
                    //ListaCaminho.Add(SlotGrid.gameObject);
                    //break;
                }
            }
            ListaSquare.Clear();
            indexAtual = index;
        }

        foreach (GameObject SlotGrid in ArrayGrid)
        {
            if (SlotGrid.gameObject.GetComponent <SlotGrid>().OcupadoJogador&& SlotGrid.gameObject.GetComponent <SlotGrid>().Marcado > 0)
            {
                Chegou          = true;
                PrimeiraProcura = true;
            }
        }

        if (!Chegou)
        {
            ReiniciarProcura();
        }
    }
Beispiel #10
0
 private void Start()
 {
     slotGrid = SlotGrid.instance;
 }
Beispiel #11
0
 private void Start()
 {
     slotGrid        = SlotGrid.instance;
     slotGridManager = SlotGridStorageManager.instance;
     MaxSpace        = slotGrid.AmountOfSlots.x * slotGrid.AmountOfSlots.y;
 }
Beispiel #12
0
 private void Awake()
 {
     CreateGrid();
     instance = this;
 }
Beispiel #13
0
    public virtual void StopSpreading()
    {
        SlotGrid.RemoveEnergyTrails(trails);

        trails.Clear();
    }
Beispiel #14
0
 public void BindData()
 {
     _presenter.OnViewLoaded();
     SlotGrid.DataBind();
 }