예제 #1
0
def play_welcome(screen):
    scenes = []

    logo = '''
         ░░░░░░░░░░░░░░░░░░░
        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
       ▒▒▒▒    ╱ o o ╲    ▒▒▒▒
   ▓▓▓ ▒▒▒▒    ╲_╰─╯_╱    ▒▒▒▒ ▓▓▓
      ╲▒▒▒▒     ╱   ╲     ▒▒▒▒╱
       ░░░░░░░░░░░░░░░░░░░░░░░
       ▓▓╳╳▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╳╳▓▓
       ▓▓▓▓▓═╣╠═╣╠═╣╠═╣╠═▓▓▓▓▓
       ▓▓▓▓╠═╣╠═╣╠═╣╠═╣╠═╣▓▓▓▓
       ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
          ╿___╿       ╿___╿'''

    Welcome = 'Welcome to this program\npress x to continue'

    effects = [
        Print(screen, StaticRenderer(images=[logo]), 2),
        Print(screen, FigletText('Car Rental', font='big'), 14),
        Print(screen,
              FigletText('The BEST!', font='small'),
              20,
              colour=Screen.COLOUR_GREEN),
        Print(screen, StaticRenderer(images=[Welcome]), 25)
    ]
    scenes.append(Scene(effects, 0))

    screen.play(scenes, stop_on_resize=True, repeat=True)
예제 #2
0
    def test_colour_maps(self):
        """
        Check that the ${} syntax is parsed correctly.
        """
        # Check the ${fg, attr, bg} variant
        renderer = StaticRenderer(images=["${3,1,2}*"])
        output = renderer.rendered_text
        self.assertEqual(len(output[0]), len(output[1]))
        self.assertEqual(output[0], ["*"])
        self.assertEqual(
            output[1][0][0],
            (Screen.COLOUR_YELLOW, Screen.A_BOLD, Screen.COLOUR_GREEN))

        # Check the ${fg, attr} variant
        renderer = StaticRenderer(images=["${3,1}*"])
        output = renderer.rendered_text
        self.assertEqual(len(output[0]), len(output[1]))
        self.assertEqual(output[0], ["*"])
        self.assertEqual(output[1][0][0],
                         (Screen.COLOUR_YELLOW, Screen.A_BOLD, None))

        # Check the ${fg} variant
        renderer = StaticRenderer(images=["${1}XY${2}Z"])
        output = renderer.rendered_text
        self.assertEqual(len(output[0]), len(output[1]))
        self.assertEqual(output[0], ["XYZ"])
        self.assertEqual(output[1][0][0], (Screen.COLOUR_RED, 0, None))
        self.assertEqual(output[1][0][1], (Screen.COLOUR_RED, 0, None))
        self.assertEqual(output[1][0][2], (Screen.COLOUR_GREEN, 0, None))
예제 #3
0
    def __init__(self, screen, path, start_frame=0, stop_frame=0):
        images = []
        colour = Screen.COLOUR_YELLOW if screen.colours <= 16 else 11
        for image in pac_man:
            images.append(image.format("${%d,2,%d}" % (colour, colour)))
        images_right = [
            image.format("${%d,2,%d}" % (colour, colour))
            for image in pac_man_right
        ]

        super(PacMan, self).__init__(screen,
                                     renderer_dict={
                                         "default":
                                         StaticRenderer(images=images,
                                                        animation=cycle),
                                         "left":
                                         StaticRenderer(images=images,
                                                        animation=cycle),
                                         "right":
                                         StaticRenderer(images=images_right,
                                                        animation=cycle),
                                     },
                                     path=path,
                                     start_frame=start_frame,
                                     stop_frame=stop_frame)
예제 #4
0
 def __init__(self,
              screen,
              path,
              colour=Screen.COLOUR_WHITE,
              start_frame=0,
              stop_frame=0):
     """
     See :py:obj:`.Sprite` for details.
     """
     super(Arrow, self).__init__(screen,
                                 renderer_dict={
                                     "default":
                                     StaticRenderer(images=default_arrow,
                                                    animation=_blink),
                                     "left":
                                     StaticRenderer(images=[left_arrow]),
                                     "right":
                                     StaticRenderer(images=[right_arrow]),
                                     "down":
                                     StaticRenderer(images=[down_arrow]),
                                     "up":
                                     StaticRenderer(images=[up_arrow]),
                                 },
                                 path=path,
                                 colour=colour,
                                 start_frame=start_frame,
                                 stop_frame=stop_frame)
