示例#1
0
    def __init__(self, number_of_enemies, enemy_type, batch):
        GameItem.__init__(self)
        self.enemies = []
        self.number_of_enemies = number_of_enemies
        self.left_x_bound = 200
        self.right_x_bound = 800
        self.top_y_bound = 650
        self.bottom_y_bound = 200
        self.x = self.left_x_bound
        self.y = self.top_y_bound
        self.remove_from_game = False

        # make sure that when you generate enemies,
        # you generate them in the correct configuration
        y_offset = self.top_y_bound
        row = 0
        for i in range(0, number_of_enemies):
            next_enemy_x = int(self.left_x_bound)
            while not next_enemy_x >= self.right_x_bound and len(self.enemies) < self.number_of_enemies:
                next_enemy_y = y_offset
                self.enemies.append(Enemy(resources.enemy_resources[enemy_type],
                                          row=row,
                                          x=next_enemy_x,
                                          y=next_enemy_y,
                                          batch=batch))
                next_enemy_x += ENEMY_MARGIN[0]
            y_offset -= int(ENEMY_MARGIN[1])
            row += 1
 def __init__(self, sprite):
     GameItem.__init__(self)
     self.velocity_x, self.velocity_y = 0.0, 0.0
     self.scale = SPRITE_SCALE
     self.sprite = sprite
     self.sprite.scale = SPRITE_SCALE
     self.sprite.x = self.sprite.x
     self.sprite.y = self.sprite.y
示例#3
0
 def __init__(self):
     GameItem.__init__(self)
     self.score = 0
     self.label = pyglet.text.Label(
         "score " + "{0:09d}".format(self.score),
         font_name="sans-serif",
         font_size=26,
         x=WINDOW_SIZE[0] - 200,
         y=WINDOW_SIZE[1] - 50,
         anchor_x="center",
         anchor_y="center",
         batch=self.game.graphics_batch,
     )
示例#4
0
 def __init__(self, lives):
     GameItem.__init__(self)
     self.lives = lives
     self.label = pyglet.text.Label(
         "lives {}".format(self.lives),
         font_name="sans-serif",
         font_size=26,
         x=WINDOW_SIZE[0] - 900,
         y=WINDOW_SIZE[1] - 50,
         anchor_x="center",
         anchor_y="center",
         batch=self.game.graphics_batch,
     )
    def __init__(self):
        GameItem.__init__(self)
        self.labels = []
        self.labels.append(pyglet.text.Label('SPACE INVADERS-LIKE GAME!',
                                        font_name='sans-serif',
                                        font_size=36,
                                        x=WINDOW_SIZE[0]//2,
                                        y=WINDOW_SIZE[1]//2,
                                        anchor_x='center',
                                        anchor_y='center',
                                        batch=self.game.graphics_batch))

        self.labels.append(pyglet.text.Label('press any key',
                                        font_name='sans-serif',
                                        font_size=26,
                                        x=WINDOW_SIZE[0]//2,
                                        y=WINDOW_SIZE[1]//2 - 100,
                                        anchor_x='center',
                                        anchor_y='center',
                                        batch=self.game.graphics_batch))
        self.win.push_handlers(self.on_key_press)
    def __init__(self):
        GameItem.__init__(self)
        self.new_objects = []
        self.labels = []
        self.labels.append(pyglet.text.Label('YOU LOST!',
                                        font_name='sans-serif',
                                        font_size=36,
                                        x=WINDOW_SIZE[0]//2,
                                        y=WINDOW_SIZE[1]//2,
                                        anchor_x='center',
                                        anchor_y='center',
                                        batch=self.game.graphics_batch))

        self.labels.append(pyglet.text.Label('press any key to play again',
                                        font_name='sans-serif',
                                        font_size=26,
                                        x=WINDOW_SIZE[0]//2,
                                        y=WINDOW_SIZE[1]//2 - 100,
                                        anchor_x='center',
                                        anchor_y='center',
                                        batch=self.game.graphics_batch))
        self.win.push_handlers(self.on_key_press)