Python Forum
Setting up a health system.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting up a health system.
#2
BoatSprite class add health variable.
self.health = 3
For your groups you can have on for boat enemies.
        self.bullet_group = pygame.sprite.Group()
        self.pirate_group = pygame.sprite.Group()
        self.croc_group = pygame.sprite.Group()
Can be replace by.
self.boat_enemies_group = pygame.sprite.Group()
Then boat losing a life. Check all objects in the list. Returns all objects that boat collided with.
# Colliding
        hit = pygame.sprite.spritecollide(self.boat, self.boat_enemies_group, False)
        if len(hit) > 0:
            self.boat.health -= 1
            if self.boat.health == 0:
                # boat dies
All your draw code for the scene should be under draw method.
    self.surface.blit(self.heart, (600, 20))
    self.surface.blit(self.heart, (600, 50))
    self.surface.blit(self.heart, (600, 80))
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Setting up a health system. - by ghost0fkarma - Mar-19-2019, 02:14 PM
RE: Setting up a health system. - by Windspar - Mar-19-2019, 05:45 PM

Forum Jump:

User Panel Messages

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