我正在 pygame 中制作一个简单的游戏应用程序,但无法弄清楚如何让用户反复点击敌人进行交互(如射击),而不仅仅是按住鼠标。请帮忙!这是我的代码。
import pygame, sys
from pygame.locals import *
from time import *
bif="map.jpg"
enemy="squarecharacter.png"
pygame.init()
screen=pygame.display.set_mode((1000,550), 0, 32)
background=pygame.image.load(bif).convert()
square1=pygame.image.load(enemy).convert_alpha()
square1_x,square1_y=(300,300)
clock=pygame.time.Clock()
speed=50
square_health1=100
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
screen.blit(background, (0,0))
screen.blit(square1, (square1_x,square1_y))
mousepos_x,mousepos_y=pygame.mouse.get_pos()
button1, button2, button3=pygame.mouse.get_pressed()
if mousepos_x in range((int(square1_x)),(int(square1_x+50))) and mousepos_y in range((int(square1_y)),(int(square1_y+50))):
if button1==1:
square_health1-=10
button1-=1
print str(square_health1)
continue