Exemplo n.º 1
0
class GameScene(AbstractScene):

    """
    @type group: GameSceneGroup
    """
    group = None
    keyboard_moving_x, keyboard_moving_y = False, False
    map_object = None
    renderer = None
    camera = None

    _instance = None

    def __init__(self, manager):
        super().__init__(manager)
        self.map_group = GameSceneGroup(self)
        self.player = slg.entities.player.Player(self.map_group)
        self.player.set_manager(self._manager)

    def set_map(self, map_object):
        self.map_object = map_object
        self.player.set_map(self.map_object)
        self.renderer = map_object.get_renderer()
        self.camera = self._manager.get_camera()

    def handle_events(self, events):
        self._manager.get_camera().update()
        self._manager.get_camera().handle_events(events, self._manager)
        self.player.handle_events(events)
        for e in events:
            if e.type == KEYDOWN:
                self.handle_keypress(e.key, pygame.key.get_mods())

    def handle_keypress(self, key, modificated):
        if key == K_SPACE and self._manager.state < GAME_STATE_LOADING:
            ChangeState(int(not bool(self._manager.state))).post()

        if key == K_ESCAPE:
            GameMenu(self._manager.get_display(), self._manager, self.group)
            ChangeState(GAME_STATE_PAUSED).post()
        if key == K_o:
            print(self.map_object)
        # if key == K_c:
        #     print(self._manager.get_camera().get_dest(), self._manager.get_camera().get_dimensions(), self._manager.get_camera().get_bounds())

    def draw(self):
        self.map_object.update()
        self.map_group.update()
        # surf = pygame.Surface((32, 16), HWSURFACE | SRCALPHA)
        # surf.fill((0, 255, 0, 128))
        # rect = self.player.collide_rect
        # print(rect)
        # rect = self.map_object.get_renderer().map_to_screen_simple(rect)
        # rect = self.map_object.get_renderer().adjust_with_cam(rect)
        self._manager.get_display().fill((0, 0, 0))
        self.map_object.draw(self._manager.get_display())
Exemplo n.º 2
0
    def __init__(self, manager):
        """
        @type manager: slg.application.manager.Manager
        """
        super().__init__(manager)
        self.group = GameSceneGroup(self)
        image = pygame.image.load(os.path.join(GUI_DIR, 'loading_screen.jpg'))
        self.image = Surface(self._manager.get_display().get_size())
        self.rect = pygame.rect.Rect(self.image.get_rect())
        image_size = image.get_size()
        surface_size = self.image.get_size()
        x = int((image_size[0] - surface_size[0]) / 2)
        y = int((image_size[1] - surface_size[1]) / 2)
        if x < 0 and y < 0:
            image = pygame.transform.scale(image, surface_size)
            x, y = 0, 0
        elif x <= 0 <= y:
            image = pygame.transform.scale(image, (surface_size[0], image_size[1]))
            x = 0
        elif y <= 0 <= x:
            image = pygame.transform.scale(image, (image_size[0], surface_size[1]))
            y = 0
        styles = {'font': 'alger', 'font_size': 40, 'align': [TextWidget.CENTER, TextWidget.CENTER]}
        text = TextWidget(**styles)
        text.set_text("""Loading...
Please wait""")
        self.image.blit(image, (-x, -y))
        text.draw(self.image)
Exemplo n.º 3
0
 def __init__(self, manager):
     super().__init__(manager)
     self.group = GameSceneGroup(self)
     display_surface = self._manager.get_display()
     self.bg = pygame.Surface(display_surface.get_size())
     ChangeState(GAME_STATE_PAUSED).post()
     showMainText(display_surface, self.group)
     slg.ui.listview.ListView('Map list', [200, 200], display_surface, self.group)
Exemplo n.º 4
0
class MainMenuScene(AbstractScene):
    """
    @type image: SurfaceType
    @type rect: pygame.rect.RectType
    """

    image = None
    rect = None

    def __init__(self, manager):
        super().__init__(manager)
        self.group = GameSceneGroup(self)
        display_surface = self._manager.get_display()
        self.bg = pygame.Surface(display_surface.get_size())
        ChangeState(GAME_STATE_PAUSED).post()
        showMainText(display_surface, self.group)
        slg.ui.listview.ListView('Map list', [200, 200], display_surface, self.group)

    def handle_events(self, events):
        self.group.handle_events(events)
        for e in events:
            if e.type == KEYDOWN:
                self.handle_keypress(e.key, pygame.key.get_mods())

    def handle_keypress(self, key, modificated):
        if key == K_m and modificated & pygame.KMOD_ALT:
            Selector(self._manager.get_display(), self.group)
        if key == K_F1:
            showMainText(self._manager.get_display(), self.group)

    def draw(self):
        display_surface = self._manager.get_display()
        display_surface.blit(self.bg, (0, 0))
        self.group.update(display_surface)
        self.group.draw(display_surface)
Exemplo n.º 5
0
class LoadingScene(AbstractScene):
    """
    @type image: SurfaceType
    @type rect: pygame.rect.RectType
    """

    image = None
    rect = None

    def __init__(self, manager):
        """
        @type manager: slg.application.manager.Manager
        """
        super().__init__(manager)
        self.group = GameSceneGroup(self)
        image = pygame.image.load(os.path.join(GUI_DIR, 'loading_screen.jpg'))
        self.image = Surface(self._manager.get_display().get_size())
        self.rect = pygame.rect.Rect(self.image.get_rect())
        image_size = image.get_size()
        surface_size = self.image.get_size()
        x = int((image_size[0] - surface_size[0]) / 2)
        y = int((image_size[1] - surface_size[1]) / 2)
        if x < 0 and y < 0:
            image = pygame.transform.scale(image, surface_size)
            x, y = 0, 0
        elif x <= 0 <= y:
            image = pygame.transform.scale(image, (surface_size[0], image_size[1]))
            x = 0
        elif y <= 0 <= x:
            image = pygame.transform.scale(image, (image_size[0], surface_size[1]))
            y = 0
        styles = {'font': 'alger', 'font_size': 40, 'align': [TextWidget.CENTER, TextWidget.CENTER]}
        text = TextWidget(**styles)
        text.set_text("""Loading...
Please wait""")
        self.image.blit(image, (-x, -y))
        text.draw(self.image)

    def handle_events(self, events):
        self.group.handle_events(events)
        for e in events:
            if e.type == KEYDOWN:
                self.handle_keypress(e.key, pygame.key.get_mods())

    def handle_keypress(self, key, modificated):
        if key == K_SPACE and self._manager.state < GAME_STATE_LOADING:
            ChangeState(int(not bool(self._manager.state))).post()

        if key == K_m and modificated and pygame.KMOD_CTRL:
            Selector(self._manager.get_display(), self.group)
            ChangeState(GAME_STATE_PAUSED).post()

    def draw(self):
        display_surface = self._manager.get_display()
        display_surface.blit(self.image, (0, 0))
        self.group.update(display_surface)
        self.group.draw(display_surface)
Exemplo n.º 6
0
 def __init__(self, manager):
     super().__init__(manager)
     self.map_group = GameSceneGroup(self)
     self.player = slg.entities.player.Player(self.map_group)
     self.player.set_manager(self._manager)