def scalePosition(self, scale): self.position = common.myMult(scale, self.absPosition) if self.isMovable: self.position = common.myAdd(self.position, (self.myCanvas.windowSurface.get_width() / 2, self.myCanvas.windowSurface.get_height() / 2)) else: self.position = common.myAdd(self.position, common.myMult(Canvas.scale, (self.image.get_width() / 2, self.image.get_height() / 2))) self.resize(scale)
def snapTiles(selectedTile, snapdSide, adjSide): snapdTile = snapdSide.tile for tile in selectedTile.tileGroup: tile.groupOffset = common.mySub(tile.absPosition, snapdTile.absPosition) for tile in selectedTile.tileGroup: tile.matchCorner(snapdSide.corner, common.myAdd(adjSide.corner.getAbsPosition(), tile.groupOffset)) snapdTile.adjTile = adjSide.tile snapdTile.adjTile.adjTile = snapdTile isSnapped = True return isSnapped, snapdTile, snapdSide
def moveUnSnappable(myCanvas, mouseLoc, selectedTiles, selectedTile, isSnapped, sidesToSnap, snapdTile, tiles): # Checks each side of one of the tiles which is snapped but can # potentially still be unsnapped. If the distance between this # tile and another tile is enough, the tiles unsnap for side in snapdTile.sides: if (side.adjSide is not None and common.getDistance(common.myAdd( common.mySub(mouseLoc, snapdTile.mouseOffset), side.corner.getOffset()), side.adjSide.corner.getPosition()) > objects.Canvas.SNAP_DISTANCE * objects.Canvas.scale + 1): isSnapped, sidesToSnap, snapdTile = moveUnSnap(myCanvas, mouseLoc, selectedTiles, selectedTile, sidesToSnap, tiles) break return (isSnapped, sidesToSnap, snapdTile)
def getAbsPosition(self): return map(int, map(round, common.myAdd(self.tile.absPosition, self.offset)))