Exemplo n.º 1
0
class Game:
    """This class represents the highest level of the game logic, managing the
    other more specific components of the game."""
    def __init__(self, core):
        self.core = core
        self.running = True

        self.screen = pygame.display.get_surface()

        self.controller = Controller()
        
        self.main_menu = MainMenu(self)
        self.game_menu = GameMenu(self)

        self.show_main_menu = True
        self.show_game_menu = False

        self.battles = []
        self.targets = []
        self.terrain = []

        ########
        from world_model import Terrain
        terrain_image = self.core.get_image("canister_apartment.png")
        test_terrain = Terrain()
        test_terrain.add_image(terrain_image)
        test_terrain.zone = "apartment"
        self.terrain.append(test_terrain)
        ########

        self.zone = Zone(self, "apartment")
        self.dialogue = None

    def fast_step(self):
        self.update()

    def step(self):
        self.update()
        self.draw()
        
    def update(self):
        for event in pygame.event.get(pygame.QUIT):
            if event.type == pygame.QUIT:
                self.running = False

        self.controller.update()

        if self.controller.just_pressed("START"):
            self.show_main_menu = not self.show_main_menu

        if self.show_main_menu:
            self.main_menu.update()
            return

        if self.show_game_menu:
            self.game_menu.update()
            if self.controller.just_pressed("Y"):
                self.show_game_menu = False
            return

        if self.dialogue is not None:
            self.dialogue.update()
        elif self.zone is not None:
            self.zone.update()

        if self.controller.just_pressed("Y"):
            self.show_game_menu = True

    def draw(self):
        self.screen.fill((0, 0, 0))

        if self.zone is not None:
            self.zone.draw()

        if self.dialogue is not None:
            self.zone.draw()
        
        if self.show_game_menu:
            self.game_menu.draw()

        if self.show_main_menu:
            self.main_menu.draw()