def __init__(self): self._init_pygame() self.screen = screenSize(1000, 700) self.background = load_sprite("space", False) self.clock = pygame.time.Clock() self.font = pygame.font.Font(None, 64) self.message = "" self.destroyed_small = 0 self.score = 0 self.scoretext = self.font.render("Score = " + str(self.score), 1, (255, 0, 0)) file = 'C://Users//ActionICT//PycharmProjects//Asteroids//assets//music//jlbrock44_-_Stars_Below_Us.mp3' pygame.init() pygame.mixer.init() pygame.mixer.music.load(file) pygame.mixer.music.play( -1) # If the loops is -1 then the music will repeat indefinitely. self.asteroids = [] self.bullets = [] self.spaceship = Spaceship((400, 300), self.bullets.append) for _ in range(6): while True: position = get_random_position(self.screen) if (position.distance_to(self.spaceship.position) > self.MIN_ASTEROID_DISTANCE): break self.asteroids.append(Asteroid(position, self.asteroids.append))
def __init__(self): self._init_pygame() # Adjust Screen Size self.screen = pygame.display.set_mode((800, 600)) # Customize Game Background self.background = load_sprite("industrial-background", False) self.clock = pygame.time.Clock() self.font = pygame.font.Font(None, 64) self.message = "" self.asteroids = [] self.bullets = [] # Adjust player starting position: Spaceship((x, y)) # Center of screen: (400, 300) # Far left center of screen: (20, 300) self.spaceship = Spaceship((100, 490), self.bullets.append) # Adjust number fo initial spawned asteroids: for _ in range(x) for _ in range(6): while True: position = get_random_position(self.screen) if (position.distance_to(self.spaceship.position) > self.MIN_ASTEROID_DISTANCE): break self.asteroids.append(Asteroid(position, self.asteroids.append))
def spawn_food(self, position=0): if position == 0: while True: position = get_random_position(self.screen) if self.snake: if not self.snake.collides_with(position): break else: break self.food.insert(0, Food(position))
def _process_game_logic(self): for game_object in self._get_game_objects(): game_object.move(self.screen) if self.spaceship: for asteroid in self.asteroids: if asteroid.collides_with(self.spaceship): self.spaceship = None #Sound('C:/Users/ActionICT/PycharmProjects/Asteroids/assets/sounds/Blastwave_FX_BankSafeExplosion_HV.37.mp3').play() self.message = FinalScreen.PROTOTYPE_FINAL_DISPLAY.format( FinalScreen.LOST_MESSAGE, FinalScreen.MESSAGE_ESC_OR_CONTINUE) + ' ' + str( self.score) break for bullet in self.bullets[:]: for asteroid in self.asteroids[:]: if asteroid.collides_with(bullet): if asteroid.size == 1: Sound( 'C:/Users/ActionICT/PycharmProjects/Asteroids/assets/sounds/firework_explosion_001.mp3' ).play() self.destroyed_small += 1 if self.destroyed_small == 4: while True: position = get_random_position(self.screen) if (position.distance_to( self.spaceship.position) > self.MIN_ASTEROID_DISTANCE): break self.destroyed_small = 0 self.asteroids.append( Asteroid(position, self.asteroids.append)) elif asteroid.size == 3: Sound( 'C:/Users/ActionICT/PycharmProjects/Asteroids/assets/sounds/zapsplat_explosion_large.mp3' ).play() else: Sound( 'C:/Users/ActionICT/PycharmProjects/Asteroids/assets/sounds/boom.mp3' ).play() self.asteroids.remove(asteroid) self.bullets.remove(bullet) asteroid.split() self.score += 10 break for bullet in self.bullets[:]: if not self.screen.get_rect().collidepoint(bullet.position): self.bullets.remove(bullet) if not self.asteroids and self.spaceship: self.message = FinalScreen.PROTOTYPE_FINAL_DISPLAY.format( FinalScreen.WON_MESSAGE, FinalScreen.MESSAGE_ESC_OR_CONTINUE)
def __init__(self): self._init_pygame() self.screen = pygame.display.set_mode((800, 600)) self.background = load_sprite("space", False) self.clock = pygame.time.Clock() self.asteroids = [] self.spaceship = Spaceship((400, 300)) for _ in range(6): while True: position = get_random_position(self.screen) if (position.distance_to(self.spaceship.position) > self.MIN_ASTEROID_DISTANCE): break self.asteroids.append(Asteroid(position))
def __init__(self) -> None: self._init_pygame() self.screen = pygame.display.set_mode((800, 600)) self.background = load_sprite(name='space', with_alpha=False) self.bullets = [] self.asteroids = [] self.spaceship = Spaceship((400, 300), self.bullets.append) for _ in range(6): while True: position = get_random_position(self.screen) if (position.distance_to(self.spaceship.position) > self.MIN_ASTEROID_DISTANCE): break self.asteroids.append(Asteroid(position, self.asteroids.append)) self.clock = pygame.time.Clock() self.font = pygame.font.Font(None, 64) self.message = ''
def __init__(self): # Call a private initialization method self._init_pygame() self.screen = pygame.display.set_mode((800, 600)) self.background = load_sprite("space", False) self.clock = pygame.time.Clock() # Ensure stable FPS self.font = pygame.font.Font(None, 64) self.message = "" self.asteroids = [] self.bullets = [] self.spaceship = Spaceship((400, 300), self.bullets.append) for _ in range(6): while True: position = get_random_position(self.screen) if (position.distance_to(self.spaceship.position) > self.MIN_ASTEROID_DISTANCE): break self.asteroids.append(Asteroid(position, self.asteroids.append))
def __init__(self): self._init_pygame() self.screen = pygame.display.set_mode((800, 600)) self.background = load_sprite("space", False) self.clock = pygame.time.Clock() self.font = pygame.font.Font(None, 64) self.message = "" self.asteroids = [] self.bullets = [] self.spaceship = Spaceship((400, 300), self.bullets.append) for _ in range(6): while True: position = get_random_position(self.screen) if ( position.distance_to(self.spaceship.position) > self.min_distance ): break self.asteroids.append(Asteroid(position, self.asteroids.append))