Example #1
0
    private MoveTile nextTile; // link for link listing

    void Start()
    {
        myTransform = gameObject.GetComponent(typeof(Transform)) as Transform;
        // add self to the tile stack
        nextTile = null;
        clear();
    }
Example #2
0
    public void ChangeNextTile(TileDirection direction)
    {
        tileDirection = direction;
        switch (direction)
        {
        case TileDirection.Up:
            nextTile = Up;
            break;

        case TileDirection.Down:
            nextTile = Down;
            break;

        case TileDirection.Left:
            nextTile = Left;
            break;

        case TileDirection.Right:
            nextTile = Right;
            break;

        default:
            break;
        }

        RotateTile(direction);
    }
Example #3
0
 public MoveCommand(MoveTile currTile, MoveTile prevTile, MoveTile adjTile, PlayerMovement plyMov)
 {
     currentTile    = currTile;
     previousTile   = prevTile;
     adjacentTile   = adjTile;
     playerMovement = plyMov;
 }
Example #4
0
    private MoveTile getMoveTile(int row, int col)
    {
        MoveTile foundTile = null;

        for (int i = moveTiles.Count - 1; i >= 0; i--)
        {
            MoveTile testMoveTile = moveTiles[i];

            if (testMoveTile.shouldDestroy)
            {
                // ignore this move tile, its being destroyed. We can remove it form our list.
                moveTiles.Remove(testMoveTile);
            }
            else
            {
                int moveTileRow = (int)testMoveTile.y / 64;
                int moveTileCol = (int)testMoveTile.x / 64;

                if (moveTileRow == row && moveTileCol == col)
                {
                    foundTile = testMoveTile;
                    break;
                }
            }
        }

        return(foundTile);
    }
Example #5
0
    private IEnumerator MoveToTile(MoveTile currTile, MoveTile prevTile, MoveTile currAdjTile, bool loop)
    {
        if (currAdjTile != null)
        {
            var distance = 0f;
            prevTile = currTile;
            currTile = currAdjTile;

            //set private members.
            previousTile = prevTile;
            currentTile  = currTile;

            var direction = currTile.transform.position - prevTile.transform.position;
            playerContainer.transform.rotation = Quaternion.LookRotation(direction.normalized);

            do
            {
                distance = (currTile.transform.position - transform.position).sqrMagnitude;
                transform.Translate(direction.normalized * moveSpeed * Time.deltaTime);
                yield return(null);
            } while(distance > 0.05);
        }

        var handler = MoveToTileDone;

        if (handler != null)
        {
            handler(this, new MoveTileEventArgs(loop));
        }
    }
Example #6
0
 /// <summary>
 /// This function determines what happens in the event of a movement collision , and then calls
 /// moveOBjectToTile to handle the movement. A movement collision is when the BoardEntity that
 /// calls this tries to move into an occupied space.
 /// </summary>
 public virtual void moveAction(MoveTile tileToMoveTo, MoveTile tileMovedFrom, int col, int row)
 {
     if (tileToMoveTo.occupant != null)
     {
         return;
     }
     moveObjectToTile(tileToMoveTo, tileMovedFrom, col, row);
 }
Example #7
0
    public void moveObjectToTile(MoveTile tileToMoveTo, MoveTile tileMovedFrom, int col, int row)
    {
        transform.position = new Vector3(col, 0, row);
        currentCol         = col;
        currentRow         = row;

        tileMovedFrom.setOccupant(null);
        tileToMoveTo.setOccupant(gameObject);
    }
Example #8
0
    public void moveInitiate(int col, int row)
    {
        if (col >= PlayerBoard.current.getColLimit() || row >= PlayerBoard.current.getRowLimit())
        {
            return;
        }
        MoveTile tileToMoveTo  = PlayerBoard.current.tile2DArray[col, row];
        MoveTile tileMovedFrom = PlayerBoard.current.tile2DArray[currentCol, currentRow];

        moveBehavior(tileToMoveTo, tileMovedFrom, col, row);
    }
