I made a pygame.sprite.group for my enemies. I can display them on the screen, but I don't know how to make them all move? I want to have them pacing back and forth on the platforms (like left and right constantly). I know how to work with the movements of one sprite, but not a bunch in a group.
Here is what I have right now:
class Platform(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('levoneplatform.png')
self.rect = self.image.get_rect()
class Enemy(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('enemy.png')
self.rect = self.image.get_rect()
class LevOne():
def __init__(self):
self.background_image = pygame.image.load('night.png').convert_alpha()
platforms_one = [ (200,300),
(50,500),
(550,650),
(300,200),
(120,100)
]
for k,v in platforms_one:
platform = Platform()
enemy = Enemy()
platform.rect.x = k
enemy.rect.x = k
platform.rect.y = v
enemy.rect.y = v - 44
platform_list.add(platform)
enemy_list.add(enemy)
def update(self):
screen.blit(self.background_image, [0, 0])
screen = pygame.display.set_mode((800,600))
enemy_list = pygame.sprite.Group()
platform_list = pygame.sprite.Group()
The rest is basically like my state changes and updates. I don't know how to move the entire sprite group. I know how to move one sprite, but not a bunch of sprites in one list.