# representing circles, movement, etc... in the OOP style. def distance(x1,y1,x2,y2): cx = x1-x2 cy = y1=y2 return (cx*cx + cy*cy)**0.5 # distance function class circle: def __init__(self,x0,y0,r0): # initialize coordinates and radius self.x = x0 self.y = y0 self.radius = r0 self.dx = 0 # initial movement vector is also zero self.dy = 0 # contructor def movement(self,newdx,newdy): # set movement vector self.dx = newdx self.dy = newdy # movement def move(self): # change coordinates according to dx,dy self.x += self.dx self.y += self.dy # move def collision(self,B): #detect collision with circle B d = distance(self.x,self.y,B.x,B.y) if d <= self.radius + B.radius: return True else: return False # collision # class circle c1 = circle(4,5,10) c1.movement(3,3) c1.move() print c1.x, c1.y