Beispiel #1
0
def setMouseOffset(myCanvas, tiles, selectedTiles, mouseLoc, isDrag,
        selectedTile, grid, gridRes):
    # Only areas near the clicked tile are checked to see if they were
    # clicked on
    areasToCheck = getAreasToCheck(mouseLoc, grid, gridRes)
    for area in areasToCheck:
        for tile in area:
            # Part of this next block insures that only the tile on top
            # of other tiles is selected
            if (not isDrag and common.isInSquare(mouseLoc, tile.position,
                    tile.radius) and
                    common.getDistance(mouseLoc, tile.position) <
                    tile.radius and (selectedTile is None or
                    tiles.index(tile) > tiles.index(selectedTile))):
                selectedTile = tile
    # If there has been a left click, a single tile is selected.  If
    # there has been a right click, a group of snapped tiles is
    # selected.
    if selectedTile is not None:
        if myCanvas.isLDown:
            selectedTiles = [selectedTile]
        else:
            selectedTiles = []
            for tile in selectedTile.tileGroup:
                selectedTiles.append(tile)
        isDrag = True
        for tile in selectedTile.tileGroup:
            tile.mouseOffset = common.mySub(mouseLoc, tile.position)
            # The next two lines move all the tiles in a seleted group
            # of tiles to the top layer of the tiles
            tiles.remove(tile)
            tiles.append(tile)
    return selectedTiles, isDrag, selectedTile
Beispiel #2
0
def checkPallet(myCanvas, tiles, mouseLoc, isDrag, selectedTile):
    for tile in myCanvas.tilePallet:
        if (not isDrag and common.isInSquare(mouseLoc, tile.position,
                tile.radius) and common.getDistance(mouseLoc, tile.position) <
                tile.radius):
            newTile = objects.Tile(myCanvas, tile.image)
            newTile.setPosition(tile.position)
            tiles.append(newTile)
            newTile.mouseOffset = common.mySub(mouseLoc, tile.position)
            selectedTile = newTile
            isDrag = True
    return isDrag, selectedTile
Beispiel #3
0
def findMatch(sideA, sideB, minDistance, isMatch, snapdSide, adjSide):
    # This block only runs if the two sides are of the same color, and
    # also neither side is already snapped to another tile.
    if (sideA.color == sideB.color and
            common.isInSquare(sideA.corner.getPosition(),
            sideB.corner.getPosition(), minDistance) and not sideB.isSnapped):
        # When this code is run on different combinations of sides, this
        # code makes sure to only set the closest two compatible sides
        # as the sides to be used for snapping.
        distance = common.getDistance(sideA.corner.getPosition(),
                sideB.corner.getPosition())
        if distance < minDistance:
            minDistance = distance
            snapdSide = sideA
            adjSide = sideB
            isMatch = True
    return minDistance, isMatch, snapdSide, adjSide
Beispiel #4
0
def checkBorderSnap(mouseLoc, sideA, sideB, checkedTiles, isDragging,
        isSnapped, sidesToSnap, snapdTile, isConflict, selectedTiles):
    if common.isInSquare(sideA.corner.getAbsPosition(),
            sideB.corner.getAbsPosition(), 1):
        if not isConflict:
            if (sideA.color == sideB.color and not
                    sideA.isSnapped and not sideB.isSnapped):
                sideA.adjSide = sideB
                sideB.adjSide = sideA
                # If colors match and both sides aren't snapped, they
                # are added to a list of sides to snap if there is an
                # unclick
                sidesToSnap.append(sideA)
            else:
                if isDragging:
                    movers.noSnapMove(mouseLoc, selectedTiles)
                    isSnapped, sidesToSnap, snapdTile, isConflict = \
                            misc.unSnapAll(sidesToSnap)
                isConflict = True
        # If there has been a conflict with another tile in the group of
        # the tile who's side is being checked, then the tile is just
        # added to a list of tiles which have already been checked
        checkedTiles.append(sideB.tile)
    return isSnapped, sidesToSnap, snapdTile, isConflict