抑制pycharm欢迎消息暂停程序

问题描述 投票:0回答:1

我正在尝试制作一个小型口袋妖怪游戏,并且正在尝试使用 pygame 有两个 Windows 弹出窗口。当第一个窗口弹出并显示敌方 Pokemon 时,我会抑制 pygame 欢迎消息,但当我这样做时,它会暂停程序并坐在那里 - 不允许执行下一个函数。

我正在使用控制台完成所有这些操作。

import sys
import variables
import time
import os
os.environ["SDL_AUDIODRIVER"] = "dummy"
os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"

time.sleep(0.5)

import pygame

# Get Pokemon name
pokemon_name = variables.get_pokemons_name

# Constants
WIDTH, HEIGHT = 300, 150
WHITE = (255, 255, 255)
RED = (255, 0, 0)

# Pokemon Health Bar
pokemon_health = 100
max_health = 100

# Load Pokemon Image
pokemon_image = (
    pygame.image.load("C:/Users/Samuel~1/Desktop/PokeMonSounds/Images/"
                      + variables.get_pokemons_name + ".png"))
# Replace "pokemon.png" with the actual image file

# Resize image
new_width = 100
new_height = 100
resized_image = pygame.transform.scale(pokemon_image, (new_width, new_height))

# Set up the display
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(variables.get_pokemons_name)

# Main game loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Update health bar based on user input (for demonstration purposes)
    # keys = pygame.key.get_pressed()
    # if keys[pygame.K_SPACE]:
        # pokemon_health -= 1

    # Draw background
    screen.fill(WHITE)

    # Draw Pokemon image
    screen.blit(resized_image, (WIDTH // 2 - new_width // 2, HEIGHT // 2 - new_height // 2))

    # Draw health bar border
    pygame.draw.rect(screen, RED, (50, 10, max_health, 20), 2)

    # Draw health bar
    pygame.draw.rect(screen, RED, (50, 10, pokemon_health, 20))

    # Update the display
    pygame.display.flip()

    # Cap the frame rate
    pygame.time.Clock().tick(30)

python pycharm
1个回答
0
投票
check this code


# Set up the display
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(variables.get_pokemons_name)

# Create the clock outside the loop
clock = pygame.time.Clock()

# Main game loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Update health bar based on user input (for demonstration purposes)
    # keys = pygame.key.get_pressed()
    # if keys[pygame.K_SPACE]:
        # pokemon_health -= 1

    # Draw background
    screen.fill(WHITE)

    # Draw Pokemon image
    screen.blit(resized_image, (WIDTH // 2 - new_width // 2, HEIGHT // 2 - new_height // 2))

    # Draw health bar border
    pygame.draw.rect(screen, RED, (50, 10, max_health, 20), 2)

    # Draw health bar
    pygame.draw.rect(screen, RED, (50, 10, pokemon_health, 20))

    # Update the display
    pygame.display.flip()

    # Cap the frame rate
    clock.tick(30)
© www.soinside.com 2019 - 2024. All rights reserved.