I'm pretty new to python and just started learning to build my first game. A tutorial I was watching got an image to move along with the mouse pointer. I had already worked out my own version of it before following his tutorial, and I guess I am just wondering if the difference in the two codes are simply down to personal choice or if there is a particular benefits of using his format over what I did. I realise for this specific action it is probably irrelevant in the grand scheme of things, but I am just thinking more about in general as I build my own coding practices and style.

I kinda see pro's and con's to both in that his might be easier to test if things need debugging as the variables can be adjusted and it's maybe seen as more readable. But in very large software I assume efficiency and saving on characters would possibly counts.

His...

       if event.type == pygame.MOUSEMOTION and event.buttons[0] == 1:
            mouse_x = event.pos[0]
            mouse_y = event.pos[1]
            zombie_DBS_rect.centerx = mouse_x
            zombie_DBS_rect.centery = mouse_y

mine...

       if event.type == pygame.MOUSEMOTION and event.buttons[0] == 1:
            zombie_DBS_rect.center = pygame.mouse.get_pos()
0

There are 0 best solutions below