Я пытаюсь сделать прицел в пигме. Однако, когда я нажимаю на врага, программа не выполняет удар (я не думаю), я слышу звук, но враг не исчезает. Когда я нажимаю на цель, она должна исчезнуть, и на экране появляется новый набор. Я очень новичок в кодировании, поэтому любая помощь приветствуется.
def game(difficulty):
config = populateConfig(difficulty)
pygame.mouse.set_visible(False)
mouseY = (WINDOWHEIGHT / 2)
mouseX = (WINDOWWIDTH / 2)
pointerImg_rect = pointerImg.get_rect()
tickCounter = 0
enemies = []
amountOfEnemies = 0
score = 0
FPS = 75
hitShots = 0
totalShots = 0
STARTINGTIME = config.get("time")
CIRCLERADIUS = 150
while True:
if(config.get("time") <= 0):
gameOver(totalShots, hitShots, difficulty, score)
tickCounter += 1
if(tickCounter % FPS == 0):
config["time"] -= 1
windowSurface.fill(WHITE)
if (amountOfEnemies == 0):
config["time"] = STARTINGTIME
while(amountOfEnemies != config.get("maxAmountOfEnemies")):
enemies.append(pygame.Rect((random.randint(0,WINDOWWIDTH - config.get("enemySize"))),
(random.randint(0,WINDOWHEIGHT - config.get("enemySize"))),
config.get("enemySize"), config.get("enemySize")))
if enemies[amountOfEnemies].topleft[0] < 135 and enemies[amountOfEnemies].topleft[1] < 65:
enemies.pop(amountOfEnemies)
else:
amountOfEnemies += 1
for event in pygame.event.get():
if event.type == QUIT:
terminate()
if event.type == KEYDOWN:
pass
if event.type == KEYUP:
if event.key == K_ESCAPE:
terminate()
if event.type == MOUSEMOTION:
pointer_rect.center = event.pos
if event.type == MOUSEBUTTONDOWN:
pygame.mixer.Channel(0).play(shootSound)
totalShots += 1
for enemy in enemies[:]:
if mouseX > enemy.topleft[0] and mouseX < enemy.bottomright[0]\ **this is the issue*
and mouseY > enemy.topleft[1] and mouseY < enemy.bottomright[1]:
pygame.mixer.Channel(1).play(hitSound)
enemies.remove(enemy)
amountOfEnemies -= 1
score += 1
hitShots += 1
for enemy in enemies:
windowSurface.blit(targetImage, enemy)
windowSurface.blit(pointerImg, pointer_rect)
drawText("Time: " + str(config.get("time")), windowSurface, 8,8)
drawText("Score: " + str(score), windowSurface, 8,38)
pygame.display.update()
mainClock.tick(FPS)
Menu()```