Exemplo n.º 1
0
    int movementToArrayNum(TileBaseScript lastTile, TileBaseScript thisTile)
    {
        int x      = lastTile.x;
        int xOther = thisTile.x;
        int y      = lastTile.y;
        int yOther = thisTile.y;

        if (x > xOther)              //left
        {
            return(0);
        }
        else if (x < xOther)         //right
        {
            return(2);
        }
        else if (y > yOther)         //down
        {
            return(3);
        }
        else if (y < yOther)         //up
        {
            return(1);
        }
        else
        {
            Debug.LogError("erorrr");
            return(-1);
        }
    }
Exemplo n.º 2
0
    void UpdateBeltInOut(TileBaseScript lastTile, TileBaseScript thisTile, BeltScript myBelt, bool isIn)
    {
        int x      = lastTile.x;
        int xOther = thisTile.x;
        int y      = lastTile.y;
        int yOther = thisTile.y;

        if (isIn)
        {
            if (x > xOther)                  //left
            {
                myBelt.inLocations [2] = true;
            }
            else if (x < xOther)             //right
            {
                myBelt.inLocations [0] = true;
            }
            else if (y > yOther)             //down
            {
                myBelt.inLocations [1] = true;
            }
            else if (y < yOther)             //up
            {
                myBelt.inLocations [3] = true;
            }
        }
        else
        {
            if (x > xOther)                  //left
            {
                myBelt.outLocations [0] = true;
            }
            else if (x < xOther)             //right
            {
                myBelt.outLocations [2] = true;
            }
            else if (y > yOther)             //down
            {
                myBelt.outLocations [3] = true;
            }
            else if (y < yOther)             //up
            {
                myBelt.outLocations [1] = true;
            }
        }

        //myBelt.UpdateGraphic ();
    }
Exemplo n.º 3
0
    void CheckSetItem(int myX, int myY, int i, bool isin)
    {
        TileBaseScript myTile = Grid.s.myTiles [myX, myY].GetComponent <TileBaseScript> ();

        if (myTile.areThereItem)
        {
            PlacedItemBaseScript myItem = myTile.myItem.GetComponent <PlacedItemBaseScript> ();
            BeltScript           myBelt = myTile.myItem.GetComponent <BeltScript> ();


            if (myItem != null)
            {
                if (isin)
                {
                    inputItems [i] = myItem;
                    myItem.outConveyors [myItem.n_out] = this;
                    myItem.n_out++;
                }
                else
                {
                    feedingItems [i] = myItem;
                    myItem.inConveyors [myItem.n_in] = this;
                    myItem.n_in++;
                }
            }
            else if (myBelt != null)
            {
                if (isin)
                {
                    inputBelts [i] = myBelt;
                    myBelt.feedingBelts [RevertLocation(i)] = this;
                }
                else
                {
                    feedingBelts [i] = myBelt;
                    myBelt.inputBelts [RevertLocation(i)] = this;
                }
            }
            else
            {
                Debug.LogError(myTile + " = " + myX + " - " + myY + "weird shit happened there");
            }
        }
    }
Exemplo n.º 4
0
    public void DrawTiles()
    {
        DeleteAllTiles();

        for (int x = 0; x < myTiles.GetLength(0); x++)
        {
            for (int y = 0; y < myTiles.GetLength(1); y++)
            {
                GameObject myTile = (GameObject)Instantiate(tileSet.prefabs[myTilesIDs.tiles [x, y]], transform.position, transform.rotation);
                myTiles [x, y] = myTile;

                TileBaseScript myTileScript = myTile.GetComponent <TileBaseScript> ();

                myTileScript.x = x;
                myTileScript.y = y;
                //myTileScript.mySet = tileSet;
                //myTileScript.tileType = myTilesIDs.tiles [x, y];
                myTileScript.UpdateLocation();

                myTileScript.transform.parent = transform;
            }
        }
    }
Exemplo n.º 5
0
    public void PlaceSelf(int myX, int myY)
    {
        //print ("saver call");

        x = myX;
        y = myY;

        TileBaseScript myTileS = Grid.s.myTiles [x, y].GetComponent <TileBaseScript> ();

        transform.position   = myTileS.transform.position;
        myTileS.areThereItem = true;
        myTileS.myItem       = gameObject;
        //print (x + " - " + y + " - " + Grid.s.myTiles [x, y].transform.position);

        //print ("saver call2");
        if (mySprites [0] == null)
        {
            PlaceSprites();
        }

        //print ("saver call3");

        _PlaceSelf();
    }