예제 #5
0
def build_building(screen, floors, lifts):
    effects = [
        Print(screen, StaticRenderer([modify_roof_for_lift_gaps(ROOF, lifts)]),
              Y_BASE - 3)
    ]
    for i in range(floors):
        effects.append(
            Print(
                screen,
                StaticRenderer([
                    modify_floor_for_lift_gaps(FLOOR, lifts).format(floors - i)
                ]), Y_BASE + i * 3))
    return effects
예제 #6
0
    def __init__(self, screen, _name, interface):
        interface._block_callback_watcher = BlockCallbackWatcher(
            screen, interface)

        effects = [
            interface._block_callback_watcher,
            DynamicSourceCursor(screen, BlockStatusRenderer(interface.node), 0,
                                0),
            Materialize(screen,
                        StaticRenderer(['${7,1}N${2,2}etwork:']),
                        41,
                        0,
                        signal_acceleration_factor=2,
                        stop_frame=100),
            DynamicSourceCursor(screen, NetworkStatusRenderer(interface.node),
                                51, 0),
            Materialize(screen,
                        StaticRenderer([self.MENU_FRAME]),
                        0,
                        2,
                        signal_acceleration_factor=1.05,
                        stop_frame=100),
            Materialize(screen,
                        StaticRenderer([self.MENU_TOP]),
                        32,
                        3,
                        signal_acceleration_factor=1.05,
                        stop_frame=100),
            DynamicSourceCursor(screen, CredstickNameRenderer(interface), 3,
                                3),
            Materialize(screen,
                        QRCodeRenderer(interface),
                        48,
                        7,
                        signal_acceleration_factor=1.1,
                        stop_frame=120),
            DynamicSourceCursor(screen, AddressRenderer(interface), 22, 5),
            DynamicSourceCursor(screen, HDPathRenderer(interface), 13, 7),
            DynamicSourceCursor(screen, EthBalanceRenderer(interface), 8, 11),
            DynamicSourceCursor(screen, EthValueRenderer(interface), 3, 13),
            DynamicSourceCursor(screen, ENSRenderer(interface), 16, 9),
            MainMenuListener(screen, interface),
            DynamicSourceCursor(screen,
                                TxQueueHashRenderer(interface),
                                0,
                                23,
                                speed=2)
        ]

        super(MainScene, self).__init__(effects, -1, name=_name)
예제 #7
0
    def __init__(self, screen, _name, interface):
        version = ""
        for char in SL_VERSION:
            version += char + " "
        version = version.replace("v ", "v")

        effects = [
            DynamicSourceCursor(screen,
                                BlockStatusRenderer(interface.node),
                                0,
                                0,
                                speed=4,
                                no_blink=True),
            Materialize(screen,
                        StaticRenderer(['${7,1}N${2,2}etwork:']),
                        41,
                        0,
                        signal_acceleration_factor=2),
            DynamicSourceCursor(screen,
                                NetworkStatusRenderer(interface.node),
                                51,
                                0,
                                speed=4),
            Materialize(screen,
                        FigletText('Shadowlands', 'slant'),
                        0,
                        2,
                        signal_acceleration_factor=1.0),
            Materialize(
                screen,
                StaticRenderer([
                    'p u b l i c    t e r m i n a l\t\t\t{}'.format(version)
                ]),
                10,
                9,
                signal_acceleration_factor=1.0,
            ),
            DynamicSourceCursor(screen,
                                CredstickNameRenderer(interface,
                                                      add_padding=False),
                                0,
                                13,
                                speed=6,
                                no_blink=False),
            CredstickWatcher(screen, interface),
            LoadingScreenListener(screen, interface)
        ]

        super(LoadingScene, self).__init__(effects, -1, name=_name)
예제 #8
0
    def test_rotated_dup(self):
        """
        Check that the RotatedDuplicate renderer works.
        """
        # Check zero padding
        renderer = RotatedDuplicate(5, 2, StaticRenderer(["ASCII"]))
        self.assertEqual(renderer.rendered_text[0], ['ASCII', 'IICSA'])

        # Check negative padding
        renderer = RotatedDuplicate(3, 2, StaticRenderer(["ASCII\nRULES"]))
        self.assertEqual(renderer.rendered_text[0], ['ULE', 'ELU'])

        # Check positive padding
        renderer = RotatedDuplicate(7, 4, StaticRenderer(["ASCII"]))
        self.assertEqual(renderer.rendered_text[0], ['', ' ASCII', ' IICSA'])
