예제 #1
0
def initiateSwap():
    '''Called when player clicks Swap'''

    # If backup mon is fainted, Player cannot swap
    if cfg.p1Backup['CurrentHP'] == 0:
        draw.resetGameDisplay()
        draw.character('normal', 1)
        draw.character('normal', 2)
        draw.messageBox("You can't swap right now!",
                        "Your backup Mon is already fainted.")
        draw.pausePrompt(200)
        return

    # If player has used all three swaps, Player cannot swap
    elif cfg.timesSwapped >= 3:
        draw.resetGameDisplay()
        draw.character('normal', 1)
        draw.character('normal', 2)
        draw.messageBox("You can't swap right now!",
                        "You have used all three of your swaps.")
        draw.pausePrompt(200)
        return

    p1Move, p2Move, = defineMoves()

    if cfg.p1Primary['SPD'] > cfg.p2Primary['SPD']:
        print('P1 moves first')
        playerMove('S', 1)
        cfg.timesSwapped += 1
        p1Move, p2Move, = defineMoves()
        playerMove(p2Move, 2)

    elif cfg.p2Primary['SPD'] > cfg.p1Primary['SPD']:
        print('P2 moves first')
        playerMove(p2Move, 2)
        p1Move, p2Move, = defineMoves()
        playerMove('S', 1)
        cfg.timesSwapped += 1

    else:
        print('Both Pius Mon have same SPD stat! Starting coin toss...')
        coinToss = random.choice([1, 2])
        if coinToss == 1:
            print('P1 moves first')
            playerMove('S', 1)
            cfg.timesSwapped += 1
            p1Move, p2Move, = defineMoves()
            playerMove(p2Move, 2)
        else:
            print('P2 moves first')
            playerMove(p2Move, 2)
            p1Move, p2Move, = defineMoves()
            playerMove('S', 1)
            cfg.timesSwapped += 1

    print('Times swapped:', cfg.timesSwapped)

    # Add turn to stats
    cfg.newStats['Turns'] += 1
예제 #2
0
def gameLoop():
    '''This scene comprises the main Pius Mon game flow.'''
    # Music
    pygame.mixer.music.load('Sounds\BattleMusic.mp3')
    pygame.mixer.music.play(-1)

    # Set Mon and trainer name
    logic.setMon(cfg.primaryPick, cfg.backupPick)
    cfg.trainerName = 'Trainer Pat'

    # Start game intro cinematic
    gameIntro(cfg.trainerName)

    # Add turn to stats
    cfg.newStats['Turns'] += 1

    draw.resetGameDisplay()
    draw.character('normal', 2)
    draw.character('normal', 1)
    draw.movePrompt('What will ' + cfg.p1Primary['Name'] + ' do?')
    pygame.display.update()
    sleep(0.5)

    inGame = True
    while inGame:
        for event in pygame.event.get():
            ##print(event)
            if event.type == QUIT:
                logic.quitGame()
            if event.type == pygame.KEYDOWN:
                # Player chooses to attack
                if event.key == pygame.K_RETURN:
                    logic.initiateAttack()

                    draw.resetGameDisplay()
                    draw.character('normal', 2)
                    draw.character('normal', 1)
                    draw.movePrompt('What will ' + cfg.p1Primary['Name'] +
                                    ' do?')
                    pygame.display.update()
                    sleep(0.5)

                # Player chooses to swap
                if event.key == pygame.K_s:
                    logic.initiateSwap()

                    draw.resetGameDisplay()
                    draw.character('normal', 2)
                    draw.character('normal', 1)
                    draw.movePrompt('What will ' + cfg.p1Primary['Name'] +
                                    ' do?')
                    pygame.display.update()
                    sleep(0.5)

        draw.resetGameDisplay()

        # Draw characters
        draw.character('normal', 2)
        draw.character('normal', 1)

        draw.movePrompt('What will ' + cfg.p1Primary['Name'] + ' do?')

        # Buttons
        draw.button('Attack', 390, 520, 150, 50, cfg.red, cfg.brightRed,
                    cfg.white, logic.initiateAttack)
        draw.button('Swap', 560, 520, 150, 50, cfg.waterBlue, cfg.iceBlue,
                    cfg.black, logic.initiateSwap)

        pygame.display.update()
        cfg.clock.tick(30)
