Esempio n. 1
0
        private void TryJoiningNeighbor(MovableTile tile, Tile neighbor, SideName side)
        {
            if (IsMovable(neighbor)) // the neighbor is attachable/movable
            {
                MovableTile neighborMovableTile = (MovableTile)neighbor;
                bool        neighborAttachableOnOppositeSide =
                    RobuzzleUtilities.IsTileAttachableOnOppositeSide(neighborMovableTile, side);

                if (neighborAttachableOnOppositeSide) //the tile and neighbor can join together
                {
                    //if the tile neighbor tile are not already attached
                    if (!AreAttached(tile, neighborMovableTile))
                    {
                        RigidbodyTile RBTile = GetRigidbodyTile(tile);
                        if (RBTile != null)//If neighbor already has a rigidbody, attach both rigidbodies
                        {
                            JoinNeighbor(RBTile, neighborMovableTile, side);
                        }
                        else//join simple movable tile with neighbors -> or can that be done somewhere else
                        {
                            RigidbodyTile RBNeighbor = GetRigidbodyTile(neighborMovableTile);
                            if (RBNeighbor != null)
                            {
                                JoinNeighbor(RBNeighbor, tile, RobuzzleUtilities.GetOppositeSide(side)); //this tile is on the left of neighbor
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 //TODO: Recheck tile type
 private void JoinNeighbor(RigidbodyTile tile, MovableTile neighbor, SideName side)
 {
     //the neighbor is on left, down or back side of the tile
     if (side == SideName.left || side == SideName.down || side == SideName.back)
     {
         JoinNeighbor(tile, neighbor, true);
     }
     else// neighbor is on the right, up or front side of the tile
     {
         JoinNeighbor(tile, neighbor, false);
     }
 }
Esempio n. 3
0
        private RigidbodyTile GetRigidbodyTile(MovableTile tile)
        {
            RigidbodyTile RBTile = null;

            if (tile.GetType() == typeof(RigidbodyTile) || tile.GetType().IsSubclassOf(typeof(RigidbodyTile)))
            {
                RBTile = (RigidbodyTile)tile;
            }
            else if (tile.transform.parent != null)
            {
                RBTile = tile.transform.parent.GetComponent <RigidbodyTile>();
            }
            return(RBTile);
        }
Esempio n. 4
0
        private void JoinNeighbor(RigidbodyTile rbTile, MovableTile neighbor, bool tile2OnNegativeSide)
        {
            RigidbodyTile neighborRigidbodyTile = GetRigidbodyTile(neighbor);

            if (neighborRigidbodyTile != null) //if the neighbor has rigidbody, or a parent has rigidbody
            {
                RigidbodyTile rbTile1;
                RigidbodyTile rbTile2;
                if (tile2OnNegativeSide)
                {
                    rbTile1 = neighborRigidbodyTile;
                    rbTile2 = rbTile;
                }
                else
                {
                    rbTile1 = rbTile;
                    rbTile2 = neighborRigidbodyTile;
                }

                /* Before attaching tile1 with tile2 we want to make sure that tile2 has a compound.
                 * Because, tile1 is added into tile2's cmompound
                 */

                if (rbTile2.Compound == null)     //tile2 has no compound
                {
                    if (rbTile1.Compound == null) //tile1 has no compound
                    {
                        rbTile2.AddInCompound(new TileCompound());
                    }
                    else // if tile1 has a compound, assign it to tile2
                    {
                        rbTile2.AddInCompound(rbTile1.Compound);
                    }
                }
                else if (rbTile1.Compound != null) // if both tiles have compound we will merge the smaller one into bigger one
                {
                    if (rbTile2.Compound.GetTotalSize() > rbTile1.Compound.GetTotalSize())
                    {
                        rbTile2.Compound.Integrate(rbTile1.Compound);
                    }
                    else
                    {
                        rbTile1.Compound.Integrate(rbTile2.Compound);
                    }
                }
                //now rbTile2 must have a compound. Tile1 is added into tile2's compound
                rbTile1.Attach(rbTile2);
            }
            else // if the neighbor has no rigidbody onitself and on its parent
            {
                if (rbTile.Compound == null)
                {
                    rbTile.AddInCompound(new TileCompound());
                }
                neighbor.Attach(rbTile);

                /*
                 * Simple moving tiles are not connected to their neighbors,
                 * until a rigidbody is added in their neighborhood. So, they must
                 * attach all their neighbors recursively when a rigidbody is added in neighborhood
                 * */
                JoinNeighbors(neighbor);
            }
        }