def _reset(self):

        self.spaceship = Spaceship()
        self.aliens.reset()
        self.barricades = Barricades()
        self.score = Score()
        self.life_counter = LifeCounter()

        self.is_game_over = False
        self.delay_since_game_over = 0
        self.is_playing = True
    def __init__(self):

        # We create a surface in which sprites will be shown
        self.window_surface = pygame.display.set_mode(WINDOW_SIZE)

        # Variables for game loop
        self.update_time_delay = 0
        self.draw_time_delay = 0

        # Game state variable
        self.is_game_over = False
        self.delay_since_game_over = 0
        self.is_playing = True

        # We create the game entities
        self.spaceship = Spaceship()
        self.aliens = Aliens()
        self.ground = Ground()
        self.barricades = Barricades()
        self.score = Score()
        self.high_score = HighScore()
        self.life_counter = LifeCounter()
        self.game_over = GameOver()
示例#3
0
def run(screen):
    """main game"""
    show_fps = True if '--fps' in sys.argv else False
    show_rects = True if '--show_rects' in sys.argv else False
    fps = 60 if '--no_limit' in sys.argv else 240
    fuel = 10000
    ground = location.Ground(450)
    background = location.Background()
    box = pygame.Rect((-100, 10), (1100, 600))
    lunar_module = LunarModule((400, 100), 1.62, fuel)
    lunar_module.set_box(box)
    controll_panel = ControllPanel((700, 20))
    ui_score = Score((10, 10))
    cm_rect = pygame.Rect((0, 0), screen.get_size())
    running = True
    boulders = gen_landscape(box.bottom, location.Boulder,
                             (box.left, box.right))
    fps_clock = pygame.time.Clock()
    deltat = 0
    score = 0
    stop_timer = None
    landing_points = pygame.sprite.Group()
    game_over_text = GameOverText()
    game_over_sound = pygame.mixer.Sound("sound/game_over.ogg")

    while running:
        pygame.event.pump()
        events = pygame.event.get()
        keys_pressed = pygame.key.get_pressed()
        for event in events:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                running = False
            elif event.type == pygame.QUIT:
                sys.exit()
        if stop_timer and stop_timer.has_expired():
            running = False
        #update lunarmodule and camera_position
        update_lm(lunar_module, events, keys_pressed)
        lunar_module.update(deltat, boulders, SOUND)
        cm_rect.center = lunar_module.rect.center

        #location
        screen.blit(background.image, background.rect)
        ground.update(cm_rect)
        advanced_draw(screen, ground.image, ground.rect, show_rects, cm_rect)
        #landing points
        score += manage_lps(lunar_module, landing_points)
        draw_group(landing_points, screen, cm_rect, show_rects)
        #draw boulders
        draw_group(boulders, screen, cm_rect, show_rects)
        #draw lunar module
        advanced_draw(screen, lunar_module.shadow.image,
                      lunar_module.shadow.rect, show_rects, cm_rect)
        draw(screen, lunar_module.image,
             lunar_module.image.get_rect(center=(400, 300)), show_rects)
        if show_rects:
            box_rect = local_rect(lunar_module.box, cm_rect)
            pygame.draw.rect(screen, (255, 255, 255), box_rect, 2)
            lm_rect = local_rect(lunar_module.rect, cm_rect)
            pygame.draw.rect(screen, (255, 255, 255), lm_rect, 2)
        #controllpanel
        velocity = math.sqrt(lunar_module.velocity[0]**2 +
                             lunar_module.velocity[1]**2)
        direction = math.degrees(
            math.atan2(lunar_module.velocity[1], lunar_module.velocity[0]))
        direction = 270 - direction
        if lunar_module.velocity[1] == lunar_module.velocity[0] == 0:
            direction = 0
        controll_panel.update(lunar_module.altitude, velocity, direction,
                              lunar_module.fuel / float(fuel))
        draw(screen, controll_panel.image, controll_panel.rect, show_rects)
        ui_score.update(score)
        screen.blit(ui_score.image, ui_score.position)
        if lunar_module.game_over:
            if not stop_timer:
                stop_timer = Timer(5)
                pygame.mixer.Channel(0).fadeout(2)
                if SOUND: game_over_sound.play()
            game_over_text.update(1 + stop_timer.get_state())
            advanced_draw(screen, game_over_text.image, game_over_text.rect,
                          show_rects)
        deltat = fps_clock.tick(fps) / 1000.0
        if show_fps:
            print 1 / deltat
        pygame.display.update()
    check_score(score, SCREEN)