Example #9
0
    public void MovePlayer(MoveTile currTile, MoveTile prevTile, MoveTile currAdjTile, bool loop = true)
    {
        if (moveToTileRoutine != null)
        {
            StopCoroutine(moveToTileRoutine);
            moveToTileRoutine = null;
        }

        HasWon            = false;
        moveToTileRoutine = StartCoroutine(MoveToTile(currTile, prevTile, currAdjTile, loop));
    }
Example #10
0
    public void clearTiles()
    {
        // iterate through deployed tiles list and remove them/add them back into the stack
        while (deployedStack != null)
        {
            tempTile      = deployedStack;
            deployedStack = deployedStack.getNextTile();

            tempTile.clear();
        }
    }
Example #11
0
 public override void moveAction(MoveTile tileToMoveTo, MoveTile tileMovedFrom, int col, int row)
 {
     if (tileToMoveTo.occupant == null)
     {
         moveObjectToTile(tileToMoveTo, tileMovedFrom, col, row);
     }
     else if (tileToMoveTo.occupant.tag == "Enemy")
     {
         tileToMoveTo.occupant.GetComponent <BoardEntity>().TakeDamage(damage);
         Destroy(gameObject);
     }
     else if (tileToMoveTo.occupant != null)
     {
         Destroy(gameObject);
     }
 }
Example #12
0
    public void moveTileAdded(MoveTile newMoveTile)
    {
        // first check if this tile exists
        for (int i = moveTiles.Count - 1; i >= 0; i--)
        {
            MoveTile testMoveTile = moveTiles[i];

            if (testMoveTile.x == newMoveTile.x && testMoveTile.y == newMoveTile.y)
            {
                moveTiles.Remove(testMoveTile);
                testMoveTile.shouldDestroy = true;
                break;                 // break out since we can only have 1 moveTile on a location
            }
        }

        moveTiles.Add(newMoveTile);
    }
Example #13
0
    public void deployTile(int x, int y, Unit myUnit)       // links to the unit it's deploying for
    // remove tile from the main stack
    {
        tempTile = headTile;

        // if we have tiles still in stack...
        if (headTile != null)
        {
            headTile = tempTile.getNextTile();
        }

        // add removed tile to the deployed stack
        tempTile.setNextTile(deployedStack);
        deployedStack = tempTile;

        // deploy the tile to the specified coordinates
        deployedStack.deploy(x, y, myUnit);
    }
Example #14
0
    private void spawnInventory()
    {
        //Debug.Log("Spawn Inv - " + _inventory.Length);
        for (int i = 0; i < _inventory.Length; i++)
        {
            if (_inventory[i] == null)
            {
                //Debug.Log("Empty Slot - " + i);
                MoveTile moveTile = new MoveTile();
                moveTile.sortZ = 5;
                moveTile.SetPosition(positionForInventory(i));

                _inventory[i] = moveTile;

                AddChild(moveTile);
            }
        }
    }
Example #15
0
    private MoveTile headTile, tempTile; // current head of the stack, and a temp tile for deployment

    // Use this for initialization
    void Awake()
    {
        // intialize anything that needs to
        headTile      = null;
        deployedStack = null;
    }
Example #16
0
 public void pushTile(MoveTile tile)
 {
     // add this tile to the stack
     tile.setNextTile(headTile);
     headTile = tile;
 }
