[ad_1]
我已经做到了,如果你点击你会转到屏幕中间,但我只希望当你在死亡屏幕上时发生这种情况,当你离开屏幕时会发生这种情况我该如何做,这样点击只有在死亡时才起作用屏幕显示
我尝试过的:
import pygame import random SCREEN_WIDTH = 800 SCREEN_HIEGHT = 600 gravity = 4 pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HIEGHT)) bg_image = pygame.image.load('Background.png') bg_rect = bg_image.get_rect() losing_image = pygame.image.load('losing screen.png') losing_rect = losing_image.get_rect() player_image = pygame.image.load('Character.png') player_rect = player_image.get_rect() player_rect.x = 30 player_rect.y = 300 dead = False clock = pygame.time.Clock() run = True score = 0 while run: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: player_rect.y = 300 player_rect.x= 30 if event.type == pygame.QUIT: run = False key = pygame.key.get_pressed() if key[pygame.K_w]: player_rect.y -= 7 if player_rect.y < 790: player_rect.y += gravity screen.fill((0,0,0)) screen.blit(bg_image, bg_rect) screen.blit(player_image, player_rect, ) if player_rect.y >= 580: dead = True screen.blit(losing_image, losing_rect) pygame.display.flip() pygame.display.update() clock.tick(60) pygame.quit()
解决方案1
您无法控制何时引发事件。 您只能设置一个条件,当您的事件处理程序被调用时,您检查显示“死亡屏幕”的游戏状态(在您的情况下是一个标志),然后进行相应的处理。 当您的“死亡屏幕”显示时,您必须设置该标志(设置为 true),然后在适当的时候重置该标志(设置为 false)。
[ad_2]
コメント