Esempio n. 1
0
def showtip():
    alltips = open(data.filepath("tips.txt")).readlines()
    for i in range(len(alltips)):
        alltips[i] = control_format(alltips[i], controller1)
    alltips = [
        line[4:] for line in alltips
        if int(line[0]) <= record.unlocked <= int(line[2])
    ]
    # ^ The characters at 0 and 2 are used to access single-digit numbers.
    tiptext = record.gettip(alltips)
    tip = effect.Tip([tiptext])
    clock = pygame.time.Clock()
    while True:
        dt = clock.tick(60) * 0.001
        if settings.printfps and random.random() < dt:
            print(clock.get_fps())

        for event in pygame.event.get():
            done = False
            result = 0
            if event.type == QUIT:
                sys.exit()
                # ^ This is OK since QUIT already occurred.
            else:
                result = read_event(
                    controller1,
                    event,
                    # pcRect=None, # leave default None--non-directional
                    mb_sids=('nab', None, 'EXIT'),
                    # always_collide_mb=2,
                    # ^ leave default None--non-directional
                )

            if result < 1:
                continue

            if controller1.getBool('EXIT'):
                done = True
            elif controller1.getBool('nab'):
                done = True
            elif controller1.getBool('SCREENSHOT'):
                screenshot(vista.screen)
            elif controller1.getBool('FULLSCREEN'):
                settings.fullscreen = not settings.fullscreen
                vista.init()
            if done:
                if settings.verbose:
                    print("* exiting showtip")
                vista.screen.fill((0, 0, 0))
                pygame.display.flip()
                return

        tip.think(dt)

        vista.screen.fill((0, 0, 0))
        tip.draw(vista.screen)
        pygame.display.flip()
        if not is_active(tip): return
Esempio n. 2
0
def rollcredits():
    clines = open(data.filepath("credits.txt")).readlines()
    credit = effect.Credit(clines)
    clock = pygame.time.Clock()
    while is_active(credit):

        dt = clock.tick(60) * 0.001
        if settings.printfps and random.random() < dt:
            print(clock.get_fps())

        for event in pygame.event.get():
            result = 0
            if event.type == QUIT:
                sys.exit()
            else:
                result = read_event(
                    controller1,
                    event,
                    # pcRect=None, # leave default None--non-directional
                    mb_sids=('nab', None, 'EXIT'),
                    # always_collide_mb=2,
                    # ^ leave default None--non-directional
                )

            if result < 1:
                continue

            if controller1.getBool('EXIT'):
                return
            elif controller1.getBool('nab'):
                credit.advance()
            elif controller1.getBool('SCREENSHOT'):
                screenshot(vista.screen)
            elif controller1.getBool('FULLSCREEN'):
                settings.fullscreen = not settings.fullscreen
                vista.init()

        credit.think(dt)

        vista.screen.fill((0, 0, 0))
        credit.draw(vista.screen)
        pygame.display.flip()
