Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
    void SetCellAction(ActionReq ar, bool hover)
    {
        GameGrid2D g = ar.p == ar.t ? this.playerGrid : this.enemyGrid;

        if (ar.loc == null)
        {
            return;             // Return early if there's not loc of cell given. Nothing will be done
        }
        switch (ar.a)
        {
        case pAction.fireBasic:
        case pAction.fireAgain:
        case pAction.buildWall:
        case pAction.buildOffenceTower:
        case pAction.buildDefenceTower:
        case pAction.buildIntelTower:
        case pAction.scout:
        case pAction.placeMine:
        case pAction.buildReflector:
        case pAction.firePiercing:
        case pAction.noAction:
        case pAction.towerTakeover:
            g.SetSingleSelect(hover, ar.loc[0]);
            break;

        case pAction.fireRow:
            g.SetRowSelect(hover, (int)ar.loc[0].y);
            break;

        case pAction.fireSquare:
            g.SetEmptySquareSelect(hover, ar.loc[0]);
            break;

        case pAction.placeMole:
            g.SetSquare3Select(hover, ar.loc[0], 1);             // 3x3 square
            break;

        case pAction.buildDefenceGrid:
            g.SetSquare3Select(hover, ar.loc[0], 2);             // 5x5 square
            break;

        case pAction.blockingShot:         // these guys don't have any targeting or loc in their action
        case pAction.hellFire:
        case pAction.flare:
            break;

        default:
            Debug.Log("Unhandled pAction Type: " + ar.a.ToString());
            break;
        }
    }
Ejemplo n.º 3
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;
    }
Ejemplo n.º 4
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());
    }
Ejemplo n.º 5
0
    public void InstantiateGrids()
    {
        float   width;
        float   height;
        Vector3 center1;
        Vector3 center2;

        if (this.transform.localScale.x > this.transform.localScale.y)          // horizontal board
        {
            width  = (this.transform.localScale.x - this.midSpace) / 2.0f;
            height = this.transform.localScale.y;
            //Debug.Log(string.Format("W{0} > H{1}", width, height));
            center1 = this.transform.position - new Vector3(width / 2.0f + this.midSpace / 2.0f, 0, 0);
            center2 = this.transform.position + new Vector3(width / 2.0f + this.midSpace / 2.0f, 0, 0);
        }
        else          // vertical board
        {
            width  = this.transform.localScale.x;
            height = (this.transform.localScale.y - this.midSpace) / 2.0f;
            //Debug.Log(string.Format("W{0} < H{1}", width, height));
            center1 = this.transform.position - new Vector3(0, height / 2.0f + this.midSpace / 2.0f, 0);
            center2 = this.transform.position + new Vector3(0, height / 2.0f + this.midSpace / 2.0f, 0);
        }
        //Debug.Log(string.Format("cent1 {0}, cent2 {1}", center1, center2));
        this.playerGrid = Instantiate(gridPrefab, center1, Quaternion.identity).GetComponent <GameGrid2D>();
        this.enemyGrid  = Instantiate(gridPrefab, center2, Quaternion.identity).GetComponent <GameGrid2D>();
        //Debug.Log("Width/Height " + width.ToString() + " " + height.ToString());
        this.playerGrid.PlaceCells(width, height);
        int[] size = this.playerGrid.GetGridSize();
        //Debug.Log("size/size " + size[0].ToString() + " " + size[1].ToString());
        this.sizex                      = size[0];
        this.sizey                      = size[1];
        this.playerGrid.parent          = this;
        this.playerGrid.playerOwnedGrid = true;
        this.enemyGrid.PlaceCells(width, height);
        this.enemyGrid.parent          = this;
        this.enemyGrid.playerOwnedGrid = false;
        this.enemyGrid.Flip();         //This one's facing the player, needs to be flipped
        //Now fill out the decorative cells
        //
    }
Ejemplo n.º 6
0
    public void SetCellStruct(bool pGrid, Vector2 pos, CellStruct cStruct)
    {
        GameGrid2D g = (pGrid) ? this.playerGrid : this.enemyGrid;

        g.SetCellStruct(pos, cStruct);
    }