Example #1
0
    def __init__(self):
        self._init_pygame()

        # creates a display surface. Images in Pygame are represented by surfaces.
        # Here are a few things to know about them:
        #    x Surfaces can be drawn on one another, allowing you to create complex
        #      scenes from simple pictures.
        #
        #    x There’s one special surface in each Pygame project. That surface represents
        #      the screen and is the one that will eventually be displayed to players.
        #      All other surfaces have to be drawn on this one at some point.
        #      Otherwise, they won’t be shown.
        #
        #    x To create the display surface, your program uses pygame.display.set_mode().
        #      The only argument you pass to this method is the size of the screen,
        #      represented by a tuple of two values: width and height.
        #      In this case, Pygame will create a screen with a width of 800 pixels
        #      and a height of 600 pixels.
        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_ASTEROID_DISTANCE):
                    break
            self.asteroids.append(Asteroid(position, self.asteroids.append))
Example #2
0
    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))
Example #3
0
    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))
Example #4
0
    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))
Example #5
0
    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 = ''
Example #6
0
 def __init__(self):
     self.score = 0
     self._init_pygame()
     self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
     self.background = load_sprite("space1", False)
     self.background_game_music = load_sound("game_play_music")
     self.game_over_music = load_sound("game_over_music")
     self.clock = pygame.time.Clock()
     self.font = pygame.font.Font(None, 64)
     self.message = ""
     self.meteroids = []
     self.bullets = []
     self.spaceship = Spaceship((400, 300), self.bullets.append)
     
     for _ in range(4):
         while True:
             pos = get_random_position(self.screen)
             if pos.distance_to(self.spaceship.position) > self.MIN_METEROID_DIS:
                 break
         self.meteroids.append(Meteroid(pos, self.meteroids.append))
Example #7
0
    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))
Example #8
0
    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))