所以我在做一个回合制游戏,玩家可以选择3次攻击,我尝试的方法是为每次攻击创建一个布尔值,并将其设置为false,当其设置为true时,对手的健康栏将绘制一个白色矩形,以创建伤害效果,并播放动画,但我不知道如何使其可重复使用“攻击”布尔值,这意味着每次玩家使用它时,rect都会变长一定数量。现在,攻击只能使用一次,它绘制一个矩形。动画也会重复播放,因为布尔值设置为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()
导入此项工作所需的时间。问题是您正在基于固定值绘制矩形。我基于HP定义了矩形的长度和起点。此外,我建议在attack.png中将HP条从黑色改为白色,然后绘制一个灰色HP条,而不是在完整HP上绘制一个白色矩形。您需要用类似这样的东西绘制灰色矩形:pygame.draw.rect(scr,gray,(203,80200敌方.getHP()*2,8))。 我最重要的建议是为你的口袋妖怪和敌人的口袋妖怪创建包含HP和其他所需信息的类。然后在内部创建方法来更改和返回信息。这也适用于你放在口袋妖怪对象和你的角色中包含口袋妖怪对象列表的攻击。上面的代码只是扩展的开始。希望这有帮助,祝你好运!:)
相关问题 更多 >
编程相关推荐