What's happening is that the apple instead of being moved down is actually being redrawn many times over at the new coordinates. It seems that you are using an inbuilt class so idk what methods it has since I normally create my own class. What would fix it is if you had your apple object created before the main loop. Then in the main loop call a method to move the apple by how many pixels you want then update the position by using screen.blit()
For example, You could create a class for your apples, the class would take 4 parameters: which pygame window, x coordinate, y coordinate, and a path to the apple image.
class Apple():
def __init__(self, place, x, y, path,):
self.place = place
self.x = x
self.y = y
self.path = path
def load(self):
screen.blit(self.path, (self.x, self.y))
def move(self):
if self.y > 0:
self.y = self.y - 4
else:
self.x = randint(0, 800)
self.y = randint(800, 1600)
You would then create the apple object:
path = "path_to_the_image_of_the_apple"
apple_x = random.randint(0, 800)
apple_y = random.randint(0, 800)
apple = Apple(screen, apple_x, apple_y, path)
In the main loop then call a method to first move the apple, apple.move()
then update the position apple.load()
Main loop:
#main game loop
while True:
#clear display
screen.fill(0)
#move call the function to move the apple
apple.move()
#updating the player
apple.load()
#update display
pygame.display.flip()
Note that in screen.blit(self.path, (self.x, self.y))
screen
is just my variable in my code. replace it with whatever yours is.