Here you download a gameobject library, which encapsulates the vector calculation
#_*_coding:utf-8_*_ fromGameobjects.vector2Import*Background_image_filename='./images/sea.jpg'Sprite_image_filename='./images/fish.png'ImportPygame fromPygame.localsImport* fromSysImportexitpygame.init () screen=pygame.display.set_mode (640,480), 0,32) Background=pygame.image.load (Background_image_filename). CONVERT () sprit=pygame.image.load (sprite_image_filename) Clock=Pygame.time.Clock () position=vector2 (100.0,100.0) Heading=Vector2 () whileTrue: forEventinchpygame.event.get ():ifevent.type==quit:exit () screen.blit (background, (0,0)) Screen.blit (sprit,position) time_passed_seconds=clock.tick ()/1000.0#arguments preceded by *: Expand the list or the meta-ancestorDestination=vector2 (*pygame.mouse.get_pos ())-vector2 (*sprit.get_size ())/2. Vector_to_mouse=vector2.from_points (position,destination) vector_to_mouse.normalize () heading=heading+ (VECTOR_TO_MOUSE/6) Position+=heading*time_passed_seconds pygame.display.update ()
Object follows mouse movement (with vector)