对于玩家可以选择移动的数量,我有一个最大值和最小值。但是每次单击输入时,我都想增加这些值的最大值和最小值。
玩家1的运动:
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
if not left_held: # Check if the left key was not previously held
left_held = True
left = max(left - 1, -1)
elif key[pygame.K_RIGHT]:
if not right_held: # Check if the right key was not previously held
right_held = True
left = min(left + 1, 1)
else:
left_held = False
right_held = False
#check for player movement in y direction
if key[pygame.K_UP]:
if not up_held: # Check if the up key was not previously held
up_held = True
up = max(up - 1, -1)
elif key[pygame.K_DOWN]:
if not down_held: # Check if the down key was not previously held
down_held = True
up = min(up + 1, +1)
else:
up_held = False
down_held = False
现在左上角的最大值和最小值分别为 1 和 -1,但是当我按下回车键时,我想将最大值和最小值更改为 2 和 -2。
按下回车键时:
if key[pygame.K_RETURN] and not enter_pressed:
dx1 = left
dy1 = up
enter_pressed = True
current_player = player2
# Increase the maximum and munimum values of up and left
max_up = max(up - 1, max_up)
max_left = max(left, max_left)
min_up = min(up, min_up)
min_left = min(left, min_left)
elif not key[pygame.K_RETURN]:
dx1 = 0
dy1 = 0
enter_pressed = False