1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Raindrop is not going down but repeating itself [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024 às 07:32.

  1. Stack

    Stack Membro Participativo

    [​IMG]

    I am doing exercise from a python book with Pygame, and I need to make the raindrop with x-coordinate and y-coordinate 0 fall down from top to bottom. But it keeps repeating itself with the y-coordinate changing, just like the picture shows. I have no idea how to deal with it since there is no error.

    Version: Pygame 2.6.0 (SDL 2.28.4, Python 3.11.9)

    raindrop.py

    import sys

    import pygame
    from pygame.sprite import Group

    from rain import Rain

    def rain_drop():
    # Initialize a pygame screen
    pygame.init()
    screen = pygame.display.set_mode((1000, 600))
    pygame.display.set_caption('Rain Drop')

    # Create a raindrop
    rain = Rain(screen)

    # Main loop
    while True:
    # Watch for keyboard and mouse event
    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    sys.exit()
    if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_q:
    sys.exit()

    # Redraw the screen
    rain.blitme()
    rain.update()
    pygame.display.flip()

    rain_drop()


    rain.py

    import pygame
    from pygame.sprite import Sprite

    class Rain(Sprite):
    def __init__(self, screen):
    super().__init__()
    self.screen = screen
    self.image = pygame.image.load('images/raindrop.webp')

    self.rect = self.image.get_rect()
    self.screen_rect = self.screen.get_rect()

    self.rect.x = 0
    self.rect.y = 0

    self.x = float(self.rect.x)
    self.y = float(self.rect.y)

    def blitme(self):
    self.screen.blit(self.image, self.rect)

    def update(self):
    self.y += 100
    self.rect.y = self.y

    Continue reading...

Compartilhe esta Página