Ejemplo n.º 1
0
 public bool move(int x, int y)       //Move the pawn to a new square. Fails if can't do that, star fox. Doesn't check for movement blocks or valid move distance.
 {
     if (x >= 0 && x < grid.Width() && y >= 0 && y < grid.Height())
     {
         if (grid [x, y].occupied == 0 && grid [x, y].occupant == null)
         {
             grid [gridX, gridY].occupied = 0;
             grid [gridX, gridY].occupant = null;
             grid [x, y].occupied         = team;
             grid [x, y].occupant         = this;
             gridX = x;
             gridY = y;
             transform.position = grid.worldPos(gridX, gridY);
             active             = false;
             return(true);
         }
         else
         {
             Debug.LogError("Pawn Movement Failed. Space already occupied");
             return(false);
         }
     }
     else
     {
         Debug.LogError("Pawn Movement Out of Bounds");
         return(false);
     }
 }
Ejemplo n.º 2
0
 public void addToGrid(movementGrid Grid)
 {
     grid = Grid;
     if (gridX >= 0 && gridY >= 0 && gridX < grid.Width() && gridY < grid.Height())
     {
         grid [gridX, gridY].restricted = Blocked;
         grid [gridX, gridY].slow       = Slowed;
         transform.position             = grid.worldPos(gridX, gridY);
     }
     else
     {
         Debug.LogError("Invalid grid obstacle position");
     }
 }
Ejemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Click"))
     {
         Vector2i pos = grid.gridPos(Camera.main.ScreenToWorldPoint(Input.mousePosition));               //Find where the mouse clicked
         if (pos.x >= 0 && pos.y >= 0 && pos.x < grid.Width() && pos.y < grid.Height())
         {
             if (selected)                              // A pawn is already selected.
             {
                 grid [aPos].occupant.deleteSpotDraw(); //Clear active drawing
                 if (grid [pos].occupied != 0)          //Aw shucks. Something's here. Let's select it!
                 {
                     aPos     = pos;
                     selected = true;
                     if (grid [pos].occupant.active)                           //If it's ready to move, let's get it some valid moves and draw them!
                     {
                         grid [pos].occupant.calcMoves();
                         grid [pos].occupant.drawValidSpots();
                     }
                 }
                 else if (grid [aPos].occupant.isValidMove(pos) && grid [aPos].occupant.active)                          //Alright. Can move. Lets do it.
                 {
                     grid [aPos].occupant.move(pos.x, pos.y);
                     selected = false;
                 }
                 else                         //Othrewise, if you don't click on anythign, you don't select things.
                 {
                     selected = false;
                 }
             }
             else
             {
                 if (grid [pos].occupied != 0)
                 {
                     aPos     = pos;
                     selected = true;
                     if (grid [pos].occupant.active)
                     {
                         grid [pos].occupant.calcMoves();
                         grid [pos].occupant.drawValidSpots();
                     }
                 }
                 else
                 {
                     selected = false;
                 }
             }
         }
         else
         {
             selected = false;
         }
     }
     if (Input.GetButtonDown("NewTurn"))            //Prototypey way to make a new turn start.
     {
         List <mGridPawn> pawns = new List <mGridPawn> ();
         pawns.AddRange(GetComponentsInChildren <mGridPawn> ());
         foreach (mGridPawn i in pawns)
         {
             i.newTurn();
         }
     }
 }