Example #17
0
    public bool willObeyFloorTile(Crew crewMember, Vector2 newPosition)
    {
        bool willObey = false;
        // check for a floor tile under crew member

        // we'll do a tile based check if the crew member is completely in a tile

        // get crew member's bounding values
        float crewXMin = newPosition.x - (crewMember.width / 2);
        float crewXMax = newPosition.x + (crewMember.width / 2);
        float crewYMin = newPosition.y - (crewMember.height / 2);
        float crewYMax = newPosition.y + (crewMember.height / 2);

        // get crew members column number tile's x bounding values
        int colNumber = (int)newPosition.x / 64;
        int xTileMin  = colNumber * 64;
        int xTileMax  = xTileMin + 64;

        // get crew members row number tile's y bounding values
        int rowNumber = (int)newPosition.y / 64;
        int yTileMin  = rowNumber * 64;
        int yTileMax  = yTileMin + 64;

        MoveTile moveTile = getMoveTile(rowNumber, colNumber);

        if (moveTile != null && moveTile != crewMember.lastMoveTileUsed)
        {
            // crew member is on a move tile and is not currently following it
            if (crewMember.direction != moveTile.direction)
            {
                // we only care if the tile will change the crew members direction

                if (crewMember.direction == VectorDirection.Up || crewMember.direction == VectorDirection.Down)
                {
                    // crew member is moving up or down, wait until crew member is contained between tile's min/max y before obeying it
                    if (crewYMin >= yTileMin && crewYMax <= yTileMax)
                    {
                        crewMember.ChangeDirection(moveTile.direction);
                        crewMember.lastMoveTileUsed = moveTile;
                        willObey = true;
                    }
                }
                else
                {
                    // crew member is moving left or right, wait until crew member is contained between tile's min/max x before obeying it
                    if (crewXMin >= xTileMin && crewXMax <= xTileMax)
                    {
                        crewMember.ChangeDirection(moveTile.direction);
                        crewMember.lastMoveTileUsed = moveTile;
                        willObey = true;
                    }
                }
            }
        }
        else if (moveTile == null)
        {
            // crew member is not on a move tile
            crewMember.lastMoveTileUsed = null;
        }

        return(willObey);
    }
Example #18
0
    private void spawnInventory()
    {
        //Debug.Log("Spawn Inv - " + _inventory.Length);
        for (int i = 0; i < _inventory.Length; i++){
            if (_inventory[i] == null){
                //Debug.Log("Empty Slot - " + i);
                MoveTile moveTile = new MoveTile();
                moveTile.sortZ = 5;
                moveTile.SetPosition(positionForInventory(i));

                _inventory[i] = moveTile;

                AddChild(moveTile);
            }
        }
    }
Example #19
0
    public bool HandleSingleTouchBegan(FTouch touch)
    {
        //Vector2 touchPosition = touch.position;

        int rowTouched = (int)touch.position.y / 64;
        int colTouched = (int)touch.position.x / 64;

        if (colTouched == 1)
        {
            bool invSelected = false;
            // could be inventory
            if (rowTouched == 8)
            {
                // inventory 1 (top)
                invSelected     = true;
                _invNumSelected = 0;
            }
            else if (rowTouched == 6)
            {
                // inventory 2
                invSelected     = true;
                _invNumSelected = 1;
            }
            else if (rowTouched == 3)
            {
                // inventory 3
                invSelected     = true;
                _invNumSelected = 2;
            }
            else if (rowTouched == 1)
            {
                // inventory 4 (bottom)
                invSelected     = true;
                _invNumSelected = 3;
            }

            if (invSelected)
            {
                // so the user selected a valid inventory slot,
                // now make sure there is something in that slot
                if (_inventory[_invNumSelected] != null)
                {
                    selectedInventory.SetPosition(colTouched * 64 + 32, rowTouched * 64 + 32);
                    selectedInventory.isVisible = true;
                }
                else
                {
                    // they clicked on an empty inventory
                    invSelected     = false;
                    _invNumSelected = -1;
                }
            }
        }
        else
        {
            if (_invNumSelected != -1 && _inventory[_invNumSelected] != null)
            {
                // they have an inventory item selected

                // check that they touched a valid tile in the game
                bool validTouch = false;
                if (colTouched >= 3 && colTouched <= 15 && rowTouched >= 1 && rowTouched <= 8)
                {
                    // main section of ship
                    // now check its not in the escape pod room
                    if (colTouched >= 7 || rowTouched >= 3)
                    {
                        validTouch = true;
                    }
                }
                else if (colTouched >= 16 && colTouched <= 18 && rowTouched >= 2 && rowTouched <= 7)
                {
                    // spawn rooms
                    validTouch = true;
                }

                if (validTouch)
                {
                    MoveTile moveTile = _inventory[_invNumSelected];
                    moveTile.SetPosition(colTouched * 64 + 32, rowTouched * 64 + 32);
                    moveTile.PlaceTile();

                    _levelManager.moveTileAdded(moveTile);

                    _inventory[_invNumSelected] = null;
                    selectedInventory.isVisible = false;
                    _invNumSelected             = -1;
                }
            }
            else
            {
                _levelManager.handleUserTouch(touch);
            }
        }

        return(true);
    }
