class Ball:
    def __init__ (self, x, y, dx, dy, radius, xMax, yMax):
        self.x = x
        self.y = y
        self.dx = dx
        self.dy = dy
        self.radius = radius
        self.xMin = radius
        self.yMin = radius
        self.xMax = xMax - radius
        self.yMax = yMax - radius

    def update (self):
        xNew = self.x + self.dx
        yNew = self.y + self.dy

        if xNew < self.xMin or xNew > self.xMax:
            self.dx = - self.dx
            xNew += 2 * self.dx
        if yNew < self.yMin or yNew > self.yMax:
            self.dy = - self.dy
            yNew += 2 * self.dy
        
        self.x = xNew
        self.y = yNew
