Exemplo n.º 1
0
    public void PlaceCells(float w, float h)
    {
        SpriteRenderer srbg = this.CellPrefab.transform.Find("Background").GetComponent <SpriteRenderer>();        // Grab background sprite size as cell size
        //Debug.Log(string.Format("STARTED GRID w:{0}, h:{1}", w, h));
        int fitx = (int)(w / (srbg.size.x));
        int fity = (int)(h / (srbg.size.y));

        cells      = new Cell2D[fitx, fity];
        this.sizex = fitx;
        this.sizey = fity;
        float   offsetx = w / fitx;
        float   offsety = h / fity;
        Vector3 start   = this.transform.position + new Vector3(offsetx / 2.0f - w / 2.0f, offsety / 2.0f - h / 2.0f, 0.0f);
        //Debug.Log(string.Format("We can fit x {0}, y {1}", fitx, fity));
        //Debug.Log(string.Format("offset x: {0}, y: {1}", offsetx, offsety));
        //Debug.Log(string.Format("Start pos: {0}", start));
        int count = 0;

        for (int x = 0; x < fitx; x++)
        {
            for (int y = 0; y < fity; y++)
            {
                count++;
                Vector3    spot     = start + new Vector3(offsetx * x, offsety * y, -0.01f);
                GameObject c        = Instantiate(this.CellPrefab, spot, Quaternion.identity, this.transform);
                Cell2D     tempCell = c.GetComponent <Cell2D>();
                tempCell.coords     = new Vector2(x, y);
                this.cells[x, y]    = tempCell;
                tempCell.parentGrid = this;
                //Debug.Log(string.Format("Spawned {0} at {1}", count, spot));
                //n.transform.parent = this.transform;
            }
        }
    }
Exemplo n.º 2
0
    public override IEnumerator IEResolve()
    {
        Debug.Log("Starting Flight's IEResolve");
        running = true;
        ActionReq  a    = actions[0];
        GameGrid2D gg   = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid;                                                      // Select grid to get coord's
        Cell2D     cell = gg.GetCell(a.loc[0]);
        CellStruct cs   = a.t == pb.pobj.playerId ? pGrid[(int)a.loc[0].x, (int)a.loc[0].y] : eGrid[(int)a.loc[0].x, (int)a.loc[0].y]; //TODO change this garbage
        float      time = 0;

        while (time <= delay) //Delay first
        {
            time += Time.deltaTime;
            yield return(null);
        }
        time = 0; //Delay artificially for a bit;
        cell.OnBuild();
        cell.SetCellStruct(cs);
        while (time <= buildDelay)
        {
            time += Time.deltaTime;
            yield return(null);
        }
        running = false;
        Destroy(gameObject);
    }
Exemplo n.º 3
0
 protected override void Start()
 {
     thisCell             = gameObject.GetComponent <Cell2D>();
     thisCell.data.TypeID = new int[GridController3D.gridController3D.Cell3DPrefab.GetComponent <Cell3D>().CellPsTypes.Count];
     for (int i = 0; i < thisCell.data.TypeID.Length; i++)
     {
         thisCell.data.TypeID[i] = 0;
     }
     m_image = GetComponent <Image>();
 }
Exemplo n.º 4
0
 protected override void Start()
 {
     thisCell      = gameObject.AddComponent <Cell2D>();
     thisCell.data = new CellData
     {
         AnchoredPosition = gameObject.GetComponent <RectTransform>().anchoredPosition,
         X = X,
         Y = Y
     };
     thisCell.enabled = false;
     m_image          = GetComponent <Image>();
 }