Esempio n. 3
0
def action():
    '''
    This is part of the gameplay event loop runs when the state is not
    in a menu, cutscene, or other non-gameplay state. However, the
    paused state is included here.
    '''
    global level
    vista.levelinit(level)
    global prevPCKey
    global touchEffect
    global touchEffectPos
    global touchColor

    butterflies, goal, timeout = loadlevel.load(level)

    clock = pygame.time.Clock()
    facingright = True
    x, y, g, vy = 200, 0, (250 if settings.easy else 500), 0
    leapvx, leapvy = 200., 200.
    twirlvy = 200.
    nabvx = 400.
    runvx = 300.
    rollvx, rollvy = 250., 250.
    dartvx, dartvy = 250., 300.
    boundvx, boundvy = -100., 250.
    nabtick, nabtime = 0, 0.25
    nabradius = 50
    twirlradius = 80
    rollradius = 80
    leaping = 0
    runtick = 0
    twirltick = 0
    rolltick = 0
    currentfeat = ""
    combocount = 0
    grounded = True
    paused = False
    titleEffect = effect.Effect(["READY", "SET", "COLLECT"])
    endtitle = True
    ending = False
    effects = []
    heffect = effect.HeightIndicator()
    ceffect = effect.ComboIndicator()
    peffect = effect.ProgressIndicator(goal)
    cdeffect = effect.CountdownIndicator(timeout)
    seffect = effect.StageNameEffect(level, goal, timeout)
    feat.startlevel()
    pygame.event.get()
    prevTitleStr = None
    pcRect = None
    pcPos = None

    while True:
        dt = clock.tick(60) * 0.001
        if settings.printfps and random.random() < dt:
            print(clock.get_fps())

        if paused:
            for event in pygame.event.get():
                result = 0
                if event.type == QUIT:
                    sys.exit()
                else:
                    result = read_event(
                        controller1,
                        event,
                        pcRect=pcRect,
                        mb_sids=('nab', None, 'BACK'),
                        # always_collide_mb=2,
                    )

                if result < 2:
                    vista.screen.blit(pausescreen, (0, 0))
                    pygame.display.flip()
                    # Try to prevent a black screen when switching
                    # away from the game and back.
                    continue

                if controller1.getBool('BACK'):
                    ending = True
                    endtitle = None
                    feat.checknewfeat(len(record.collected))
                    if record.catchamount >= goal:
                        unlocked = record.unlocked
                        record.checkhiscore(level)
                        if record.unlocked > unlocked:
                            level = record.unlocked
                    paused = False
                    noise.unpause()
                elif controller1.getBool('SCREENSHOT'):
                    screenshot(vista.screen)
                elif controller1.getBool('nab'):
                    paused = False
                    noise.unpause()
                elif controller1.getBool('FULLSCREEN'):
                    settings.fullscreen = not settings.fullscreen
                    vista.init()
            vista.screen.blit(pausescreen, (0, 0))
            pygame.display.flip()
            continue
        # action main event loop (when not paused):
        up_events = []
        for event in pygame.event.get():
            result = 0
            if event.type == QUIT:
                sys.exit()
            elif event.type == MOUSEBUTTONUP:
                # Process this separately in case the button was
                # pressed and released in the same frame such as
                # with the scroll wheel turning.
                up_events.append(event)
            else:
                # pcRect may be None for a frame but read_event
                # is ok with that.
                always_collide_mb = None
                if event.type == MOUSEBUTTONDOWN:
                    if not grounded:
                        # Double-jump if in the air
                        # - 3: Change right-click from 'x' to 'jump'
                        #      even if not clicking the character
                        # - 4&5: Change wheel roll to nab to allow roll
                        #      ('x' and 'nab' at the same time) with
                        #      only a mouse.
                        always_collide_mb = (2, 3, 4, 5)
                    elif (pcRect is not None) and (event.pos[1] < pcRect.top):
                        # Jump if clicking above the character's head
                        # even if on the ground and not clicking in
                        # pcRect.
                        always_collide_mb = (3)
                    if settings.verbose:
                        print("[main.action] pcRect={}" "".format(pcRect))
                        if pcRect is not None:
                            print("[main.action] pcRect.top={}"
                                  "".format(pcRect.top))
                        print("[main.action] event.pos={}"
                              "".format(event.pos))
                        print("[main.action] always_collide_mb={}"
                              "".format(always_collide_mb))

                result = read_event(
                    controller1,
                    event,
                    pcRect=pcRect,
                    mb_sids=('nab', 'nab', 'jump'),
                    always_collide_mb=always_collide_mb,
                )
                # ^ Set the wheel to nab and add 3, 4 & 5 to
                #   always_collide_mb when in the air to allow
                #   the roll combo using only a mouse but still
                #   allowing both:
                #   - nab would be impossible if left button
                #     were in always_collide_mb--when not, click on
                #     the character to nab, and click away to dart
                #     or turn
                #   - See "Mouse Controls" in readme.md.
                # 1: left
                # 2: middle
                # 3: right
                # 4: scroll up
                # 5: scroll down
                # ^ The first one in mb_sids is used for button 1.

            controller_changed = result > 0

            if controller1.getBool('EXIT') and controller_changed:
                # The same button for exit is also pause.
                paused = True
                noise.pause()
                pausescreen = pygame.Surface(
                    vista.screen.get_size()).convert_alpha()
                fade = pygame.Surface(vista.screen.get_size()).convert_alpha()
                fade.fill((0, 0, 0, 128))
                pausescreen.blit(vista.screen, (0, 0))
                pausescreen.blit(fade, (0, 0))
                pausetitle = effect.PauseTitle(["PAUSED"])
                pauseFmt = "Press [nab] to resume|or [BACK] to exit level"
                pauseStr = control_format(pauseFmt, controller1)
                pauseinfo = effect.PauseInfo([pauseStr])
                pausetitle.position(pausescreen)
                pauseinfo.position(pausescreen)
                pausetitle.draw(pausescreen)
                pauseinfo.draw(pausescreen)
            if controller1.getBool('SCREENSHOT') and controller_changed:
                screenshot(vista.screen)
            if controller1.getBool('feat') and controller_changed:
                settings.hidefeatnames = not settings.hidefeatnames
                feat.startlevel(False)
            if controller1.getBool('FULLSCREEN') and controller_changed:
                settings.fullscreen = not settings.fullscreen
                vista.init()

        # k = pygame.key.get_pressed()
        # k = controller1.toKeys()
        kcombo = combo.get_combo(controller1)
        if settings.verbose:
            if (kcombo is not None) and (kcombo != ""):
                print("[main] kcombo={}".format(kcombo))
            # else:
            #     print("[main] controller1._states={}"
            #           "".format(controller1._states))
        for event in up_events:
            # Process these after combos in case down and up were on
            # the same frame. For further details about
            # read_event see the first call (this one should match it,
            # but always_collide_mb doesn't matter on MOUSEBUTTONUP.
            always_collide_mb = None
            result = read_event(
                controller1,
                event,
                pcRect=pcRect,
                mb_sids=('nab', 'nab', 'jump', 'nab', 'nab'),
                always_collide_mb=always_collide_mb,
            )

        # print("PRESSED:{}".format(controller1.getTrues()))
        if grounded:
            # print("ground combo:{}".format(kcombo))
            dx = 0
            if controller1.getInt('x') > 0:
                dx += runvx * dt
            elif controller1.getInt('x') < 0:
                dx -= runvx * dt
            if nabtick:
                dx = 0

            if not is_active(cdeffect):
                dx = 0
                kcombo = ""

            if dx:
                facingright = dx > 0
                currentfeat = "run"
                x += dx
            elif not nabtick:
                currentfeat = ""

            if kcombo == "leap" and "leap" in feat.known:
                if feat.attempt("leap"):
                    vx = leapvx if facingright else -leapvx
                    vy = leapvy
                    combocount = 1
                    grounded = False
                    currentfeat = "leap"
                    noise.play("hop")
            elif kcombo == "twirl" and "twirl" in feat.known:
                if feat.attempt("twirl"):
                    combocount = 1
                    grounded = False
                    currentfeat = "twirl"
                    vx = 0
                    vy = twirlvy
                    twirltick = 1
                    noise.play("rotor")
            elif kcombo == "nab" and "nab" in feat.known:
                if feat.attempt("nab"):
                    currentfeat = "nab"
                    nabtick = nabtime
                    noise.play("woosh")
            elif kcombo == ("roll-r" if facingright else
                            "roll-l") and "roll" in feat.known:
                if feat.attempt("roll"):
                    grounded = False
                    currentfeat = "roll"
                    vx = (rollvx if facingright else -rollvx)
                    vy = rollvy
                    combocount = 1
                    rolltick = 1
                    twirltick = 0
                    noise.play("rotor")
            elif kcombo == ("dart-r" if facingright else
                            "dart-l") and "dart" in feat.known:
                if feat.attempt("dart"):
                    grounded = False
                    currentfeat = "dart"
                    vx = (dartvx if facingright else -dartvx)
                    vy = dartvy
                    combocount = 1
                    rolltick = 0
                    twirltick = 0
                    noise.play("hop")
            elif kcombo == ("dart-l" if facingright else
                            "dart-r") and "bound" in feat.known:
                if feat.attempt("bound"):
                    grounded = False
                    currentfeat = "bound"
                    vx = (boundvx if facingright else -boundvx)
                    vy = boundvy
                    combocount = 1
                    rolltick = 0
                    twirltick = 0
                    noise.play("hop")
        else:
            # print("air combo:{}".format(kcombo))
            if kcombo == "leap" and "leap" in feat.known:
                if feat.attempt("leap"):
                    vx = leapvx if facingright else -leapvx
                    vy = leapvy
                    combocount += 1
                    currentfeat = "leap"
                    twirltick = 0
                    noise.play("hop")
            elif kcombo == ("turn-r" if facingright else
                            "turn-l") and "turn" in feat.known:
                if feat.attempt("turn"):
                    facingright = not facingright
                    vx = leapvx if facingright else -leapvx
                    vy = leapvy
                    combocount += 1
                    twirltick = 0
                    rolltick = 0
                    currentfeat = "leap"
                    noise.play("hop")
            elif kcombo == "nab" and "nab" in feat.known:
                if feat.attempt("nab"):
                    currentfeat = "nab"
                    nabtick = nabtime
                    vx = nabvx if facingright else -nabvx
                    combocount += 1
                    twirltick = 0
                    rolltick = 0
                    noise.play("woosh")
            elif kcombo == "twirl" and "twirl" in feat.known:
                if feat.attempt("twirl"):
                    currentfeat = "twirl"
                    vx = 0
                    vy = twirlvy
                    combocount += 1
                    twirltick = 1
                    rolltick = 0
                    noise.play("rotor")
            elif kcombo == ("roll-r" if facingright else
                            "roll-l") and "roll" in feat.known:
                if feat.attempt("roll"):
                    currentfeat = "roll"
                    vx = (rollvx if facingright else -rollvx)
                    vy = rollvy
                    combocount += 1
                    rolltick = 1
                    twirltick = 0
                    noise.play("rotor")
            elif kcombo == ("dart-r" if facingright else
                            "dart-l") and "dart" in feat.known:
                if feat.attempt("dart"):
                    currentfeat = "dart"
                    vx = (dartvx if facingright else -dartvx)
                    vy = dartvy
                    combocount += 1
                    rolltick = 0
                    twirltick = 0
                    noise.play("hop")
            elif kcombo == ("dart-l" if facingright else
                            "dart-r") and "bound" in feat.known:
                if feat.attempt("bound"):
                    currentfeat = "bound"
                    vx = (boundvx if facingright else -boundvx)
                    vy = boundvy
                    combocount += 1
                    rolltick = 0
                    twirltick = 0
                    noise.play("hop")

            if nabtick:
                x += vx * dt
            else:
                x += vx * dt
                y += vy * dt - 0.5 * g * dt**2
                vy -= g * dt
            if y < 0:
                y = 0
                vy = 0
                grounded = True
                combocount = 0
                feat.land()
                ach = record.getrecords()
                if ach:
                    effects.append(effect.AchievementEffect(ach))
                currentfeat = ""
                twirltick = 0
                rolltick = 0

        x, y = vista.constrain(x, y, 30)

        nx, ny, nr = None, None, None
        if nabtick:
            nabtick = max(nabtick - dt, 0)
            if not nabtick:
                currentfeat = "" if grounded else "leap"
            nx, ny = x + (40 if facingright else -40), y + 80
            nr = nabradius
        elif currentfeat == "twirl":
            nx, ny = x, y + 80
            nr = twirlradius
        elif currentfeat == "roll":
            nx, ny = x, y + 50
            nr = rollradius
        if nx is not None:
            for b in list(butterflies):
                adx, ady = b.x - nx, b.y - ny
                if adx**2 + ady**2 < nr**2:
                    b.nabbed = True
                    butterflies.remove(b)
                    value = 3 * b.value if settings.easy else b.value
                    effects.append(effect.NabBonusIndicator(value, (b.x, b.y)))
                    if grounded:
                        ach = record.checknabgrounded(b)
                        if ach:
                            effects.append(effect.AchievementEffect(ach))
                    else:
                        record.checknab(b)

        heffect.update(y / 25.)
        heffect.position(vista.screen)
        ceffect.update(combocount)
        ceffect.position(vista.screen)
        peffect.update(record.catchamount)
        cdeffect.position(vista.screen)

        hbonus = record.checkheightrecord(y / 25.)
        if hbonus:
            effects.append(effect.HeightBonusIndicator(hbonus))
        cbonus = record.checkcomborecord(combocount)
        if cbonus:
            effects.append(effect.ComboBonusIndicator(cbonus))

        if currentfeat == "leap":
            picname = "run2"
        elif currentfeat == "run":
            picname = ("run0", "run1", "run2", "run1")[int(4 * runtick / 0.5)]
            runtick += dt
            runtick %= 0.5
        elif currentfeat == "nab":
            picname = ("nab3", "nab2", "nab1",
                       "nab0")[int(4. * nabtick / nabtime)]
            if not grounded:
                picname = "sky" + picname
        elif currentfeat == "twirl":
            twirltick += dt
            picname = ("twirl0", "twirl1", "twirl2",
                       "twirl3")[int(4 * twirltick / 0.25) % 4]
        elif currentfeat == "roll":
            rolltick += dt
            picname = "roll%s" % (int(8 * rolltick / 0.35) % 8)
        elif currentfeat == "dart":
            picname = "dart"
        elif currentfeat == "bound":
            picname = "bound"
        else:
            picname = "stand"
        if "twirl" not in picname and not facingright:
            picname = picname + "-b"
        vista.position((x, y), facingright, vy)

        butterflies += loadlevel.newbutterflies(level, dt)

        feat.think(dt)
        vista.think(dt)
        for b in butterflies:
            b.think(dt)
        # seffect.set_verbose(True)
        seffect.think(dt)
        # if not seffect:  # never occurs :(
        # if not bool(seffect):  # never occurs :(
        if not is_active(seffect):
            # ^ __bool__() must be called manually--
            #   The reason seffect is always True even when is the
            #   self.texts evaluates to False in the method is unknown.
            #   Redefining __bool__ in the subclass doesn't help. See
            #   <https://github.com/poikilos/lepidopterist/issues/12>.
            titleEffect.think(dt)
        for fx in effects:
            fx.think(dt)
        effects = [fx for fx in effects if is_active(fx)]
        ceffect.think(dt)
        if not is_active(titleEffect):
            cdeffect.think(dt)
        # titleEffect.set_verbose(True)
        # if prevTitleStr != titleEffect.debug():
        #     print("titleEffect: '{}'".format(titleEffect.debug()))
        # prevTitleStr = titleEffect.debug()
        if grounded and not is_active(cdeffect) and not effects and not ending:
            ending = True
            if record.catchamount >= goal:
                w = ["Stage complete!"]
                unlocked = record.unlocked
                w += record.checkhiscore(level)
                if record.unlocked > unlocked:
                    level = record.unlocked
            else:
                w = ["Stage incomplete"]
            with open('contestdata.txt', 'a') as myfile:
                now = datetime.now()
                myfile.write(str(now) + '\n')
                myfile.write('level=' + str(level) + '\n')
                myfile.write('record.catchamount=' + str(record.catchamount) +
                             '\n')
                myfile.write('record.collected=' + str(record.collected) +
                             '\n')
            w += feat.checknewfeat(len(record.collected))
            endtitle = effect.EndEffect(w)
        if ending and is_active(endtitle):
            endtitle.think(dt)

        vista.clear()
        sprite.frames[picname].draw((x, y))
        # ^ draw uses vista so x,y is modifies by camera panning
        # Player Character:
        if prevPCKey is None:
            prevPCKey = "stand"
        '''
        pcPos = vista.get_screen_pos((x, y))
        pcRect = sprite.frames[prevPCKey].image.get_rect()
        pcRect.width = pcRect.width * 1.5
        pcRect.center = pcPos
        pcRect.height = pcRect.height * .4
        pcRect.top -= pcRect.height / 2
        '''
        pcInternalRect = sprite.frames[prevPCKey].image.get_rect()
        pcRect = vista.get_frame_screen_rect(
            sprite.frames[prevPCKey],
            (x, y),
            width=pcInternalRect.width * 1.5,
            height=pcInternalRect.height / 2,
        )
        pcRect.height *= 6
        # ^ allow clicking below the character for nab
        prevPCKey = picname

        for b in butterflies:
            b.draw()
        if nr is not None and settings.showdots:
            vista.circle((int(nx), int(ny)), int(nr))
        feat.draw(facingright=facingright)
        heffect.draw(vista.screen)
        ceffect.draw(vista.screen)
        cdeffect.draw(vista.screen)
        peffect.draw(vista.screen)
        for fx in effects:
            fx.draw(vista.screen)
        seffect.draw(vista.screen)
        if not is_active(seffect):
            titleEffect.draw(vista.screen)
        if ending and is_active(endtitle):
            endtitle.draw(vista.screen)
        if is_active(touchEffect):
            if pcRect is not None:
                if settings.visualDebug:
                    pygame.draw.rect(vista.screen, idleColor, pcRect)
                    pygame.draw.circle(vista.screen, whiteColor,
                                       (int(pcPos[0]), int(pcPos[1])), 10)
            touchEffect.draw(vista.screen)
            pygame.draw.circle(vista.screen, touchColor,
                               (touchEffect.x0, touchEffect.y0), 10)
        pygame.display.flip()
        if not is_active(endtitle):
            return
Esempio n. 4
0
def cutscene():
    global level
    if record.checkvisited(level) and not (settings.alwaysshow or level == 7):
        return
    clock = pygame.time.Clock()
    dlines = loadlevel.getdialogue(level)
    dialogue = None
    background = pygame.Surface(vista.screen.get_size())
    background.fill((0, 0, 0))

    def drawbackgroundline(y):
        if speaker == "m":
            r = random.randint(0, 144)
            color = r, r, 144
        elif speaker == "e":
            r = random.randint(0, 64)
            color = 192 - r, 192 - 2 * r, 0
        elif speaker == "s":
            r = random.randint(64, 192)
            color = r, r, r
        elif speaker == "v":
            r = random.randint(0, 64)
            color = r, 128 + r, r
        pygame.draw.line(background, color, (0, y), (9999, y))

    speaker = None
    dticker = 0
    while dlines or is_active(dialogue):
        dt = clock.tick(60) * 0.001
        dticker += dt
        if settings.printfps and random.random() < dt:
            print(clock.get_fps())

        for event in pygame.event.get():
            result = 0
            if event.type == QUIT:
                sys.exit()
                # ^ This is OK since QUIT already occurred.
            # elif event.type == MOUSEBUTTONDOWN:
            #     controller1._states['nab'] = 1
            #     result = 2
            else:
                result = read_event(
                    controller1,
                    event,
                    # pcRect=None, # leave default None--non-directional
                    mb_sids=('nab', None, 'EXIT'),
                    # always_collide_mb=2,
                    # ^ leave default None--non-directional
                )

            if result < 2:
                continue
            print("cutscene event result: {}".format(result))

            if controller1.getBool('EXIT'):
                controller1.clearPressed()
                return
            elif controller1.getBool('nab') and dticker > 0.4:
                dialogue = None
            elif controller1.getBool('SCREENSHOT'):
                screenshot(vista.screen)
            elif controller1.getBool('FULLSCREEN'):
                settings.fullscreen = not settings.fullscreen
                vista.init()

        if not is_active(dialogue):
            if not dlines:
                return
            dticker = 10. if (dialogue is None) else 0
            newspeaker, _, line = dlines[0].partition("|")
            dialogue = effect.Dialogue(line, newspeaker)
            if newspeaker != speaker:
                speaker = newspeaker
                for y in range(100, 300):
                    drawbackgroundline(y)
            del dlines[0]

        dialogue.think(dt)

        for j in range(100):
            if random.random() < dt:
                drawbackgroundline(random.randint(100, 299))

        vista.screen.blit(background, (0, 0))
        sprite.frames["head-%s" % speaker].place((0, 0))
        dialogue.draw(vista.screen)
        pygame.display.flip()
    controller1.clearPressed()
