Ejemplo n.º 1
0
 //starting the movement action and setting the tile we were to walkable again
 public override void doAction()
 {
     um         = this.GetComponent <UnitMovement> ();
     targetNode = GridGenerator.me.getTile((int)um.positionWeAreAt.x, (int)um.positionWeAreAt.y);
     targetNode.setTileWalkable(true);
     targetNode.setTileStandable(true);
     um.moveToLocation(positionWeAreMovingTo);
 }
Ejemplo n.º 2
0
 //set every changed tile to the previous position
 public override void cleanUp()
 {
     targetNode = GridGenerator.me.getTile((int)um.positionWeAreAt.x, (int)um.positionWeAreAt.y);
     targetNode.setTileWalkable(false);
     targetNode.setTileStandable(false);
     targetNode = GridGenerator.me.getTile((int)positionWeAreMovingTo.x, (int)positionWeAreMovingTo.y);
     targetNode.setTileStandable(true);
 }
Ejemplo n.º 3
0
 //check if the movement action is completed and if it is made the tile we are on to unwalkable to prevent soldiers stacking on top of each other and prevent placing buildings on top of soldiers
 public override bool getIsActionComplete()
 {
     if (Vector3.Distance(positionWeAreMovingTo, this.transform.position) < 2.0f)
     {
         TileMasterClass targetNode = GridGenerator.me.getTile((int)positionWeAreMovingTo.x, (int)positionWeAreMovingTo.y);
         targetNode.setTileWalkable(false);
         um = this.GetComponent <UnitMovement> ();
         um.positionWeAreAt = positionWeAreMovingTo;
         return(true);
     }
     else
     {
         return(false);
     }
 }
    void createBuildingAtLocation(Vector3 cursorPos, int width, int height)//creates a building from the one currently selected at the mouse position
    {
        //gets the lowets and highest of the each axis, works cause the selected tiles are in increasing order
        int xLowBound  = (int)currentlySelected[0].GetComponent <TileMasterClass>().getGridCoords().x;
        int xHighBound = (int)currentlySelected[currentlySelected.Count - 1].GetComponent <TileMasterClass>().getGridCoords().x;
        int yLowBound  = (int)currentlySelected[0].GetComponent <TileMasterClass>().getGridCoords().y;
        int yHighBound = (int)currentlySelected[currentlySelected.Count - 1].GetComponent <TileMasterClass>().getGridCoords().y;

        for (int x = 0; x < currentlySelected.Count - 1; x++)//goes through all the tiles and makes the ones not on the outside(where the actual building will be placed unwalkable)
        {
            GameObject      tile = currentlySelected[x];
            TileMasterClass tm   = tile.GetComponent <TileMasterClass>();

            Vector2 curTileGrid = tm.getGridCoords();
            if (curTileGrid.x == xLowBound || curTileGrid.x == xHighBound)
            {
                if (curTileGrid.y == yLowBound || curTileGrid.y == yHighBound)
                {
                    Debug.Log("Keeping" + tile.name + " Walkable");
                }
            }
            else if (curTileGrid.y == yLowBound || curTileGrid.y == yHighBound)
            {
                if (curTileGrid.x == xLowBound || curTileGrid.x == xHighBound)
                {
                    Debug.Log("Keeping" + tile.name + " Walkable");
                }
            }
            else
            {
                tm.setTileWalkable(false);
            }
        }


        //this code creates the building
        Vector3        spawnPos = currentlySelected[(currentlySelected.Count - 1) / 2].transform.position;
        GameObject     built    = (GameObject)Instantiate(AssignMethodToInventoryItems.me.getToBuild(), spawnPos, Quaternion.Euler(0, 0, 0));
        SpriteRenderer sr       = built.AddComponent <SpriteRenderer>();

        sr.sprite       = built.GetComponent <Building>().buildingSprite;
        sr.sortingOrder = 10;
        built.AddComponent <BoxCollider2D>();
        built.SetActive(true);
        clearSelected();
    }