Пример #1
0
def Paused():
    global pause

    # Remove original button
    pygame.draw.rect(game_display, Tool.white,
                     (display_width * 0.7, display_height * 0.7,
                      display_width * 0.2, display_height * 0.1))
    pygame.draw.rect(game_display, Tool.white,
                     (display_width * 0.7, display_height * 0.85,
                      display_width * 0.2, display_height * 0.1))

    pause = True
    #pygame.draw.rect(game_display, red,[display_width*(0.7+0.0195*i) + 1, display_height*0.42 + 1, display_width * 0.02 - 2, display_height*0.06 - 2])
    large_text = pygame.font.Font("freesansbold.ttf", 115)
    text_surf, text_rect = Tool.TextObjects("Paused", large_text, Tool.red)
    text_rect.center = ((display_width * 0.6 / 2), (display_height * 0.4))

    while pause:
        game_display.blit(text_surf, text_rect)

        Tool.Button(game_display, "Continue", display_width * 0.05,
                    display_height * 0.7, display_width * 0.6 * 0.3,
                    display_height * 0.2, Tool.green, Tool.bright_green,
                    Unpause)
        Tool.Button(game_display, "Quit", display_width * 0.38,
                    display_height * 0.7, display_width * 0.6 * 0.3,
                    display_height * 0.2, Tool.red, Tool.bright_red, QuitGame)

        for event in pygame.event.get():
            Tool.CheckAltF4(event)
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    Unpause()

            if event.type == pygame.QUIT:
                QuitGame()

        pygame.display.update()
        clock.tick(15)
    game_display.blit(background_photo, [0, 0])
Пример #2
0
def GameStart():
    """Define Game Intro screen"""
    intro = True

    button_width_factor = 0.18
    button_height_factor = 0.1

    def StartGame():
        nonlocal intro
        intro = False

    def StartButton():
        button_width_factor = 0.18
        button_height_factor = 0.1
        Tool.Button(game_display, "START", display_width / 2 * 0.8,
                    display_height * 0.65, display_width * button_width_factor,
                    display_height * button_height_factor, Tool.green,
                    Tool.bright_green, StartGame)

    def TogglePlayer2():
        Tool.players = 2
        P1_text = game_font.render("1P", True, Tool.white)
        game_display.blit(P1_text, P1_rect)
        P2_text = game_font.render("2P", True, Tool.red)
        game_display.blit(P2_text, P2_rect)
        clock.tick(20)

    def TogglePlayer1():
        Tool.players = 1
        P1_text = game_font.render("1P", True, Tool.red)
        game_display.blit(P1_text, P1_rect)
        P2_text = game_font.render("2P", True, Tool.white)
        game_display.blit(P2_text, P2_rect)
        clock.tick(20)

    # Game Intro background display
    intro_background = pygame.image.load('BackgroundIntro.png')
    intro_background = pygame.transform.scale(
        intro_background, (display_width, display_height + 30))
    game_display.blit(intro_background, [0, -30])

    game_font = pygame.font.Font('msjhbd.ttc', 30)
    if Tool.players == 1:
        P1_text = game_font.render("1P", True, Tool.red)
    else:
        P1_text = game_font.render("1P", True, Tool.white)
    P1_rect = P1_text.get_rect()
    P1_rect.center = ((display_width / 2 * 0.78), (display_height * 0.43) - 30)
    game_display.blit(P1_text, P1_rect)

    if Tool.players == 2:
        P2_text = game_font.render("2P", True, Tool.red)
    else:
        P2_text = game_font.render("2P", True, Tool.white)

    P2_rect = P2_text.get_rect()
    P2_rect.center = ((display_width / 2 * 1.12), (display_height * 0.43) - 30)
    game_display.blit(P2_text, P2_rect)
    # Load player mode picture and modify
    one_player_pre = pygame.image.load('小傑正面.png')
    one_player_pre = pygame.transform.scale(one_player_pre,
                                            (Person.width, Person.height))
    one_player_after = pygame.image.load('小傑正面.png')
    one_player_after = pygame.transform.scale(one_player_pre,
                                              (Person.width, Person.height))
    two_player_pre = pygame.image.load('2P_Pre.png')
    two_player_pre = pygame.transform.scale(
        two_player_pre, (Person.width * 2 + 5, Person.height))
    two_player_after = pygame.image.load('2P_Pre.png')
    two_player_after = pygame.transform.scale(
        two_player_pre, (Person.width * 2 + 5, Person.height))

    while intro:
        for event in pygame.event.get():
            Tool.CheckAltF4(event)
            if event.type == pygame.QUIT:
                QuitGame()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    TogglePlayer1()
                if event.key == pygame.K_RIGHT:
                    TogglePlayer2()
                if event.key == pygame.K_SPACE:
                    StartGame()

        StartButton()

        # display player mode button
        Tool.PictureButton(game_display, one_player_pre, one_player_after,
                           display_width / 2 * 0.75,
                           display_height * 0.48 - 15, display_width * 0.18,
                           display_height * 0.1, TogglePlayer1)
        Tool.PictureButton(game_display, two_player_pre, two_player_after,
                           display_width / 2 * 1.05,
                           display_height * 0.48 - 15, display_width * 0.85,
                           display_height * 0.1, TogglePlayer2)
        """
        if Tool.players == 1:
            PlayerOneButton()
        else:
            PlayerTwoButton()
        """

        pygame.display.update()
        clock.tick(15)
