| 236 | |
| 237 | |
| 238 | class Objects: |
| 239 | def __init__(self): |
| 240 | # Initial location of the spaceship |
| 241 | self.x = 40 |
| 242 | self.y = (Display().windows.get_height() - Display.spaceship.get_width()) / 2 |
| 243 | # List of lasers |
| 244 | self.laser_list = [] |
| 245 | # List of enemies |
| 246 | self.enemies_list = [] |
| 247 | # How many initial enemies there should be |
| 248 | self.enemy_count = 3 |
| 249 | # Background location |
| 250 | self.background_list = [[0, 0], [1800, 0]] |
| 251 | self.score = 0 |
| 252 | # Condition |
| 253 | self.condition = 10 |
| 254 | |
| 255 | def objects(self): |
| 256 | # Background |
| 257 | Display().windows.fill((0, 0, 0)) |
| 258 | # Stars Background |
| 259 | self.background() |
| 260 | # Collision Box |
| 261 | self.collision_box() |
| 262 | # Space_Ship |
| 263 | Display().windows.blit(Display().spaceship, (self.x, self.y)) |
| 264 | # Laser |
| 265 | self.fire_laser() |
| 266 | # Enemies |
| 267 | self.enemies_movement() |
| 268 | # Score |
| 269 | self.score_board() |
| 270 | |
| 271 | def collision_box(self): |
| 272 | return pygame.Rect( |
| 273 | (self.x, self.y), |
| 274 | (Display().spaceship.get_width(), Display().spaceship.get_height()), |
| 275 | ) |
| 276 | |
| 277 | def background(self): |
| 278 | for location in self.background_list: |
| 279 | # Display the background |
| 280 | Display().windows.blit(Display().background, (location[0], location[1])) |
| 281 | # Change the x location of the background to give the illusion of movement |
| 282 | location[0] -= 2 |
| 283 | |
| 284 | if location[0] + Display().background.get_width() <= 0: |
| 285 | # Resets the location of the background if it's offscreen |
| 286 | index = self.background_list.index(location) |
| 287 | self.background_list[index][0] = ( |
| 288 | self.background_list[index - 1][0] + 1800 |
| 289 | ) |
| 290 | |
| 291 | def add_enemies(self): |
| 292 | # Adds enemy if score is more or equals than the limit |
| 293 | if self.score >= self.condition: |
| 294 | self.enemy_count += 1 |
| 295 | # Increase the limit |