Python Forum
[PyGame] Confused with Pygame documentation. (Newbie here)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Confused with Pygame documentation. (Newbie here)
#1
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!

# 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/
Reply


Messages In This Thread
Confused with Pygame documentation. (Newbie here) - by monkeydesu - Sep-10-2022, 04:07 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020