Search code examples
pythonanimationasciimaticscross-hair-label

naming an asciimatics scene


I am trying to make a game with a fight. to do this i need to loop through a certain scene until either the player or monster has a health value of 0 or less. so i have variables set up to play the next scene (which is the same scene that i want to loop) after the variable hits 0. but the problem s that i dont know how to name a scene. here is my code:

def whack(self, sound):
    global PL, KL, SL, BL
    x, y = self._path.next_pos()
    if self.overlaps(PLAYER, use_new_pos=True):
        PL += 1
        raise NextScene
    if self.overlaps(SMOLFUNGI, use_new_pos=True):
        SL -= 1
        raise NextScene('the scene that is looping')
    else:
        self._scene.add_effect(Print(
            self._screen,
            SpeechBubble(sound), y, x, clear=True, delete_count=50))
    if PL < 1:
        raise StopApplication
    if SL < 1:
        raise NextScene

# Scene 7.
path = Path()
path.jump_to(podium[0], podium[1])

effects = [
    Print(screen,
    Box(screen.width, screen.height, uni=screen.unicode_aware),
    0, 0, start_frame=1),
      Print(screen, StaticRenderer(images=Grass),
    x=screen.width - 140,
    y=screen.height - 6,
      colour=Screen.COLOUR_WHITE),
    SMOLFUNGI,
    PLAYER,
    cross_hairs,
]
scenes.append(Scene(effects, -1))

Solution

  • It's just a parameter on the Scene object. For an explanation of how to use them, read the relevant section in the docs (https://asciimatics.readthedocs.io/en/stable/widgets.html#exceptions).

    The key example is as follows.

    # Given this scene list...
    scenes = [
        Scene([ListView(screen, contacts)], -1, name="Main"),
        Scene([ContactView(screen, contacts)], -1, name="Edit Contact")
    ]
    screen.play(scenes)
    
    # You can use this code to move back to the first scene at any time...
    raise NextScene("Main")