Exemplo n.º 5
0
    public override void Init(List <ActionReq> actions, PlayBoard2D pb, CellStruct[,] pGrid, CellStruct[,] eGrid)
    {
        base.argInit(actions, pb, pGrid, eGrid);
        projectile     = GetComponent <SpriteRenderer>();
        orig_z         = transform.position.z;
        orig_scale     = transform.localScale;
        hitParticle    = transform.Find("HitParticle").GetComponent <ParticleSystem>();
        trailParticle  = GetComponent <ParticleSystem>();
        rock           = transform.Find("Rock").gameObject;
        rockSpriteRend = rock.GetComponent <SpriteRenderer>();
        ActionReq  a    = actions[0];
        GameGrid2D gg   = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid; // Select grid to get coord's
        Cell2D     cell = gg.GetCell(a.loc[0]);

        this.startpos           = a.p == pb.pobj.playerId ? pb.playerShotOrig : pb.enemyShotOrig;
        this.transform.position = startpos;
        this.endpos             = cell.transform.position;
    }
Exemplo n.º 6
0
    public override IEnumerator IEResolve()
    {
        running = true;
        Debug.Log("Starting Flight's IEResolve");
        float time = 0;

        //Delay first
        while (time <= delay)
        {
            time += Time.deltaTime;
            yield return(null);
        }
        time = 0; // Now launch
        trailParticle.Play(false);
        while (time <= duration)
        {
            float interpolant = time / duration;
            //Set new scale
            float   scale    = Mathf.Lerp(scaleMin, scaleMax, curve.Evaluate(interpolant));
            Vector3 newscale = new Vector3(orig_scale.x * scale, orig_scale.y * scale, orig_scale.z); // Scale object up and down based on curve, multipled by height scalar
            transform.localScale = newscale;
            //Set new position
            Vector3 newpos = Vector3.Lerp(startpos, endpos, interpolant);
            newpos.z           = orig_z;
            transform.position = newpos;
            //Update rotation
            rock.transform.Rotate(new Vector3(0, 0, rotation * Time.deltaTime));
            //Update time and yield
            time += Time.deltaTime;
            yield return(null);
        }
        Debug.Log("Projectile has landed");
        //the projectile has landed, play sound, update cell, etc.
        ActionReq  a    = actions[0];
        GameGrid2D gg   = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid;                                                      // Select grid to get coord's
        Cell2D     cell = gg.GetCell(a.loc[0]);
        CellStruct cs   = a.t == pb.pobj.playerId ? pGrid[(int)a.loc[0].x, (int)a.loc[0].y] : eGrid[(int)a.loc[0].x, (int)a.loc[0].y]; //TODO change this garbage

        cell.OnHit();
        cell.SetCellStruct(cs);
        running = false; // Say we're done running when we hit the end location
        StartCoroutine(IEFade());
    }
Exemplo n.º 7
0
 public void Load2DGrid()
 {
     if (GameplayGridData.Cells != null)
     {
         for (int i = 0; i < GameplayGridData.Cells.Length; i++)
         {
             for (int j = 0; j < GameplayGridData.Cells[i].Length; j++)
             {
                 GameObject    tempCell          = Instantiate(Cell2DPrefab, MapSpace);
                 RectTransform tempCellTransform = tempCell.GetComponent <RectTransform>();
                 tempCell.SetActive(true);
                 tempCellTransform.sizeDelta        = new Vector2(XMod2D, YMod2D);
                 tempCellTransform.anchoredPosition = GameplayGridData.Cells[i][j].AnchoredPosition;
                 Cell2D cellvalue = tempCell.AddComponent <Cell2D>();
                 cellvalue.data = GameplayGridData.Cells[i][j];
                 Load3DGrid(GameplayGridData.Cells[i][j], tempCellTransform.anchoredPosition.x / XMod2D, tempCellTransform.anchoredPosition.y / YMod2D);
             }
         }
     }
 }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetAxis(XButton) > 0)
        {
            GameObject newLinerendererObj = GameObject.Instantiate(LinerendPrefab, Vector3.zero, Quaternion.identity);
            lineRenderer = newLinerendererObj.GetComponent <LineRenderer>();
            lineRenderer.positionCount = 0;
        }
        if (Input.GetAxis(RTrigger) > 0 && (Input.GetAxis(Vertical) != 0 || Input.GetAxis(Horizontal) != 0))
        {
            currentX += Input.GetAxis(Horizontal);
            if (currentX > grid.GridDim_X)
            {
                currentX = grid.GridDim_X;
            }
            else if (currentX < 0)
            {
                currentX = 0;
            }

            currentY += Input.GetAxis(Vertical);
            if (currentY > grid.GridDim_Y)
            {
                currentY = grid.GridDim_Y;
            }
            else if (currentY < 0)
            {
                currentY = 0;
            }

            Cell2D  currentCell = grid.ReturnCell((int)currentX, (int)currentY);
            Vector3 CellPos     = currentCell.data.AnchoredPosition;
            if (prevCellPos != CellPos)
            {
                lineRenderer.positionCount++;
                lineRenderer.SetPosition(lineRenderer.positionCount - 1, CellPos);
                prevCellPos = CellPos;
            }
        }
    }