Пример #3
0
def GameLoop():
    global game_speed
    game_speed = 60
    global game_exit
    game_exit = False

    Init()
    NonMovingBackgroundDisplay()

    InitializeStairPhotos()

    #initial stair list
    global stair_list
    stair_list = []
    Stair.stair_list = stair_list
    for i in range(8):
        new_stair = Stair.Stair(display_width * 0.6, i)
        stair_list.append(new_stair)
    stair_list[4].x = 300
    stair_list[4].type = "general"

    jie_front = pygame.image.load('小傑正面.png')
    jie_right1 = pygame.image.load('小傑側面_右跨步.png')
    jie_right2 = pygame.image.load('小傑側面_右收步.png')
    jie_left1 = pygame.image.load('小傑側面_左跨步.png')
    jie_left2 = pygame.image.load('小傑側面_左收步.png')
    jie_front = pygame.transform.scale(jie_front,
                                       (Person.width, Person.height))
    jie_right1 = pygame.transform.scale(jie_right1,
                                        (Person.width, Person.height))
    jie_right2 = pygame.transform.scale(jie_right2,
                                        (Person.width, Person.height))
    jie_left1 = pygame.transform.scale(jie_left1,
                                       (Person.width, Person.height))
    jie_left2 = pygame.transform.scale(jie_left2,
                                       (Person.width, Person.height))

    ming_front = pygame.image.load('小銘正面.png')
    ming_right1 = pygame.image.load('小銘側面_右跨步.png')
    ming_right2 = pygame.image.load('小銘側面_右收步.png')
    ming_left1 = pygame.image.load('小銘側面_左跨步.png')
    ming_left2 = pygame.image.load('小銘側面_左收步.png')
    ming_front = pygame.transform.scale(ming_front,
                                        (Person.width, Person.height))
    ming_right1 = pygame.transform.scale(ming_right1,
                                         (Person.width, Person.height))
    ming_right2 = pygame.transform.scale(ming_right2,
                                         (Person.width, Person.height))
    ming_left1 = pygame.transform.scale(ming_left1,
                                        (Person.width, Person.height))
    ming_left2 = pygame.transform.scale(ming_left2,
                                        (Person.width, Person.height))

    global person_list
    person_list = []
    Person.display_width = display_width
    Person.display_height = display_height
    for i in range(Tool.players):
        if i == 0:
            person = Person.Person(300 + 75 + 40 - i * 40,
                                   stair_list[4].y - 60, jie_front, jie_right1,
                                   jie_right2, jie_left1, jie_left2, i + 1)
        elif i == 1:
            person = Person.Person(300 + 75 + 40 - i * 40,
                                   stair_list[4].y - 60, ming_front,
                                   ming_right1, ming_right2, ming_left1,
                                   ming_left2, i + 1)
        person_list.append(person)

    Score.Instance = Score.Score()

    global events

    alt = False
    f4 = False
    while not game_exit:
        try:
            #Update and Display

            BackgroundDisplay()
            events = pygame.event.get()
            for i in range(8):
                stair_list[i].Update(display_width * 0.6)
                """
                for person in person_list:
                    stair_list[i].HitPersonUpdate(person)
                """

            # 附近的樓梯檢查碰撞就好

            for person in person_list:
                try:
                    stair_list[(person.y - 33) // 75].HitPersonUpdate(person)
                except IndexError:
                    pass
                try:
                    stair_list[(person.y - 33) // 75 +
                               1].HitPersonUpdate(person)
                except IndexError:
                    pass

            # person update
            for person in person_list:
                person.Update(events)

            if Tool.players == 2:
                Person.PersonInteraction(person_list)

            Score.Instance.Update()

            GraphicDisplay()

            for event in events:
                Tool.CheckAltF4(event)
                #Quit
                if event.type == pygame.QUIT:
                    QuitGame()

                #Press Space to Pause
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        Paused()
                    if event.key == pygame.K_F4:
                        f4 = True
                    if event.key == pygame.K_LALT or event.key == pygame.K_RALT:
                        alt = True

                if alt and f4:
                    QuitGame()

                if event.type == pygame.KEYUP:
                    if event.key == pygame.K_F4:
                        f4 = False
                    if event.key == pygame.K_LALT or event.key == pygame.K_RALT:
                        alt = False

            pygame.display.update()
            if Score.Instance.current_score % 50 == 0:
                game_speed += 0.2
            clock.tick(int(game_speed))

        except Exceptions.GameOverError:
            game_exit = True