抑制pycharm欢迎消息暂停程序

zte4gxcn  于 5个月前  发布在  PyCharm
关注(0)|答案(1)|浏览(78)

我试图做一个小口袋妖怪游戏,我试图有两个窗口弹出使用pygame.当第一个窗口弹出与敌人口袋妖怪,我抑制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)

字符串

4uqofj5v

4uqofj5v1#

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)

字符串

相关问题