예제 #9
0
    def test_cycle(self):
        """
        Check that Cycle works.
        """
        # Check that cycle swaps colours every other frame.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        effect = Cycle(screen, StaticRenderer(images=["hello"]), 2)
        effect.reset()
        # First 2 calls should do nothing and use black.
        effect.update(0)
        screen.centre.assert_not_called()
        effect.update(1)
        screen.centre.assert_called_with("hello", 2, 0)
        # Next 2 calls should do nothing and use red.
        screen.centre.reset_mock()
        effect.update(2)
        screen.centre.assert_not_called()
        effect.update(3)
        screen.centre.assert_called_with("hello", 2, 1)

        # Check there is no stop frame
        self.assertEqual(effect.stop_frame, 0)

        # This effect should ignore events.
        event = object()
        self.assertEqual(event, effect.process_event(event))
예제 #10
0
    def update(self, frame_no):
        self._draw_label()

        # Calculate new visible limits if needed.
        height = self._h
        if not self._line_wrap:
            self._start_column = min(self._start_column, self._column)
            # self._start_column += _find_min_start(
            #   self._value[self._line][self._start_column:self._column + 1],
            #   self.width,
            #   self._frame.canvas.unicode_aware,
            #   self._column >= self.string_len(self._value[self._line]))

        # Clear out the existing box content
        (colour, attr, bg) = self._pick_colours("edit_text")
        for i in range(height):
            self._frame.canvas.print_at(" " * self.width,
                                        self._x + self._offset, self._y + i,
                                        colour, attr, bg)

        # Convert value offset to display offsets
        # NOTE: _start_column is always in display coordinates.
        display_text = self._reflowed_text
        display_start_column = self._start_column
        display_line, display_column = 0, 0
        for i, (_, line, col) in enumerate(display_text):
            if line <= self._line and col <= self._column:
                display_line = i
                display_column = self._column - col

        # Restrict to visible/valid content.
        self._start_line = max(
            0,
            max(display_line - height + 1, min(self._start_line,
                                               display_line)))

        # # Render visible portion of the text.
        # for line, (text, _, _) in enumerate(display_text):
        #   if self._start_line <= line < self._start_line + height:
        #     self._frame.canvas.print_at(
        #       text,
        #       # _enforce_width(text[display_start_column:], self.width,
        #       #                self._frame.canvas.unicode_aware),
        #       self._x + self._offset,
        #       self._y + line - self._start_line,
        #       colour, attr, bg)

        # for y, l in enumerate(self.value):
        #   self._scene.add_effect(Print(self._screen,
        #                         StaticRenderer(images=[self._render(l)]), x=0, y=y, colour=7))
        image, colours = StaticRenderer(self.value).rendered_text
        for (i, line) in enumerate(image):
            self._frame.canvas.paint(line,
                                     self._x,
                                     self._y + i,
                                     self._colour,
                                     attr=self._attr,
                                     bg=self._bg,
                                     transparent=self._transparent,
                                     colour_map=colours[i])
예제 #11
0
 def test_width(self):
     """
     Check that the max_width property works.
     """
     # Max width should match largest width of any entry.
     renderer = StaticRenderer(images=["A\nB", "C  "])
     self.assertEqual(renderer.max_width, 3)
예제 #12
0
 def test_repr(self):
     """
     Check that the string representation works.
     """
     # String presentation should be the first image as a printable string.
     renderer = StaticRenderer(images=["A\nB", "C  "])
     self.assertEqual(str(renderer), "A\nB")
예제 #13
0
    def test_print(self):
        """
        Check that the Print Effect works.
        """
        # Check that print only redraws on specified rate.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        effect = Print(screen, StaticRenderer(images=["hello"]), 2, 1)
        effect.reset()
        effect.update(0)
        screen.paint.assert_called_with("hello",
                                        1,
                                        2,
                                        7,
                                        attr=0,
                                        bg=0,
                                        colour_map=[(None, None, None)
                                                    for _ in range(5)],
                                        transparent=True)
        screen.paint.reset_mock()
        effect.update(1)
        effect.update(2)
        effect.update(3)
        screen.paint.assert_not_called()

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)

        # This effect should ignore events.
        event = object()
        self.assertEqual(event, effect.process_event(event))
예제 #14
0
 def test_height(self):
     """
     Check that the max_height property works.
     """
     # Max height should match largest height of any entry.
     renderer = StaticRenderer(images=["A\nB", "C  "])
     self.assertEqual(renderer.max_height, 2)
