Sep-10-2022, 04:07 AM
(This post was last modified: Sep-10-2022, 06:45 AM by Yoriz.
Edit Reason: Added prefix
)
Sorry, I'm new and really confused by a few things with the tutorial I'm using. I've been looking for answers for like 3 hours. Please help!
The website I'm using:
https://realpython.com/pygame-a-primer/
# Define the enemy object by extending pygame.sprite.Sprite # The surface you draw on the screen is now an attribute of 'enemy' class Enemy(pygame.sprite.Sprite): def __init__(self): super(Enemy, self).__init__() self.surf = pygame.Surface((20, 10)) self.surf.fill((255, 255, 255)) self.rect = self.surf.get_rect( center=( random.randint(SCREEN_WIDTH + 20, SCREEN_WIDTH + 100), random.randint(0, SCREEN_HEIGHT), ) ) self.speed = random.randint(5, 20) # Move the sprite based on speed # Remove the sprite when it passes the left edge of the screen def update(self): self.rect.move_ip(-self.speed, 0) if self.rect.right < 0: self.kill()My confusion is in the last part...
self.rect.move_ip(-self.speed, 0)Why minus self for speed? And what is the zero for?
if self.rect.right < 0: self.kill()And what does the "right" here mean? I understand it's to wipe the sprite enemy from the screen. Does "right" mean the screen border or something? Super confused! )=
The website I'm using:
https://realpython.com/pygame-a-primer/