Skip to content

Commit d396037

Browse files
committed
spawning considers player position
1 parent 5f26857 commit d396037

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

static/scripts/asteroid.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def should_be_removed(self):
137137

138138

139139
class AsteroidAttack:
140-
def __init__(self, spritesheet, width: int, height: int, max_size_px: float, spawnrate: int = 500):
140+
def __init__(self, spritesheet, width: int, height: int, max_size_px: float, spawnrate: int = 500, spawn_at_player_chance: int = 10):
141141
self.sheet = spritesheet
142142
self.w = width
143143
self.h = height
@@ -150,7 +150,7 @@ def __init__(self, spritesheet, width: int, height: int, max_size_px: float, spa
150150
self._use_grow_rate = 6.0 # default growth rate (how fast they appear to approach the player)
151151
self._use_health = 450 # default durability (affects asteroids being destroyed by impacts w/ player)
152152
self._use_damage_mul = 1.0
153-
153+
self.spawn_at_player_chance = spawn_at_player_chance
154154
def _spawn_one(self):
155155
# Don't spawn if at the limit
156156
if len(self.asteroids) >= self._max_asteroids:
@@ -159,9 +159,13 @@ def _spawn_one(self):
159159
# Planet area (left side)
160160
planet_width = self.w * 0.3
161161
space_start_x = planet_width + 50
162-
163-
x = random.uniform(space_start_x, self.w)
164-
y = random.uniform(0, self.h)
162+
if random.randint(1, self.spawn_at_player_chance) == 1:
163+
print("spawning at player")
164+
x = window.player.x
165+
y = window.player.y
166+
else:
167+
x = random.uniform(space_start_x, self.w)
168+
y = random.uniform(0, self.h)
165169

166170
if x < (SCREEN_W / 2):
167171
velocity_x = random.uniform(-15, -5)

0 commit comments

Comments
 (0)