예제 #15
0
 def start(screen):
     centre = (screen.width // 2, screen.height // 2)
     fish = Fish()
     effects = []
     colors = [
         Screen.COLOUR_RED, Screen.COLOUR_CYAN, Screen.COLOUR_MAGENTA,
         Screen.COLOUR_GREEN, Screen.COLOUR_WHITE, Screen.COLOUR_YELLOW
     ]
     for _ in range(0, 50):
         path = Path()
         # Spawn object on scene. Or teleport it to that cords.
         path.jump_to(0, random.randint(5, screen.height))
         # Move object to that cords in stright line. 3rd argument is how many steps it takes to complete this path.
         path.move_straight_to(screen.width,
                               random.randint(5, screen.height),
                               random.randint(100, 200))
         # Create sprite. Sprite is an effect, which can follow path.
         sprite = Sprite(
             screen,
             renderer_dict={
                 "default": StaticRenderer(images=[fish.small_fish])
             },
             path=path,  #)
             colour=random.choice(colors))
         # Add effect to effect list. Effect is basically anything that will be displayed on scene.
         effects.append(sprite)
     # Add all effects yo this scene
     scene = [Scene(effects, -1)]
     screen.set_title('ASCIIQuarium')
     # Play scene, auto reprat, stop when window is resized.
     screen.play(scene, repeat=False)
예제 #16
0
def demo(screen):
    scenes = []
    cell1 = Rainbow(screen,
                    RotatedDuplicate(screen.width // 2,
                                     max(screen.width // 2, screen.height),
                                     FigletText("ASCII" if screen.width < 80 else "ASCII rules",
                                                font="banner",
                                                width=screen.width // 2)))
    cell2 = ""
    size = int(sqrt(screen.height ** 2 + screen.width ** 2 // 4))
    for _ in range(size):
        for x in range(size):
            c = x * screen.colours // size
            cell2 += "${%d,2,%d}:" % (c, c)
        cell2 += "\n"
    for i in range(8):
        scenes.append(
            Scene([Print(screen,
                         Kaleidoscope(screen.height, screen.width, cell1, i),
                         0,
                         speed=1,
                         transparent=False),
                   Print(screen,
                         FigletText(str(i)), screen.height - 6, x=screen.width - 8, speed=1)],
                  duration=360))
        scenes.append(
            Scene([Print(screen,
                         Kaleidoscope(screen.height, screen.width, StaticRenderer([cell2]), i),
                         0,
                         speed=1,
                         transparent=False)],
                  duration=360))
    screen.play(scenes, stop_on_resize=True)
예제 #17
0
 def __init__(self, screen, path, start_frame=0, stop_frame=0):
     """
     See :py:obj:`.Sprite` for details.
     """
     super(Sam, self).__init__(
         screen,
         renderer_dict={
             "default": StaticRenderer(images=sam_default, animation=_blink),
             "left": StaticRenderer(images=[sam_left]),
             "right": StaticRenderer(images=[sam_right]),
             "down": StaticRenderer(images=[sam_down]),
             "up": StaticRenderer(images=[sam_up]),
         },
         path=path,
         start_frame=start_frame,
         stop_frame=stop_frame)
예제 #18
0
    def _render_now(self):
        clocktext = "00:00.00"
        try:
            clocktext = (clocktext if lastframe is None else
                         lastframe["game_clock_display"])
        except:
            pass

        return StaticRenderer(images=[clocktext]).rendered_text
예제 #19
0
 def __init__(self, screen, path, start_frame=0, stop_frame=0):
     super(Shell, self).__init__(screen,
                                 renderer_dict={
                                     "default":
                                     StaticRenderer(images=[shell]),
                                 },
                                 path=path,
                                 start_frame=start_frame,
                                 stop_frame=stop_frame)
예제 #20
0
def main(screen):
    effects = [
        Print(screen,
              StaticRenderer(images=[tree]),
              colour=Screen.COLOUR_GREEN,
              x=0,
              y=0)
    ]
    screen.play([Scene(effects, -1)], stop_on_resize=True)
예제 #21
0
 def test_images(self):
     """
     Check that the images property works.
     """
     # Images should be the parsed versions of the original strings.
     renderer = StaticRenderer(images=["A\nB", "C  "])
     images = renderer.images
     self.assertEqual(next(images), ["A", "B"])
     self.assertEqual(next(images), ["C  "])
예제 #22
0
 def __init__(self, screen):
     """
     See :py:obj:`.Sprite` for details.
     """
     super(CrossHairs, self).__init__(
         screen,
         renderer_dict={"default": StaticRenderer(images=["X"])},
         path=MouseController(self, screen, screen.width // 2,
                              screen.height // 2),
         colour=Screen.COLOUR_RED)
예제 #23
0
 def __init__(self, screen, path, start_frame=0, stop_frame=0):
     super(Eyes, self).__init__(screen,
                                renderer_dict={
                                    "default":
                                    StaticRenderer(images=[eyes]),
                                },
                                colour=Screen.COLOUR_BLUE,
                                path=path,
                                start_frame=start_frame,
                                stop_frame=stop_frame)
def s2r(string):
    """ Return a rendered associated to the string

    Args:
        string : the string to be rendreed

    Returns: 
        rendered: The associated Rendered object 
    """
    return StaticRenderer(images=[r""" %s """ % string])
예제 #25
0
 def __init__(self, screen, path, start_frame=0, stop_frame=0):
     super(ScaredGhost, self).__init__(
         screen,
         renderer_dict={
             "default": StaticRenderer(images=scared_ghost),
         },
         colour=Screen.COLOUR_BLUE,
         path=path,
         start_frame=start_frame,
         stop_frame=stop_frame)
     self._eaten = False
예제 #26
0
    def _render_now(self):
        try:
            playername = lastframe["teams"][self.team]["players"][
                self.player]["name"]
            if self.rjust:
                playername = playername.rjust(16)
            else:
                playername = playername.ljust(16)
        except:
            playername = "-" * 16

        return StaticRenderer(images=[playername]).rendered_text
예제 #27
0
    def __init__(self, screen, path, start_frame=0, stop_frame=0):

        super().__init__(
            screen,
            renderer_dict={
                "default": StaticRenderer(images=generate_scroller_frames())
            },
            path=path,
        )

        def _update(self, frame_no):
            super(NinjaRobotScroller, self)._update(frame_no)
예제 #28
0
 def __init__(self,
              screen,
              path,
              colour=Screen.COLOUR_WHITE,
              start_frame=0,
              stop_frame=0):
     super(Lift, self).__init__(
         screen,
         renderer_dict={"default": StaticRenderer(images=[LIFT])},
         path=path,
         colour=colour,
         start_frame=start_frame,
         stop_frame=stop_frame)
예제 #29
0
 def __init__(self, screen, path, colour=1, start_frame=0, stop_frame=0):
     images = []
     for image in ghost:
         images.append(image.format("${%d,2,%d}" % (colour, colour)))
     super(Ghost, self).__init__(screen,
                                 renderer_dict={
                                     "default":
                                     StaticRenderer(images=images),
                                 },
                                 colour=colour,
                                 path=path,
                                 start_frame=start_frame,
                                 stop_frame=stop_frame)
예제 #30
0
    def wait_screen(self):
        def input_event_handler(event):
            if isinstance(event, KeyboardEvent):
                c = event.key_code
                self.sm.step(c)
                if c is ord(" "):
                    raise StopApplication("Screen stopped by user")

        # self.mGPU.setCurrentScreen(screen)
        effects = [
            Print(self.mGPU.screen,
                  FigletText("DIFFICULTY:   {}".format(
                      self.sm.state["DIFFICULTY"]),
                             font='small'),
                  y=self.mGPU.height // 2 - 10),
            Print(self.mGPU.screen,
                  Fire(10, self.mGPU.width, "*" * self.mGPU.width, 1, 30,
                       self.mGPU.screen.colours, False),
                  y=self.mGPU.height - 5,
                  speed=1,
                  transparent=True),
            Print(self.mGPU.screen,
                  StaticRenderer(images=[
                      r"""
_______________________________________________________________________________________
| OBJECTIVE                                                                            |
|--------------------------------------------------------------------------------------|
|                                                                                      |
|  You need to escape the maze ASAP. Find the ${1}RED${7} door!                                |
|  You are only allowed to look at the map for a limited number of times.              |
|                                                                                      |
|                                                                                      |
|  control : Press A, W, S, D to move around. Press Q and E to pan.                    |
|  Press M to look at the map (Psst you only can look at the map limited no. of time)  |
|  Press P to pause the game. (It can be tiring so take your time to solve the maze)   |
|                                                                                      |
|  Are you ready?  \☺/                                                                 |
|  Good luck!       []                                                                 |
|                   /\                        ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄      |
|                                             █        ▀█▄▀▄▀██████ ▀█▄▀▄▀██████       |
|  Press [SPACE BAR] to start the game                   ▀█▄█▄███▀    ▀█▄█▄███         |
|______________________________________________________________________________________|
            """
                  ]),
                  y=self.mGPU.height // 2 - 5)
        ]

        self.mGPU.set_title("Maze Runner")
        self.mGPU.playScene(effects,
                            stop_on_resize=True,
                            input_handler=input_event_handler)