I'm making a pygame, survive the hord type game. I have it set up to where enemy's will walk towards the player. If they hit the player, they take some of his health. if the player shoots them, they die/disappear, and the player gets a point or two.
I want the enemy's to all spawn off screen within a certain distance, and then walk onto screen so that you don't start the game with enemy's 5 pixels away, or on top of you.
I thought of trying to create an if statement, that only adds the enemy to the sprite list if they are not within a certain range, but then many sprites won't spawn at all, removing my ability to control the actual number of enemy's that spawn.
Below is the structure of how I am spawning enemy's. As you can see, some are spawing off screen as far as 200 pixels away in any direction, which is good, but they can also spawn right on top of my player.
In case you are wondering, the inputs for my Enemy_1pt class are (image,speed,health)
for i in range(10):
enemy_1pt = Enemy_1pt(fire_drake_image,1.5,1)
enemy_1pt.rect.x = random.randrange(-200,screen_width+200)
enemy_1pt.rect.y = random.randrange(-200,screen_height+200)
enemy_1pt_list.add(enemy_1pt)
all_sprites_list.add(enemy_1pt)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…