예제 #3
0
def gameIntro(trainerName):
    '''Displays the game intro scene.
    This scene introduces the opponent and the two Mon who will be fighting.

    trainerName -- nickname of the human player
    '''
    inIntro = True
    while inIntro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                logic.quitGame()
        cfg.gameDisplay.fill(cfg.white)
        cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
        x = cfg.displayWidth
        rect = cfg.TrainerEthan.get_rect()
        rect.center = ((cfg.displayWidth / 2), (cfg.displayHeight / 2))
        cfg.gameDisplay.blit(cfg.TrainerEthan, rect)

        # Trainer moves to center of screen
        cinematic = True
        while cinematic:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    logic.quitGame()
            x -= 20
            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            rect = cfg.TrainerEthan.get_rect()
            rect.center = ((x), (cfg.displayHeight / 2))
            cfg.gameDisplay.blit(cfg.TrainerEthan, rect)
            draw.messageBox('Trainer Ethan challenges you to a battle!', '')
            pygame.display.update()
            cfg.clock.tick(60)

            # Stop moving when image is at center of screen
            if x <= cfg.displayWidth / 2:
                cinematic = False

        draw.messageBox('Trainer Ethan challenges you to a battle!', '')
        draw.pausePrompt(600)

        cfg.gameDisplay.fill(cfg.white)
        cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
        draw.platform(2)
        draw.character('normal', 2)
        draw.messageBox(
            'Trainer Ethan sent out ' + cfg.p2Primary['Name'] + '!', '')
        draw.pausePrompt(200)

        cfg.gameDisplay.fill(cfg.white)
        cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
        draw.platform(1)
        draw.character('normal', 1)
        draw.messageBox(
            trainerName + ' sent out ' + cfg.p1Primary['Name'] + '!', '')

        draw.platform(2)
        draw.character('normal', 2)

        draw.pausePrompt(200)

        inIntro = False
예제 #4
0
def playerMove(action, player):
    '''Called when a Mon (on either team) makes a move.

    action -- A1/A2/A3 (attack) or S (for swap)
    player -- 1 (human) or 2 (AI)
    '''
    # Called when player 1 OR player 2 moves
    if player == 1:
        p1rect = cfg.MegabiteNormal.get_rect()
        p1rect.bottomleft = (32, 430)
        p2rect = cfg.SnowbroNormal.get_rect()
        p2rect.bottomleft = (530, 234)

        # In case player cannot swap
        p1Move, p2Move = defineMoves()

        # Player 1 attacks
        if len(action) > 1 or cfg.p1Backup['CurrentHP'] <= 0:
            if action == 'S':
                action = p1Move

            # Reset display
            draw.resetGameDisplay()
            draw.character('normal', 2)
            draw.messageBox(cfg.p1Primary['Name'] + ' used ' + action + '!',
                            '')

            # Player attack animation
            draw.character('attack', 1)
            draw.pausePrompt(200)

            # Reset display
            draw.resetGameDisplay()
            draw.character('normal', 1)

            # Only performs attack
            damage, powerMsg, fainted = playerAttacks(action, 1)
            if fainted:
                return

            # Reset display
            draw.resetGameDisplay()
            draw.character('normal', 1)

            if powerMsg == 'SuperE':
                print('Super effective attack')
                draw.messageBox(
                    cfg.p1Primary['Name'] + " attacks for " + str(damage) +
                    " damage.", "It's super effective!")
            elif powerMsg == 'NotVE':
                print('Not very effective attack')
                draw.messageBox(
                    cfg.p1Primary['Name'] + " attacks for " + str(damage) +
                    " damage.", "It's not very effective...")
            else:
                draw.messageBox(
                    cfg.p1Primary['Name'] + " attacks for " + str(damage) +
                    " damage.", '')

            # Update health bars
            draw.healthBar(1)
            draw.healthBar(2)

            # Enemy hit animation
            draw.character('hit', 2)
            draw.pausePrompt(200)

        # Player 1 swaps
        else:
            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.character('normal', 2)
            draw.messageBox('Come back, ' + cfg.p1Primary['Name'] + '!', '')
            draw.pausePrompt(200)

            # Swap occurs
            swapMon(1)

            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            draw.platform(2)
            draw.character('normal', 2)
            draw.healthBar(2)

            pygame.display.update()
            sleep(0.6)

            draw.messageBox('Go, ' + cfg.p1Primary['Name'] + '!', '')
            draw.pausePrompt(200)

            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.character('normal', 2)
            pygame.display.update()
            sleep(0.2)

    else:
        # Player 2 attacks
        if len(action) > 1 or cfg.p2Backup['CurrentHP'] <= 0:
            if action == 'S':
                action = p2Move

            # Reset display
            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.messageBox(cfg.p2Primary['Name'] + ' used ' + action + '!',
                            '')

            # Player attack animation
            draw.character('attack', 2)
            draw.pausePrompt(200)

            # Reset display
            draw.resetGameDisplay()
            draw.character('normal', 2)

            # Only performs attack
            damage, powerMsg, fainted = playerAttacks(action, 2)
            if fainted:
                return

            # Reset display
            draw.resetGameDisplay()
            draw.character('normal', 2)

            if powerMsg == 'SuperE':
                print('Super effective attack')
                draw.messageBox(
                    cfg.p2Primary['Name'] + " attacks for " + str(damage) +
                    " damage.", "It's super effective!")
            elif powerMsg == 'NotVE':
                print('Not very effective attack')
                draw.messageBox(
                    cfg.p2Primary['Name'] + " attacks for " + str(damage) +
                    " damage.", "It's not very effective...")
            else:
                draw.messageBox(
                    cfg.p2Primary['Name'] + " attacks for " + str(damage) +
                    " damage.", '')

            # Update health bars
            draw.healthBar(1)
            draw.healthBar(2)

            # Enemy hit animation
            draw.character('hit', 1)
            draw.pausePrompt(200)

        # Player 2 swaps
        else:
            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.character('normal', 2)
            draw.messageBox(
                'Trainer Ethan is calling back ' + cfg.p2Primary['Name'] + '!',
                '')
            draw.pausePrompt(200)

            # Swap occurs
            swapMon(2)

            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            draw.platform(1)
            draw.character('normal', 1)
            draw.healthBar(1)

            pygame.display.update()
            sleep(0.6)

            draw.messageBox(
                'Trainer Ethan sent out ' + cfg.p2Primary['Name'] + '!', '')
            draw.pausePrompt(200)

            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.character('normal', 2)
            pygame.display.update()
            sleep(0.2)
