【发布时间】:2020-10-13 07:55:05
【问题描述】:
所以我制作了一个回合制游戏,玩家有 3 次攻击可供选择,我尝试这样做的方式是为每次攻击创建一个布尔值并将其设置为 false,当其设置为 true 时,对手的健康栏会在其上绘制一个白色矩形以创建损坏效果并播放动画,但我不知道如何制作它以便此“攻击”布尔值可重复使用,这意味着每次玩家使用它时矩形都会变长一定量。现在攻击只能使用一次,它会绘制一个矩形,并且动画会一直重复播放,因为布尔值设置为 true,如果我将其设置为 false,那么矩形会消失,我还尝试为每次使用攻击时都会增加的矩形宽度,但由于某种原因,它会给矩形一个边框。我将如何添加这个攻击系统?我附上了下面代码的必要部分,带有必备文件的整个代码是here
Hit = [pygame.image.load('Hit1.png'), pygame.image.load('Hit2.png'), pygame.image.load('Hit3.png')]
hitcount = 0
def attack():
global FlareonX
global FlareonY
global hitcount
f = 0
Ax = 70
Ay = 0
scr_shake = False
quick_attack = False
click = False
cursorX = 230
cursorY = 540
A1 = font.render('Thundershock', True, black)
A2 = font.render('Quick Attack', True, black)
A3 = font.render('Growl', True, black)
A4 = font2.render('Electric', True, yellow)
A5 = font2.render('Normal', True, grey)
drawA4 = False
drawA5 = False
back_black = pygame.image.load('black_back.png')
back_white = pygame.image.load('white_back.png')
button_back = pygame.Rect(75, 200, 50, 50)
running = True
while running:
scr.fill(black)
if scr_shake:
for Ay in [0, 0, 0, 0, 0, 0, -20, -20, -20, -20, -20, -20, 20, 20, 20, 20, 20, 20,]:
scr.fill(black)
scr.blit(attack_scr, (70, Ay))
f += 1
if f >= 9:
break
scr.blit(attack_scr, (Ax, Ay))
scr.blit(Flareon, (470, 0))
scr.blit(A1, (270, 435))
scr.blit(A2, (270, 470))
scr.blit(A3, (270, 505))
scr.blit(Cursor, (cursorX, cursorY))
scr.blit(back_white, (70, 200))
mx, my = pygame.mouse.get_pos()
if button_back.collidepoint((mx, my)):
scr.blit(back_black, (70, 200))
if click:
return
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
if event.type == pygame.KEYDOWN:
if cursorY <= 535 and event.key == pygame.K_DOWN:
cursorY += 35
if cursorY >= 470 and event.key == pygame.K_UP:
cursorY += -35
if cursorY == 435:
drawA5 = False
drawA4 = True
elif cursorY == 470:
drawA4 = False
drawA5 = True
elif cursorY == 505:
drawA4 = False
drawA5 = True
elif cursorY >= 505:
drawA4 = False
drawA5 = False
# ATTACK MECHANISM
if cursorY == 470 and event.key == pygame.K_RETURN:
quick_attack = True
if drawA4:
scr.blit(A4, (265, 310))
if drawA5:
scr.blit(A5, (265, 310))
if hitcount + 2 >= 22:
hitcount = 0
if quick_attack:
scr.blit(Hit[hitcount // 7], (FlareonX, FlareonY))
scr_shake = True
hitcount += 2
pygame.draw.rect(scr, white, (373, 79, 30, 8))
pygame.display.update()
【问题讨论】: