MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / Enemies

Class Enemies

projects/Space Shooter/main.py:210–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208
209
210class Enemies:
211 def __init__(self):
212 # Place the enemies at random
213 self.x = random.randint(700, 1000)
214 self.y = random.randint(
215 0,
216 Display().windows.get_height() - Display().enemy_spaceship.get_height() + 1,
217 )
218 # Randomly select between two types of enemies
219 self.type = random.choice([1, 2])
220 # List for the location of the lasers/missiles
221 self.bullets_list = []
222 self.alive = True
223
224 def collision_box(self):
225 return pygame.Rect(
226 (self.x, self.y),
227 (
228 Display().enemy_spaceship.get_width(),
229 Display().enemy_spaceship.get_height(),
230 ),
231 )
232
233 def firing(self):
234 # Append the location of lasers/missiles
235 self.bullets_list.append([self.x, self.y])
236
237
238class Objects:

Callers 2

place_enemiesMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected