Пример #1
0
def confirm_title_screen_interpreter(keyEvent):
    global previousMode
    if keyEvent.key == K_y: 
        global showTitleScreen
        showTitleScreen = True
        save(previousMode)
    elif keyEvent.key == K_n:
        import titleScreen
        titleScreen.title_screen()
        return
    elif keyEvent.key == K_BACKSPACE:
        if previousMode is None:
            previousMode = town_mode
        previousMode()
Пример #2
0
def main(window_style=0):
    pygame.init()
    if pygame.mixer and not pygame.mixer.get_init():
        print('Warning, no sound')
        pygame.mixer = None

    window_style = 0  # |FULLSCREEN
    best_depth = pygame.display.mode_ok(screen_rect.size, window_style, 32)
    screen = pygame.display.set_mode(screen_rect.size, window_style, best_depth)
    pygame.display.set_caption(CAPTION)

    splash_intro(screen)
    title_screen(screen, screen_rect)
    main_menu(screen, screen_rect)
    #game_play(screen, screen_rect)

    if pygame.mixer:
        pygame.mixer.music.fadeout(1000)
    pygame.time.wait(1000)
    pygame.quit()
Пример #3
0
def save_game(saveName, previousModeIn=None, preserveSaveName=True):
    global previousMode
    if previousModeIn is not None:
        previousMode = previousModeIn
    if not os.path.exists(saveDirectory):
        os.makedirs(saveDirectory)
    if saveName.split('.')[-1] != 'sav':
        saveName += '.sav'
    with open(os.path.join(saveDirectory, saveName), 'wb') as saveFile:
        universal.state.save(saveFile)
        saveFile.flush()
    global showTitleScreen, previousMode
    if quitting:
        quit()
    elif showTitleScreen:
        import titleScreen
        showTitleScreen = False
        titleScreen.title_screen()
    else:
        if previousMode is not None:
            previousMode()
        else:
            town_mode()
Пример #4
0
def to_title_screen_interpreter(keyEvent):
    universal.clear_screen()
    if keyEvent.key == universal.K_RETURN:
        titleScreen.title_screen()
Пример #5
0
def begin_game(episode):
    global displayedText
    global commands
    global screen
    global font
    import os
    if '.init.sav' in os.listdir('save'):
        os.remove(os.path.join('save', '.init.sav'))
# Initialise screen
    #commandText = textrect.render_textrect(' '.join(commands), font, commandView, LIGHT_GREY, DARK_GREY, 1)
    #commandTextPos = commandText.get_rect()
    #commandTextPos.centerx, commandTextPos.centery = commandView.center;
    # Blit everything to the screen
    defaultFont = pygame.font.SysFont(universal.FONT_LIST, universal.DEFAULT_SIZE)
    titleFont = pygame.font.SysFont(universal.FONT_LIST_TITLE, universal.TITLE_SIZE)
    universal.init_game()
    background = universal.get_background()
    screen = universal.get_screen()
    screen.blit(background, (0, 0))
    commandView = universal.get_command_view()
    worldView = universal.get_world_view()
    #commandSurface = pygame.Surface((commandView.width, commandView.height))
    #commandSurface.fill((255, 0, 0))
    #commandSurface.fill(DARK_GREY)
    #commandSurface.fill(LIGHT_GREY)
    #pygame.display.flip()
    leftCommandView = universal.get_left_command_view()
    rightCommandView = universal.get_right_command_view()
    middleCommandView = universal.get_middle_command_view()
    dirtyRects = titleScreen.title_screen(episode)
    #screen.blit(commandSurface, commandView.topleft)
    #screen.blit(background, (0,))
    # Event loop
    #fps = 30
    #clock = pygame.time.Clock()
    while True:
        #screen.blit(commandSurface, commandView.topleft)
        #pygame.draw.rect(commandSurface, LIGHT_GREY, commandView, 5)
        #Technically, this for loop is silly now, because I'm only allowing one event in
        #queue at a time. (Search for CLEAR) 
        for event in pygame.event.get():
            if event.type == KEYUP:
                if event.key == K_LSUPER or event.key == K_RSUPER: 
                    pygame.display.iconify()
                else:
                    #CLEAR
                    #This will have to be changed if I ever implement something that requires rapid key combinations.
                    pygame.event.clear()
                    newDirtyRects = universal.get_command_interpreter()(event)
                    try:
                        dirtyRects.extend(newDirtyRects)
                    except TypeError:
                        pass
            elif event.type == QUIT:
                music.close_music_files()
                import os
                if '.init.sav' in os.listdir('save'):
                    os.remove(os.path.join('save', '.init.sav'))
                music.clean_up_music()
                return
            if universal.get_text_to_display() != '':
                if universal.get_title_text() != '':
                    position = (worldView.topleft[0], worldView.topleft[1] + titleFont.get_linesize())
                    textRect = worldView.copy()
                    textRect.height = textRect.height - titleFont.get_linesize()
                    universal.display_text(universal.get_title_text(), worldView, position, isTitle=True)
                displayPosition = (worldView.topleft[0], worldView.topleft[1] + 2 * titleFont.get_linesize())
                textRect = worldView.copy()
                dirtyRects.append(textRect)
                textRect.height = textRect.height - 2 * titleFont.get_linesize()
                universal.display_text(universal.get_text_to_display(), textRect, displayPosition, isTitle=False)
                universal.clear_text_to_display()
        #The following is a bit of command position fiddling to make everything look nice and balanced.
        universal.display_commands()
        pygame.draw.rect(screen, universal.LIGHT_GREY, pygame.Rect(commandView.topleft, commandView.size), universal.COMMAND_VIEW_LINE_WIDTH)
        #pygame.display.flip()
        #clock.tick_busy_loop(fps)
        newDirtyRects = []
        #Bonemouth was having a strange error where the game would crash when trying to save, apparently because the game only takes one list of dirty rects? Not sure, and couldn't replicate it,
        #and of course the error message doesn't actually print the value of dirty rects :-/, so I can't figure out what dirty rects look like when the bug is thrown. So I'm assuming for some
        #strange reason I'm ending up with a nested list. So I flatten it first. Note that since every atomic element is a rectangle, and those aren't iterable, we don't need to worry about 
        #accidentally flattening tuples or strings.
        for maybeList in dirtyRects:
            if isinstance(maybeList, pygame.Rect):
                newDirtyRects.append(maybeList)
            else:
                newDirtyRects.extend(maybeList)
        newDirtyRects.append(get_command_view())
        #Wine doesn't play nice with the dirty rects approach, so if we are running under Wine, then we update everything forever.
        if universal.playOnMac:
            pygame.display.flip()
        elif dirtyRects:
            pygame.display.update(newDirtyRects)
        dirtyRects = []