Exemplo n.º 6
0
    void _PlaceSelf()
    {
        //print ("Place self");

        GameObject           InstantiatedItem = (GameObject)Instantiate(myPlacedItem, transform.position, Quaternion.identity);
        PlacedItemBaseScript InstItemScript   = InstantiatedItem.GetComponent <PlacedItemBaseScript> ();

        foreach (GameObject thisSprite in mySprites)
        {
            ItemSprite mySprite = null;
            try{
                mySprite = thisSprite.GetComponentInChildren <ItemSprite> ();
            }catch {
            }
            if (mySprite != null)
            {
                int checkX = x - mySprite.x;
                int checkY = y - mySprite.y;

                try {
                    TileBaseScript myTile = Grid.s.myTiles [checkX, checkY].GetComponent <TileBaseScript> ();
                    //myTile.itemPlaceable = false;
                    myTile.areThereItem = true;
                    myTile.myItem       = InstantiatedItem;
                    InstItemScript.tilesCovered [InstItemScript.n_cover] = myTile;
                    InstItemScript.n_cover++;
                } catch {
                }
            }
        }

        InstItemScript.x = x;
        InstItemScript.y = y;
        //print ("destroy");
        Destroy(gameObject);
    }
Exemplo n.º 7
0
    public void ClickTile(GameObject tile)
    {
        if (!canEditTiles)
        {
            return;
        }

        s = this;
        //print (tile);

        TileBaseScript myTileScript = tile.GetComponent <TileBaseScript> ();

        int x = myTileScript.x;
        int y = myTileScript.y;

        Destroy(myTiles [x, y].gameObject);

        GameObject tileToSpawn;

        tileToSpawn             = tileSet.prefabs [myType];
        myTilesIDs.tiles [x, y] = myType;

        GameObject myTile = (GameObject)Instantiate(tileToSpawn, transform.position, transform.rotation);

        myTiles [x, y] = myTile;

        myTileScript = myTile.GetComponent <TileBaseScript> ();

        myTileScript.x = x;
        myTileScript.y = y;
        myTileScript.UpdateLocation();

        myTileScript.transform.parent = transform;

        //Save ();
    }
