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); } } }
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); }
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); } } }