Pygame independent moving images on the screen
Question: I am new to Python and Pygame. I want to have a screen in pygame with multiple
copies of the same images moving around independently. I have tried to write
it as a class and then call instances of it inside the `while` loop, but it
doesn't work. Could someone show how can i basically do such a thing using a
`class`?


Answer: I've tried to keep everything simple

Example:

    
    
    import pygame
    pygame.init()
    
    WHITE = (255,255,255)
    BLUE = (0,0,255)
    window_size = (400,400)
    screen = pygame.display.set_mode(window_size)
    clock = pygame.time.Clock()
    
    class Image():
        def __init__(self,x,y,xd,yd):
            self.image = pygame.Surface((40,40))
            self.image.fill(BLUE)
            self.x = x
            self.y = y
            self.x_delta = xd
            self.y_delta = yd
        def update(self):
            if 0 <= self.x + self.x_delta <= 360:
                self.x += self.x_delta
            else:
                self.x_delta *= -1
            if 0 <= self.y + self.y_delta <= 360:
                self.y += self.y_delta
            else:
                self.y_delta *= -1
            screen.blit(self.image,(self.x,self.y))
    
    list_of_images = []
    list_of_images.append(Image(40,80,2,0))
    list_of_images.append(Image(160,240,0,-2))
    
    done = False
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
        screen.fill(WHITE)
        for image in list_of_images:
            image.update()
        pygame.display.update()
        clock.tick(30)
    
    pygame.quit()
    

Each image can be called individually from the list and moved by simply
changing Image.x/y to whatever you want