예제 #5
0
def checkIfFainted():
    '''Checks if a player's primary Mon is fainted.

    Return parameter:
        fainted -- boolean
    '''
    fainted = False
    if cfg.p1Primary['CurrentHP'] <= 0:
        fainted = True
        print('p1 primary mon fainted')

        # Perform swap if fainted
        draw.resetGameDisplay()
        draw.character('hit', 1)
        draw.character('normal', 2)
        draw.messageBox(cfg.p1Primary['Name'] + ' fainted!', '')
        draw.pausePrompt(200)

        if cfg.p1Backup['CurrentHP'] <= 0:
            # Player loses, AI wins
            print('p1 loses')
            win = False

            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            draw.platform(2)
            draw.healthBar(2)
            draw.character('normal', 2)
            draw.messageBox('You have lost the battle!', '')
            draw.pausePrompt(600)
            screens.resultsScreen(win)

        # Swap occurs
        else:
            swapMon(1)

            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            draw.platform(2)
            draw.character('normal', 2)
            draw.healthBar(2)

            pygame.display.update()
            sleep(0.6)

            draw.messageBox('Go, ' + cfg.p1Primary['Name'] + '!', '')
            draw.pausePrompt(200)

            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.character('normal', 2)
            pygame.display.update()
            sleep(0.2)

    elif cfg.p2Primary['CurrentHP'] <= 0:
        fainted = True
        print('p2 primary mon fainted')

        # Perform swap if fainted

        draw.resetGameDisplay()
        draw.character('normal', 1)
        draw.character('hit', 2)
        draw.messageBox(cfg.p2Primary['Name'] + ' fainted!', '')
        draw.pausePrompt(200)

        if cfg.p2Backup['CurrentHP'] <= 0:
            # Player wins
            print('p1 wins')
            win = True

            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            draw.platform(1)
            draw.healthBar(1)
            draw.character('normal', 1)
            draw.messageBox('You have won the battle!', '')
            draw.pausePrompt(600)
            screens.resultsScreen(win)

        # Swap occurs
        else:
            swapMon(2)

            cfg.gameDisplay.fill(cfg.white)
            cfg.gameDisplay.blit(cfg.gameBackground, (0, 0))
            draw.platform(1)
            draw.character('normal', 1)
            draw.healthBar(1)

            pygame.display.update()
            sleep(0.6)

            draw.messageBox(
                'Trainer Ethan brought out ' + cfg.p2Primary['Name'] + '!', '')
            draw.pausePrompt(200)

            draw.resetGameDisplay()
            draw.character('normal', 1)
            draw.character('normal', 2)
            pygame.display.update()
            sleep(0.2)

    return fainted