Esempio n. 5
0
def worldmap():
    global level
    global touchEffect
    global touchEffectPos
    global touchColor
    controller1.clearPressed()
    if settings.unlockall:
        record.unlocked = 6
    vista.mapinit()
    levelnames = [
        "Stage 1: Mortimer's backyard",
        "Stage 2: Dojo of the Royal Lepidopteral Society",
        "Stage 3: Bucolic Meadow of Doom",
        "Stage 4: Some field you have to cross",
        "Stage 5: Imperial palace of|the Royal Society of Lepidopterists",
        "Final stage:|The Lost Buttefly Garden of Verdania"
    ]
    levelps = [(150, 90), (250, 130), (350, 110), (450, 150), (550, 130),
               (650, 170)]
    clock = pygame.time.Clock()
    teffect = effect.LevelNameEffect("")
    chooseLevelFmt = "Press nab to choose level"
    chooseLevelStr = control_format(chooseLevelFmt, controller1)
    speffect = effect.PressSpaceEffect([chooseLevelStr])
    speffect.position(vista.screen)
    hseffect = effect.HighScoreEffect("")
    hceffect = effect.HCRecord([record.gethcrecord()])
    hceffect.position(vista.screen)
    updateteffect = True
    udseq = []
    esign, rsign = None, None
    pcRect = None
    pcPos = None
    while True:
        dt = clock.tick(60) * 0.001
        if settings.printfps and random.random() < dt:
            print(clock.get_fps())
        events = []
        if pcPos is not None:
            # Don't check or discard events until the rect is obtained.
            events = pygame.event.get()
        touchText = None
        for event in events:
            result = 0
            if event.type == QUIT:
                sys.exit()
                # ^ This is OK since QUIT already occurred.
            else:
                # pcRect may be None for a frame but read_event
                # is ok with that.
                result = read_event(
                    controller1,
                    event,
                    pcRect=pcRect,
                    mb_sids=('nab', ),
                    # always_collide_mb=always_collide_mb,
                )
            # if touchText is not None:
            #     touchText = str(result) + ": " + touchText
            #     print(touchText)
            if result < 2:
                # ^ 2 is for if hat is being pressed down or the
                #   analog stick is past the deadZone and wasn't before.
                continue
            '''
            print(
                "worldmap event result: {}; x:{}; y:{}; pressed:{};"
                " last_read_actuator_info:{}"
                "".format(
                    result,
                    controller1.getInt('x'),
                    controller1.getInt('y'),
                    controller1.getTrues(),
                    last_read_actuator_info(),
                )
            )
            '''

            if controller1.getBool('SCREENSHOT'):
                screenshot(vista.screen)
            if controller1.getInt('x') > 0:
                udseq = []
                if level < record.unlocked:
                    level += 1
                    updateteffect = True
            if controller1.getInt('x') < 0:
                udseq = []
                if level > 1:
                    level -= 1
                    updateteffect = True
            upValue = controller1.getInt('y') < 0
            downValue = controller1.getInt('y') > 0
            if (upValue or downValue) and not easy_locked():
                udseq.append(0 if upValue else 1)
                # Activate Easy Mode
                if len(udseq) >= 8 and tuple(
                        udseq[-8:]) == (0, 0, 1, 1, 0, 0, 1,
                                        1) and not settings.easy:
                    settings.easy = True
                    esign = effect.EasyModeIndicator(["Easy Mode Activated!"])
                    esign.position(vista.screen)
                    udseq = []
                    noise.play("cha-ching")
                # Display all cut scenes
                if len(udseq) >= 8 and tuple(
                        udseq[-8:]) == (0, 1, 1, 1, 1, 0, 0, 0):
                    settings.alwaysshow = True
                    for level in (1, 2, 3, 4, 5, 6, 7):
                        if level in (1, 4):
                            noise.play("gnos")
                        if level in (2, 5):
                            noise.play("one")
                        if level in (3, 6):
                            noise.play("xylo")
                        cutscene()
                    rollcredits()
                    theend()
                # Delete the saved game
                if len(udseq) >= 8 and tuple(
                        udseq[-8:]) == (0, 1, 0, 0, 1, 0, 1, 1):
                    game.remove()
                    rsign = effect.EasyModeIndicator(["Save game deleted!"])
                    rsign.position(vista.screen)
                    udseq = []
                    noise.play("cha-ching")
            if controller1.getBool('nab'):
                # Enter an area (exit the world map):
                print("* exiting world map")
                controller1._states['x'] = 0
                return

            if controller1.getBool('FULLSCREEN'):
                settings.fullscreen = not settings.fullscreen
                vista.init()

        if updateteffect:
            teffect.update(levelnames[level - 1])
            teffect.position(vista.screen)
            updateteffect = False

        hstext = "high score: LLL%s" % record.hiscore[
            level] if level in record.hiscore else ""
        hseffect.update(hstext)
        hseffect.position(vista.screen)
        if (esign is not None) and is_active(esign):
            esign.think(dt)
        if (rsign is not None) and is_active(rsign):
            rsign.think(dt)
            if not is_active(rsign):
                sys.exit()

        vista.mapclear()
        for j in range(1, record.unlocked):
            x0, y0 = levelps[j - 1]
            x1, y1 = levelps[j]
            vista.line((x0, y0 - 6), (x1, y1 - 6), (0, 0, 0), (200, 200, 200))
        for p in levelps:
            sprite.frames["leveldisk"].draw(p)
        sprite.frames["stand"].draw(levelps[level - 1])
        pcRect = vista.get_frame_screen_rect(
            sprite.frames["stand"],
            levelps[level - 1],
            width=sprite.frames["stand"].image.get_rect().width * .7,
        )
        pcPos = vista.get_screen_pos(levelps[level - 1])
        # ^ Player Character

        teffect.draw(vista.screen)
        #        speffect.draw(vista.screen)
        hseffect.draw(vista.screen)
        hceffect.draw(vista.screen)
        if is_active(esign):
            esign.draw(vista.screen)
        if is_active(rsign):
            rsign.draw(vista.screen)
        if pcRect is not None:
            if settings.visualDebug:
                pygame.draw.rect(vista.screen, idleColor, pcRect)
        if is_active(touchEffect):
            # touchEffect.draw(vista.screen, center=touchEffectPos)
            touchEffect.draw(vista.screen)
            pygame.draw.circle(vista.screen, touchColor,
                               (touchEffect.x0, touchEffect.y0), 10)
        pygame.display.flip()