Example #20
0
    public void moveTileAdded(MoveTile newMoveTile)
    {
        // first check if this tile exists
        for (int i = moveTiles.Count-1; i >= 0; i--)
        {
            MoveTile testMoveTile = moveTiles[i];

            if (testMoveTile.x == newMoveTile.x && testMoveTile.y == newMoveTile.y){
                moveTiles.Remove(testMoveTile);
                testMoveTile.shouldDestroy = true;
                break; // break out since we can only have 1 moveTile on a location
            }
        }

        moveTiles.Add(newMoveTile);
    }
Example #21
0
 private void Start()
 {
     moveToTileRoutine      = null;
     previousTile           = currentTile;
     changedCachedDirection = MoveTile.TileDirection.None;
 }
Example #22
0
 /// <summary>
 /// This function determines how a BoardEntity should move. By default, it simply calls moveAction and passes
 /// its params along. This is separated from moveAction so that each can be overridden individually.
 /// </summary>
 public virtual void moveBehavior(MoveTile tileToMoveTo, MoveTile tileMovedFrom, int col, int row)
 {
     moveAction(tileToMoveTo, tileMovedFrom, col, row);
 }
Example #23
0
 public void setNextTile(MoveTile tile)
 {
     nextTile = tile;
 }
Example #24
0
    public void ModifyAdjacentTile(MoveTile previous, TileDirection dir = TileDirection.None)
    {
        previousTile = previous;
        //Return the same direction as currentTile.

        var prevDirection = dir == TileDirection.None ? previous.Direction : dir;

        switch (prevDirection)
        {
        case TileDirection.Up:
            nextTile      = Up;
            tileDirection = TileDirection.Up;
            break;

        case TileDirection.Down:
            nextTile      = Down;
            tileDirection = TileDirection.Down;
            break;

        case TileDirection.Left:
            nextTile      = Left;
            tileDirection = TileDirection.Left;
            break;

        case TileDirection.Right:
            nextTile      = Right;
            tileDirection = TileDirection.Right;
            break;

        default:
            break;
        }

        //No tiles on the same direction.
        if (nextTile == null)
        {
            switch (prevDirection)
            {
            case TileDirection.Up:
            {
                nextTile      = Up;
                tileDirection = TileDirection.Up;

                if (nextTile == null)
                {
                    nextTile      = Right;
                    tileDirection = TileDirection.Right;
                }

                if (nextTile == null)
                {
                    nextTile      = Left;
                    tileDirection = TileDirection.Left;
                }

                if (nextTile == null)
                {
                    nextTile      = Down;
                    tileDirection = TileDirection.Down;
                }
            }
            break;

            case TileDirection.Down:
            {
                nextTile      = Down;
                tileDirection = TileDirection.Down;

                if (nextTile == null)
                {
                    nextTile      = Left;
                    tileDirection = TileDirection.Left;
                }

                if (nextTile == null)
                {
                    nextTile      = Right;
                    tileDirection = TileDirection.Right;
                }

                if (nextTile == null)
                {
                    nextTile      = Up;
                    tileDirection = TileDirection.Up;
                }
            }
            break;

            case TileDirection.Left:
            {
                nextTile      = Left;
                tileDirection = TileDirection.Left;

                if (nextTile == null)
                {
                    nextTile      = Down;
                    tileDirection = TileDirection.Down;
                }

                if (nextTile == null)
                {
                    nextTile      = Up;
                    tileDirection = TileDirection.Up;
                }

                if (nextTile == null)
                {
                    nextTile      = Right;
                    tileDirection = TileDirection.Right;
                }
            }
            break;

            case TileDirection.Right:
            {
                nextTile      = Right;
                tileDirection = TileDirection.Right;

                if (nextTile == null)
                {
                    nextTile      = Up;
                    tileDirection = TileDirection.Up;
                }

                if (nextTile == null)
                {
                    nextTile      = Down;
                    tileDirection = TileDirection.Down;
                }

                if (nextTile == null)
                {
                    nextTile      = Left;
                    tileDirection = TileDirection.Left;
                }
            }
            break;

            default:
                break;
            }
        }
    }