So I'm currently planning on making a relatively basic game which involves enemies making their way towards a player's "base" which will be located directly at the centre of the screen. I'm struggling to find a way in which I can spawn these enemies from all sides of the screen but only on the edges. Below is the basic class I have created for the enemy sprite and my attempt at trying to spawn them in a location that is on the outer part of the screen. For the most part it works, apart from the fact that it will never spawn any of the sprites at the bottom outer part of my screen since I'm unsure of how to make the Y coordinate a random number between 0,80 OR between 600,680. Also, this doesn't really seem like the most efficient way of assigning the X and Y values. Would appreciate any advice or help given. Screen dimensions I am using are 800x680, Thanks.
class Enemy(pygame.sprite.Sprite):
def __init__(self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((15,15))
self.image.fill(RED)
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
all_sprites = pygame.sprite.Group()
mobs = pygame.sprite.Group()
for i in range (10):
x = random.randint(0,800)
if x < 100 or x > 700:
y = random.randint(0,680)
else:
y = random.randint(0,80)
m = Enemy(x,y)
all_sprites.add(m)
mobs.add(m)