Exemplo n.º 9
0
 public void LoadGrid()
 {
     if (GridController3D.gridController3D.GameplayGridData.Cells != null)
     {
         for (int i = 0; i < GridController3D.gridController3D.GameplayGridData.Cells.Length; i++)
         {
             for (int j = 0; j < GridController3D.gridController3D.GameplayGridData.Cells[i].Length; j++)
             {
                 GameObject    tempCell          = Instantiate(Cell2DPrefab, MapSpace);
                 RectTransform tempCellTransform = tempCell.GetComponent <RectTransform>();
                 tempCell.SetActive(true);
                 tempCellTransform.sizeDelta        = new Vector2(XMod, YMod);
                 tempCellTransform.anchoredPosition = GridController3D.gridController3D.GameplayGridData.Cells[i][j].AnchoredPosition;
                 Cell2D cellvalue = tempCell.AddComponent <Cell2D>();
                 cellvalue.data = GridController3D.gridController3D.GameplayGridData.Cells[i][j];
                 TypeSelectorCell2D typeSelector = tempCell.AddComponent <TypeSelectorCell2D>();
                 typeSelector.gridController = this;
                 GridController3D.gridController3D.LoadGrid(GridController3D.gridController3D.GameplayGridData.Cells[i][j], tempCellTransform.anchoredPosition.x / XMod, tempCellTransform.anchoredPosition.y / YMod);
             }
         }
     }
     GridController3D.gridController3D.JustLoaded = true;
 }
Exemplo n.º 10
0
        /// <summary>
        /// "пересобрать ячейки"
        /// </summary>
        void RebuildCells()
        {
            if (CellNet != null)
            {
                foreach (var cell in CellNet)
                {
                    cell.Particles.Clear();
                }
            }
            CellNet = null;
            Cells.Clear();
            if (AllParticles.Count == 0)
            {
                return;
            }
            xmin = AllParticles.Min(p => p.X) - hmax * 0.5;
            ymin = AllParticles.Min(p => p.Y) - hmax * 0.5;
            xmax = AllParticles.Max(p => p.X) + hmax * 0.5;
            ymax = AllParticles.Max(p => p.Y) + hmax * 0.5;

            Nrows   = (int)Ceiling((ymax - ymin) / hmax);
            Ncols   = (int)Ceiling((xmax - xmin) / hmax);
            CellNet = new Cell2D[Ncols, Nrows];
            for (int i = 0; i < Ncols; i++)
            {
                for (int j = 0; j < Nrows; j++)
                {
                    double x0 = xmin + i * hmax;
                    double x1 = x0 + hmax;
                    double y0 = ymin + j * hmax;
                    double y1 = y0 + hmax;
                    CellNet[i, j] = new Cell2D(i, j, x0, x1, y0, y1);
                    Cells.Add(CellNet[i, j]);
                }
            }
        }