Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init_asteroids():
for i in range(ASTEROID_COUNT):
asteroid = Asteroid(batch)
position = random.choice([0,1])
if position == 0:
asteroid.x = random.randint(0, window.width)
asteroid.y = random.choice([0, window.height])
else:
asteroid.x = random.choice([0, window.width])
asteroid.y = random.randint(0, window.height)
asteroid.x_speed = random.choice([-1,1]) * random.randint(ASTEROID_MIN_SPEED,ASTEROID_MAX_SPEED)
asteroid.y_speed = random.choice([-1,1]) * random.randint(ASTEROID_MIN_SPEED,ASTEROID_MAX_SPEED)
objects.append(asteroid)
def init_asteroids():
for i in range(ASTEROID_COUNT):
asteroid = Asteroid()
position = random.choice([0,1])
if position == 0:
asteroid.x = random.randint(0, window.width)
asteroid.y = random.choice([0, window.height])
else:
asteroid.x = random.choice([0, window.width])
asteroid.y = random.randint(0, window.height)
asteroid.x_speed = random.choice([-1,1]) * random.randint(ASTEROID_MIN_SPEED,ASTEROID_MAX_SPEED)
asteroid.y_speed = random.choice([-1,1]) * random.randint(ASTEROID_MIN_SPEED,ASTEROID_MAX_SPEED)
objects.append(asteroid)
def asteroids(num_asteroids, player_position, batch=None):
"""Generate asteroid objects with random positions and velocities, not close to the player"""
asteroids = []
for i in range(num_asteroids):
asteroid_x, asteroid_y = player_position
while util.distance((asteroid_x, asteroid_y), player_position) < 100:
asteroid_x = random.randint(0, 800)
asteroid_y = random.randint(0, 600)
new_asteroid = asteroid.Asteroid(x=asteroid_x, y=asteroid_y, batch=batch)
new_asteroid.rotation = random.randint(0, 360)
new_asteroid.velocity_x, new_asteroid.velocity_y = random.random()*40, random.random()*40
asteroids.append(new_asteroid)
return asteroids
def init_asteroids():
for i in range(ASTEROID_COUNT):
asteroid = Asteroid(batch, objects)
position = random.choice([0,1])
if position == 0:
asteroid.x = random.randint(0, window.width)
asteroid.y = random.choice([0, window.height])
else:
asteroid.x = random.choice([0, window.width])
asteroid.y = random.randint(0, window.height)
asteroid.x_speed = random.choice([-1,1]) * random.randint(ASTEROID_MIN_SPEED,ASTEROID_MAX_SPEED)
asteroid.y_speed = random.choice([-1,1]) * random.randint(ASTEROID_MIN_SPEED,ASTEROID_MAX_SPEED)
def asteroids(num_asteroids, player_position, batch):
"""Generate asteroid objects with random positions and velocities, not close to the player"""
asteroids = []
for i in range(num_asteroids):
asteroid_x, asteroid_y = player_position
while util.distance((asteroid_x, asteroid_y), player_position) < 100:
asteroid_x = random.randint(0, 800)
asteroid_y = random.randint(0, 600)
new_asteroid = asteroid.Asteroid(x=asteroid_x, y=asteroid_y, batch=batch)
new_asteroid.rotation = random.randint(0, 360)
new_asteroid.vx, new_asteroid.vy = random.random()*40, random.random()*40
asteroids.append(new_asteroid)
return asteroids