예제 #1
0
    // Places tile on new space in LevelPart and updated references of shared walls and neighbors
    public void Reposition(Vector2 newPos, LevelPart newBelonging, bool setNeigh)
    {
        UpdateAttachedObjectsList();
        Vector2 movedDistance = new Vector2(newPos.x - Pos.x, newPos.y - Pos.y);

        // set LevelPart belonging to
        mLevelPartBelongingTo = newBelonging;

        // Delete Neighbors refrence to this tile, and delete own references
        DeleteNeighborRelation(LookingDirection.North);
        DeleteNeighborRelation(LookingDirection.East);
        DeleteNeighborRelation(LookingDirection.South);
        DeleteNeighborRelation(LookingDirection.West);

        // reposition on LevelPart
        gameObject.transform.localPosition = new Vector3(newPos.x * World.TILE_SIZE, 0, newPos.y * World.TILE_SIZE);
        mPos = newPos;

        // get new neighbors from LevelPart
        if (setNeigh)
        {
            SetNeighbor(LookingDirection.North, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x, newPos.y + 1)));
            SetNeighbor(LookingDirection.West, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x - 1, newPos.y)));
            SetNeighbor(LookingDirection.South, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x, newPos.y - 1)));
            SetNeighbor(LookingDirection.East, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x + 1, newPos.y)));
        }

        // Take objects belonging to tile with it
        foreach (GameObject obj in AttachedObjects)
        {
            obj.transform.position = new Vector3(obj.transform.position.x + movedDistance.x * World.TILE_SIZE, obj.transform.position.y, obj.transform.position.z + movedDistance.y * World.TILE_SIZE);
        }
    }
예제 #2
0
    public void updateNeighbors()
    {
        Vector2 newPos = Pos;

        SetNeighbor(LookingDirection.North, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x, newPos.y + 1)));
        SetNeighbor(LookingDirection.West, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x - 1, newPos.y)));
        SetNeighbor(LookingDirection.South, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x, newPos.y - 1)));
        SetNeighbor(LookingDirection.East, mLevelPartBelongingTo.GetTileByPos(new Vector2(newPos.x + 1, newPos.y)));
    }