I'm trying to create a simple game where u have to dodge enemies(asteroids), with pygame, but now I'm having trouble spawning them and I don't know if i should use lists or other things, or the enemy class(asteroidClass) is enough. The interval between spawning them is pretty simple I just don't how to deal with the spawn part (dealing with this for 3 days).
import pygame
import random
pygame.init()
#images
background = pygame.image.load('#path')
asteroid = pygame.image.load('#path')
display = pygame.display.set_mode((300,500))
FPS = 50
display.blit(background,(0,0))
#player everything is fine
#asteroid
class asteroidClass:
def __init__(self,asteroidX,asteroidY,asteroidVel):
self.x = asteroidX
self.y = asteroidY
self.vel = asteroidVel
def asteroid_advancing(self):
self.y += self.vel
display.blit(asteroid, (self.x, self.y))
def update():
pygame.display.update()
pygame.time.Clock().tick(FPS)
#variables
asteroidX = random.randint(0,250)
asteroidY, asteroidVel = 0, 2
asteroidOutClass = asteroidClass(asteroidX,asteroidY,asteroidVel)
#main loop
run = True
while run:
#should spawn multiple I don't know with what logic
#spawning in the same x
#saw in web they're using lists, maybe i should too?
#when i print i it just do 0123456 like it should, then restart to 0123456, is it wrong? kinda 100%
for i in range(7):
asteroidOutClass.asteroid_advancing() #everytime it's called should spawn and asteroid in random x?
update()
display.blit(background, (0, 0))