Exemplo n.º 8
0
    void PlaceBeltsCheck()
    {
        if (Input.touchCount > 0)
        {
            Ray        myRay = mycam.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit hit   = new RaycastHit();
            if (Physics.Raycast(myRay, out hit))                                                                                        // cast the ray
            {
                TileBaseScript tileS;
                try {
                    tileS = hit.collider.gameObject.GetComponent <TileBaseScript> ();                           //hit something
                } catch {
                    return;
                }

                if (b_lastTile == tileS)                                                                                                                //is it still the same tile?
                //print ("do nothing");
                {
                    return;
                }
                if (b_lastTile != null)                                                                                                                 //how much did we moved - if too much do shit
                {
                    if (Mathf.Abs(b_lastTile.x - tileS.x) >= 2 || Mathf.Abs(b_lastTile.y - tileS.y) >= 2 || Mathf.Abs(b_lastTile.y - tileS.y) + Mathf.Abs(b_lastTile.x - tileS.x) >= 2)
                    {
                        print("we moved 2 blocks");

                        if (b_lastBelt != null)
                        {
                            b_lastBelt.UpdateGraphic();
                        }

                        b_lastBelt = null;
                        b_lastItem = null;
                        b_lastTile = null;
                    }
                }

                if (tileS.beltPlaceable)                                                        //can we place a belt here
                {
                    if (!tileS.areThereItem)                                                    //there are no items here so place a belt
                    {
                        BeltScript myBelt = ((GameObject)Instantiate(beltPrefab, tileS.transform.position, Quaternion.identity)).GetComponent <BeltScript> ();
                        myBelt.gameObject.name = myBelt.gameObject.name + " - " + n;
                        myBelt.x = tileS.x;
                        myBelt.y = tileS.y;
                        n++;
                        tileS.areThereItem = true;
                        tileS.myItem       = myBelt.gameObject;

                        if (b_lastTile != null)                                                                                                         //this is not the starting point - update in location
                        {
                            UpdateBeltInOut(b_lastTile, tileS, myBelt, true);
                        }

                        if (b_lastBelt != null)                                                                                                         //there was a belt before this one - update its out stuff
                        {
                            UpdateBeltInOut(b_lastTile, tileS, b_lastBelt, false);

                            b_lastBelt.feedingBelts [movementToArrayNum(b_lastTile, tileS)]           = myBelt;
                            myBelt.inputBelts [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastBelt;
                        }

                        if (b_lastItem != null)                                                                                                         //there was an item before us - update its out stuff
                        {
                            b_lastItem.outConveyors [b_lastItem.n_out] = myBelt;
                            b_lastItem.n_out++;
                            myBelt.inputItems [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastItem;
                        }

                        if (b_lastBelt != null)
                        {
                            b_lastBelt.UpdateGraphic();
                        }
                        if (myBelt != null)
                        {
                            myBelt.UpdateGraphic();
                        }

                        b_lastBelt = myBelt;
                        b_lastItem = null;
                        b_lastTile = tileS;
                    }
                    else                                                                                                                                                //there is an item below us
                    {
                        PlacedItemBaseScript myItem = null;
                        BeltScript           myBelt = null;
                        myItem = tileS.myItem.GetComponent <PlacedItemBaseScript> ();
                        myBelt = tileS.myItem.GetComponent <BeltScript> ();

                        if (b_lastBelt == null && b_lastItem == null)                                                                                   //nothing to something
                        //do nothing

                        {
                        }
                        else if (b_lastBelt == null && b_lastItem != null && myItem != null)                                    //item to item
                        //do nothing

                        {
                        }
                        else if (b_lastBelt == null && b_lastItem != null && myBelt != null)                                    //item to belt
                        {
                            b_lastItem.outConveyors [b_lastItem.n_out] = myBelt;
                            b_lastItem.n_out++;
                            b_lastBelt.inputItems [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastItem;
                            UpdateBeltInOut(b_lastTile, tileS, myBelt, true);
                        }
                        else if (b_lastBelt != null && b_lastItem == null && myBelt != null)                                    //belt to belt
                        {
                            UpdateBeltInOut(b_lastTile, tileS, b_lastBelt, false);
                            b_lastBelt.feedingBelts [movementToArrayNum(b_lastTile, tileS)]           = myBelt;
                            myBelt.inputBelts [RevertLocation(movementToArrayNum(b_lastTile, tileS))] = b_lastBelt;

                            UpdateBeltInOut(b_lastTile, tileS, myBelt, true);
                        }
                        else if (b_lastBelt != null && b_lastItem == null && myItem != null)                                    //belt to item
                        {
                            UpdateBeltInOut(b_lastTile, tileS, b_lastBelt, false);
                            b_lastBelt.feedingItems [movementToArrayNum(b_lastTile, tileS)] = myItem;

                            myItem.inConveyors [myItem.n_in] = b_lastBelt;
                            myItem.n_in++;
                        }
                        else
                        {
                            Debug.LogError("weird shit happened: " + b_lastTile + " - " + tileS + " - " + b_lastBelt + " - " + b_lastItem + " - " + myBelt + " - " + myItem);
                        }

                        if (b_lastBelt != null)
                        {
                            b_lastBelt.UpdateGraphic();
                        }
                        if (myBelt != null)
                        {
                            myBelt.UpdateGraphic();
                        }

                        b_lastBelt = myBelt;
                        b_lastItem = myItem;
                        b_lastTile = tileS;
                    }
                }
            }
        }
        else
        {
            if (b_lastBelt != null)
            {
                b_lastBelt.UpdateGraphic();
            }

            b_lastBelt = null;
            b_lastItem = null;
            b_lastTile = null;
        }
    }
Exemplo n.º 9
0
    public void InstantiationUpdate()
    {
        TileBaseScript myTileS = Grid.s.myTiles [x, y].GetComponent <TileBaseScript> ();

        transform.position   = myTileS.transform.position;
        myTileS.areThereItem = true;
        myTileS.myItem       = gameObject;


        for (int i = 0; i <= 3; i++)
        {
            if (inLocations [i])
            {
                switch (i)
                {
                case 0:
                    CheckSetItem(x - 1, y - 0, 0, true);
                    break;

                case 1:
                    CheckSetItem(x - 0, y + 1, 1, true);
                    break;

                case 2:
                    CheckSetItem(x + 1, y - 0, 2, true);
                    break;

                case 3:
                    CheckSetItem(x - 0, y - 1, 3, true);
                    break;

                default:
                    print("cry like a bitch");
                    break;
                }
            }

            if (outLocations [i])
            {
                switch (i)
                {
                case 0:
                    CheckSetItem(x - 1, y - 0, 0, false);
                    break;

                case 1:
                    CheckSetItem(x - 0, y + 1, 1, false);
                    break;

                case 2:
                    CheckSetItem(x + 1, y - 0, 2, false);
                    break;

                case 3:
                    CheckSetItem(x - 0, y - 1, 3, false);
                    break;

                default:
                    print("cry like a bitch");
                    break;
                }
            }
        }

        UpdateGraphic();
        Invoke("UpdatePulseControls", 0.1f);
    }
Exemplo n.º 10
0
 void OnEnable()
 {
     tile = (TileBaseScript)target;
 }