Flash事件在输入时停止

时间:2015-04-01 16:35:56

标签: python pygame

我正在尝试添加一个胜利事件,导致屏幕快速闪烁蓝色和黄色,但出现了问题。最初,我尝试了一个等待函数,但问题是它在那段时间内冻结了其他所有内容。我还尝试在切换之前将颜色调回4次,但问题是在更快或更慢的计算机上它会表现不同。目前,我使用Pygame.time.set_timer,但问题是如果我应用任何其他输入,如箭头键,那么它将停止闪烁,直到我停止输入。理想情况下,它会继续闪烁直到V = 0.它应该闪烁蓝色和黄色,V = 2,而V = 1会使它闪红,还有其他我尚未决定的东西。这就是我用于闪烁的

    if V == 2:
        if event.type == event_500ms:
            if Blue == 1:
                D.fill(BLUE)
                Blue = 2
            elif Blue == 2:
                D.fill(YELLOW)
                Blue = 1

这是所有代码。上面显示的代码几乎位于整个代码的底部。

import pygame, sys, random
from pygame.locals import *

pygame.init()

BLACK =          (  0,   0,   0)
ABINO =          ( 34,  45, 102)
PINDLER =        (255, 123,  90)
MEXON =          (200, 190, 220)
WHITE =          (255, 255, 255)
YELLOW =         (255, 255,   0)
RED =            (255,   0,   0)
BLUE =           (  0,   0, 255)

size = [700, 500]
D = pygame.display.set_mode(size)
L = pygame.draw.aaline
R = pygame.draw.rect
G = random.randrange(1, 10)
GM = 1
GMT = 2
CIP = 1
CO = 2
V = 0
Blue = 1
event_500ms = pygame.USEREVENT + 1
pygame.time.set_timer(event_500ms, 500)

pygame.display.set_caption("Moline")
myfont = pygame.font.SysFont("monospace", 15)
T = myfont.render
M1S = "RULES:"
M2S = "1. To start, press each arrow key in a random sequence"
M2F = " for roughly one second."
M3S = "2. To win, re-merge the four men on the crossmark."
M4S = "3. Complete before the running man completes a lap."
M5S = "4. Mouse movement is illegal and causes a severe time penalty."
L1 = T(M1S, 1, (255, 255, 0))
L2 = T(M2S, 1, (255, 255, 0))
L2C = T(M2F, 1, (255, 255, 0))
L3 = T(M3S, 1, (255, 255, 0))
L4 = T(M4S, 1, (255, 255, 0))
L5 = T(M5S, 1, (255, 255, 0))
B = D.blit
Fx = 10
Fy = 10
L6 = T("cheeeeeeeeese", 1, (255, 255, 0))

def MOLINE1(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE2(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE3(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE4(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE5(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def FINISH(D, x, y):
    R(D, BLACK, ( 4, 42, 6, 6))
    R(D, WHITE, (10, 42, 6, 6))
    R(D, BLACK, (16, 42, 6, 6))
    R(D, WHITE, (22, 42, 6, 6))
    R(D, BLACK, (28, 42, 6, 6))
    R(D, WHITE, (34, 42, 6, 6))

    R(D, WHITE, ( 4, 48, 6, 6))
    R(D, BLACK, (10, 48, 6, 6))
    R(D, WHITE, (16, 48, 6, 6))
    R(D, BLACK, (22, 48, 6, 6))
    R(D, WHITE, (28, 48, 6, 6))
    R(D, BLACK, (34, 48, 6, 6))

    R(D, BLACK, ( 4, 54, 6, 6))
    R(D, WHITE, (10, 54, 6, 6))
    R(D, BLACK, (16, 54, 6, 6))
    R(D, WHITE, (22, 54, 6, 6))
    R(D, BLACK, (28, 54, 6, 6))
    R(D, WHITE, (34, 54, 6, 6))

x_speed = 0
y_speed = 0

x2_speed = 0
y2_speed = 0

x3_speed = 0
y3_speed = 0

x4_speed = 0
y4_speed = 0

x_coord = 300
y_coord = 300

x2_coord = 300
y2_coord = 300

x3_coord = 300
y3_coord = 300

x4_coord = 300
y4_coord = 300

X5_coord = 30
Y5_coord = 10

direction = 'right'

clock = pygame.time.Clock()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                x_speed =- 3
                x2_speed = 3
                y3_speed =- 3
                y4_speed = 3
            elif event.key == pygame.K_RIGHT:
                x_speed = 3
                x2_speed =- 3
                y3_speed = 3
                y4_speed =- 3
            elif event.key == pygame.K_UP:
                y_speed =- 3
                y2_speed = 3
                x3_speed =- 3
                x4_speed = 3
            elif event.key == pygame.K_DOWN:
                y_speed = 3
                y2_speed =- 3
                x3_speed = 3
                x4_speed =- 3
            elif event.key == pygame.K_TAB:
                GMT += 1
                CIP = 2
                if GMT % 2:
                    GM = 2
                else:
                    GM = 1

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                x_speed=0
                x2_speed=0
                y3_speed=0
                y4_speed=0
            elif event.key == pygame.K_RIGHT:
                x_speed=0
                x2_speed=0
                y3_speed=0
                y4_speed=0
            elif event.key == pygame.K_UP:
                y_speed=0
                y2_speed=0
                x3_speed=0
                x4_speed=0
            elif event.key == pygame.K_DOWN:
                y_speed=0
                y2_speed=0
                x3_speed=0
                x4_speed=0

        elif event.type == MOUSEBUTTONDOWN:
            x_coord = 300
            y_coord = 300
            x2_coord = 300
            y2_coord = 300
            x3_coord = 300
            y3_coord = 300
            x4_coord = 300
            y4_coord = 300
            X5_coord = 30
            Y5_coord = 10
            direction = 'right'
            D.fill(BLACK)
            G = random.randrange(1, 10)
            CO = 2
            V = 2

        elif event.type == MOUSEBUTTONUP:
            X5_coord = 30
            Y5_coord = 10
            direction = 'right'

        if direction == 'right':
            X5_coord += 10
            if X5_coord == 670:
                direction = 'down'
        elif direction == 'down':
            Y5_coord += 10
            if Y5_coord == 460:
                direction = 'left'
        elif direction == 'left':
            X5_coord -= 10
            if X5_coord == 10:
                direction = 'up'
        elif direction == 'up':
            Y5_coord -= 10
            if Y5_coord == 10:
                direction = 'right'





    x_coord = x_coord + x_speed
    y_coord = y_coord + y_speed

    x2_coord = x2_coord + x2_speed
    y2_coord = y2_coord + y2_speed

    x3_coord = x3_coord + x3_speed
    y3_coord = y3_coord + y3_speed

    x4_coord = x4_coord + x4_speed
    y4_coord = y4_coord + y4_speed

    if GM == 2 and CIP == 2:
        D.fill(BLACK)
        CIP = 1

    if GM == 1:
        D.fill(MEXON)

    if G >= 6:
        B(L6, (80, 150))

    if G == 1 and CO == 2:
        x_coord = 366
        y_coord = 201

        x2_coord = 234
        y2_coord = 399

        x3_coord = 201
        y3_coord = 366

        x4_coord = 399
        y4_coord = 234

        CO = 1

    elif G == 2 and CO == 2:
        x_coord = 240
        y_coord = 312

        x2_coord = 360
        y2_coord = 288

        x3_coord = 312
        y3_coord = 240

        x4_coord = 288
        y4_coord = 360

        CO = 1

    elif G == 3 and CO == 2:
        x_coord = 405
        y_coord = 228

        x2_coord = 195
        y2_coord = 372

        x3_coord = 228
        y3_coord = 405

        x4_coord = 372
        y4_coord = 195

        CO = 1

    elif G == 4 and CO == 2:
        x_coord = 179
        y_coord = 309

        x2_coord = 421
        y2_coord = 291

        x3_coord = 309
        y3_coord = 179

        x4_coord = 291
        y4_coord = 421

        CO = 1

    elif G == 5 and CO == 2:
        x_coord = 315
        y_coord = 450

        x2_coord = 285
        y2_coord = 150

        x3_coord = 450
        y3_coord = 315

        x4_coord = 150
        y4_coord = 285

        CO = 1

    elif G == 6 and CO == 2:
        x_coord = 180
        y_coord = 390

        x2_coord = 420
        y2_coord = 210

        x3_coord = 390
        y3_coord = 180

        x4_coord = 210
        y4_coord = 420

        CO = 1

    elif G == 7 and CO == 2:
        x_coord = 267
        y_coord = 204

        x2_coord = 333
        y2_coord = 396

        x3_coord = 204
        y3_coord = 267

        x4_coord = 396
        y4_coord = 333

        CO = 1

    elif G == 8 and CO == 2:
        x_coord = 363
        y_coord = 390

        x2_coord = 237
        y2_coord = 210

        x3_coord = 390
        y3_coord = 363

        x4_coord = 210
        y4_coord = 237

        CO = 1

    elif G == 9 and CO == 2:
        x_coord = 234
        y_coord = 273

        x2_coord = 366
        y2_coord = 327

        x3_coord = 273
        y3_coord = 234

        x4_coord = 327
        y4_coord = 366

        CO = 1

    elif G == 10 and CO == 2:
        x_coord = 102
        y_coord = 267

        x2_coord = 498
        y2_coord = 333

        x3_coord = 267
        y3_coord = 102

        x4_coord = 333
        y4_coord = 498

        CO = 1

    if V == 2:
        if event.type == event_500ms:
            if Blue == 1:
                D.fill(BLUE)
                Blue = 2
            elif Blue == 2:
                D.fill(YELLOW)
                Blue = 1



    B(L1, (47, 45))
    B(L2, (47, 60))
    B(L2C, (65, 75))
    B(L3, (47, 90))
    B(L4, (47, 105))
    B(L5, (47, 120))

    L(D, PINDLER, (40, 5), (695, 5), 10)
    L(D, PINDLER, (3, 42), (3, 495), 10)
    L(D, PINDLER, (3, 495), (695, 495), 10)
    L(D, PINDLER, (695, 495), (695, 5), 10)

    L(D, PINDLER, (3, 41), (658, 42), 10)
    L(D, PINDLER, (40, 5), (40, 458), 10)
    L(D, PINDLER, (40, 458), (658, 458), 10)
    L(D, PINDLER, (658, 458), (658, 42), 10)

    FINISH(D, Fx, Fy)

    MOLINE1(D, x_coord, y_coord)

    MOLINE2(D, x2_coord, y2_coord)

    MOLINE3(D, x3_coord, y3_coord)

    MOLINE4(D, x4_coord, y4_coord)

    MOLINE5(D, X5_coord, Y5_coord)


    pygame.draw.line(D, PINDLER, (303, 302), (307, 306), 1)
    pygame.draw.line(D, PINDLER, (307, 302), (303, 306), 1)






    pygame.display.flip()

    clock.tick(60)

pygame.quit()

这是建议的编辑,但它不能令人遗憾地工作。它使flash永远不会发生。

        elif event.type == MOUSEBUTTONUP:
            X5_coord = 30
            Y5_coord = 10
            direction = 'right'

        if direction == 'right':
            X5_coord += 10
            if X5_coord == 670:
                direction = 'down'
        elif direction == 'down':
            Y5_coord += 10
            if Y5_coord == 460:
                direction = 'left'
        elif direction == 'left':
            X5_coord -= 10
            if X5_coord == 10:
                direction = 'up'
        elif direction == 'up':
            Y5_coord -= 10
            if Y5_coord == 10:
                direction = 'right'

        if V == 2:
            if event.type == event_500ms:
                if Blue == 1:
                    D.fill(BLUE)
                    Blue = 2
                elif Blue == 2:
                    D.fill(YELLOW)
                    Blue = 1



    x_coord = x_coord + x_speed
    y_coord = y_coord + y_speed

    x2_coord = x2_coord + x2_speed
    y2_coord = y2_coord + y2_speed

    x3_coord = x3_coord + x3_speed
    y3_coord = y3_coord + y3_speed

    x4_coord = x4_coord + x4_speed
    y4_coord = y4_coord + y4_speed

1 个答案:

答案 0 :(得分:0)

你的缩进是错误的。您显示的代码不是循环块的一部分,因此它在循环后执行:

while True:
    for event in pygame.event.get():
        # Other event handling

    # Other code

    if V == 2:
        if event.type == event_500ms:
            if Blue == 1:
                D.fill(BLUE)
                Blue = 2
            elif Blue == 2:
                D.fill(YELLOW)
                Blue = 1

这意味着event是最后处理的事件,当不是任何其他输入时,它是您的计时器。否则,它可能会有所不同。将其移动到事件循环中,并缩进它:

while True:
    for event in pygame.event.get():
        # Other event handling
        if V == 2:
            if event.type == event_500ms:
                if Blue == 1:
                    D.fill(BLUE)
                    Blue = 2
                elif Blue == 2:
                    D.fill(YELLOW)
                    Blue = 1
    # Other code

但是,这样做会导致蓝色/黄色背景被其他绘图代码透支。因此,只需将其他绘图代码包装在if V != 2块中:

import pygame, sys, random
from pygame.locals import *

pygame.init()

BLACK =          (  0,   0,   0)
ABINO =          ( 34,  45, 102)
PINDLER =        (255, 123,  90)
MEXON =          (200, 190, 220)
WHITE =          (255, 255, 255)
YELLOW =         (255, 255,   0)
RED =            (255,   0,   0)
BLUE =           (  0,   0, 255)

size = [700, 500]
D = pygame.display.set_mode(size)
L = pygame.draw.aaline
R = pygame.draw.rect
G = random.randrange(1, 10)
GM = 1
GMT = 2
CIP = 1
CO = 2
V = 0
Blue = 1
event_500ms = pygame.USEREVENT + 1
pygame.time.set_timer(event_500ms, 500)

pygame.display.set_caption("Moline")
myfont = pygame.font.SysFont("monospace", 15)
T = myfont.render
M1S = "RULES:"
M2S = "1. To start, press each arrow key in a random sequence"
M2F = " for roughly one second."
M3S = "2. To win, re-merge the four men on the crossmark."
M4S = "3. Complete before the running man completes a lap."
M5S = "4. Mouse movement is illegal and causes a severe time penalty."
L1 = T(M1S, 1, (255, 255, 0))
L2 = T(M2S, 1, (255, 255, 0))
L2C = T(M2F, 1, (255, 255, 0))
L3 = T(M3S, 1, (255, 255, 0))
L4 = T(M4S, 1, (255, 255, 0))
L5 = T(M5S, 1, (255, 255, 0))
B = D.blit
Fx = 10
Fy = 10
L6 = T("cheeeeeeeeese", 1, (255, 255, 0))

def MOLINE1(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE2(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE3(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE4(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def MOLINE5(D, x, y):
    pygame.draw.ellipse(D, BLACK, [1 + x, y, 10, 10], 0)

    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [10 + x, 27 + y], 2)
    pygame.draw.line(D, BLACK, [5 + x, 17 + y], [x, 27 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 17 + y], [5 + x, 7 + y], 2)

    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [9 + x, 17 + y], 2)
    pygame.draw.line(D, PINDLER, [5 + x, 7 + y], [1 + x, 17 + y], 2)

def FINISH(D, x, y):
    R(D, BLACK, ( 4, 42, 6, 6))
    R(D, WHITE, (10, 42, 6, 6))
    R(D, BLACK, (16, 42, 6, 6))
    R(D, WHITE, (22, 42, 6, 6))
    R(D, BLACK, (28, 42, 6, 6))
    R(D, WHITE, (34, 42, 6, 6))

    R(D, WHITE, ( 4, 48, 6, 6))
    R(D, BLACK, (10, 48, 6, 6))
    R(D, WHITE, (16, 48, 6, 6))
    R(D, BLACK, (22, 48, 6, 6))
    R(D, WHITE, (28, 48, 6, 6))
    R(D, BLACK, (34, 48, 6, 6))

    R(D, BLACK, ( 4, 54, 6, 6))
    R(D, WHITE, (10, 54, 6, 6))
    R(D, BLACK, (16, 54, 6, 6))
    R(D, WHITE, (22, 54, 6, 6))
    R(D, BLACK, (28, 54, 6, 6))
    R(D, WHITE, (34, 54, 6, 6))

x_speed = 0
y_speed = 0

x2_speed = 0
y2_speed = 0

x3_speed = 0
y3_speed = 0

x4_speed = 0
y4_speed = 0

x_coord = 300
y_coord = 300

x2_coord = 300
y2_coord = 300

x3_coord = 300
y3_coord = 300

x4_coord = 300
y4_coord = 300

X5_coord = 30
Y5_coord = 10

direction = 'right'

clock = pygame.time.Clock()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                x_speed =- 3
                x2_speed = 3
                y3_speed =- 3
                y4_speed = 3
            elif event.key == pygame.K_RIGHT:
                x_speed = 3
                x2_speed =- 3
                y3_speed = 3
                y4_speed =- 3
            elif event.key == pygame.K_UP:
                y_speed =- 3
                y2_speed = 3
                x3_speed =- 3
                x4_speed = 3
            elif event.key == pygame.K_DOWN:
                y_speed = 3
                y2_speed =- 3
                x3_speed = 3
                x4_speed =- 3
            elif event.key == pygame.K_TAB:
                GMT += 1
                CIP = 2
                if GMT % 2:
                    GM = 2
                else:
                    GM = 1

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                x_speed=0
                x2_speed=0
                y3_speed=0
                y4_speed=0
            elif event.key == pygame.K_RIGHT:
                x_speed=0
                x2_speed=0
                y3_speed=0
                y4_speed=0
            elif event.key == pygame.K_UP:
                y_speed=0
                y2_speed=0
                x3_speed=0
                x4_speed=0
            elif event.key == pygame.K_DOWN:
                y_speed=0
                y2_speed=0
                x3_speed=0
                x4_speed=0

        elif event.type == MOUSEBUTTONDOWN:
            x_coord = 300
            y_coord = 300
            x2_coord = 300
            y2_coord = 300
            x3_coord = 300
            y3_coord = 300
            x4_coord = 300
            y4_coord = 300
            X5_coord = 30
            Y5_coord = 10
            direction = 'right'
            D.fill(BLACK)
            G = random.randrange(1, 10)
            CO = 2
            V = 2

        elif event.type == MOUSEBUTTONUP:
            X5_coord = 30
            Y5_coord = 10
            direction = 'right'

        if direction == 'right':
            X5_coord += 10
            if X5_coord == 670:
                direction = 'down'
        elif direction == 'down':
            Y5_coord += 10
            if Y5_coord == 460:
                direction = 'left'
        elif direction == 'left':
            X5_coord -= 10
            if X5_coord == 10:
                direction = 'up'
        elif direction == 'up':
            Y5_coord -= 10
            if Y5_coord == 10:
                direction = 'right'
        print(V, event, event.type, event_500ms, V == 2, event.type == event_500ms, Blue)
        if V == 2:
            if event.type == event_500ms:
                if Blue == 1:
                    D.fill(BLUE)
                    Blue = 2
                elif Blue == 2:
                    D.fill(YELLOW)
                    Blue = 1

    if V != 2:
        x_coord = x_coord + x_speed
        y_coord = y_coord + y_speed

        x2_coord = x2_coord + x2_speed
        y2_coord = y2_coord + y2_speed

        x3_coord = x3_coord + x3_speed
        y3_coord = y3_coord + y3_speed

        x4_coord = x4_coord + x4_speed
        y4_coord = y4_coord + y4_speed

        if GM == 2 and CIP == 2:
            D.fill(BLACK)
            CIP = 1

        if GM == 1:
            D.fill(MEXON)

        if G >= 6:
            B(L6, (80, 150))

        if G == 1 and CO == 2:
            x_coord = 366
            y_coord = 201

            x2_coord = 234
            y2_coord = 399

            x3_coord = 201
            y3_coord = 366

            x4_coord = 399
            y4_coord = 234

            CO = 1

        elif G == 2 and CO == 2:
            x_coord = 240
            y_coord = 312

            x2_coord = 360
            y2_coord = 288

            x3_coord = 312
            y3_coord = 240

            x4_coord = 288
            y4_coord = 360

            CO = 1

        elif G == 3 and CO == 2:
            x_coord = 405
            y_coord = 228

            x2_coord = 195
            y2_coord = 372

            x3_coord = 228
            y3_coord = 405

            x4_coord = 372
            y4_coord = 195

            CO = 1

        elif G == 4 and CO == 2:
            x_coord = 179
            y_coord = 309

            x2_coord = 421
            y2_coord = 291

            x3_coord = 309
            y3_coord = 179

            x4_coord = 291
            y4_coord = 421

            CO = 1

        elif G == 5 and CO == 2:
            x_coord = 315
            y_coord = 450

            x2_coord = 285
            y2_coord = 150

            x3_coord = 450
            y3_coord = 315

            x4_coord = 150
            y4_coord = 285

            CO = 1

        elif G == 6 and CO == 2:
            x_coord = 180
            y_coord = 390

            x2_coord = 420
            y2_coord = 210

            x3_coord = 390
            y3_coord = 180

            x4_coord = 210
            y4_coord = 420

            CO = 1

        elif G == 7 and CO == 2:
            x_coord = 267
            y_coord = 204

            x2_coord = 333
            y2_coord = 396

            x3_coord = 204
            y3_coord = 267

            x4_coord = 396
            y4_coord = 333

            CO = 1

        elif G == 8 and CO == 2:
            x_coord = 363
            y_coord = 390

            x2_coord = 237
            y2_coord = 210

            x3_coord = 390
            y3_coord = 363

            x4_coord = 210
            y4_coord = 237

            CO = 1

        elif G == 9 and CO == 2:
            x_coord = 234
            y_coord = 273

            x2_coord = 366
            y2_coord = 327

            x3_coord = 273
            y3_coord = 234

            x4_coord = 327
            y4_coord = 366

            CO = 1

        elif G == 10 and CO == 2:
            x_coord = 102
            y_coord = 267

            x2_coord = 498
            y2_coord = 333

            x3_coord = 267
            y3_coord = 102

            x4_coord = 333
            y4_coord = 498

            CO = 1




        B(L1, (47, 45))
        B(L2, (47, 60))
        B(L2C, (65, 75))
        B(L3, (47, 90))
        B(L4, (47, 105))
        B(L5, (47, 120))

        L(D, PINDLER, (40, 5), (695, 5), 10)
        L(D, PINDLER, (3, 42), (3, 495), 10)
        L(D, PINDLER, (3, 495), (695, 495), 10)
        L(D, PINDLER, (695, 495), (695, 5), 10)

        L(D, PINDLER, (3, 41), (658, 42), 10)
        L(D, PINDLER, (40, 5), (40, 458), 10)
        L(D, PINDLER, (40, 458), (658, 458), 10)
        L(D, PINDLER, (658, 458), (658, 42), 10)

        FINISH(D, Fx, Fy)

        MOLINE1(D, x_coord, y_coord)

        MOLINE2(D, x2_coord, y2_coord)

        MOLINE3(D, x3_coord, y3_coord)

        MOLINE4(D, x4_coord, y4_coord)

        MOLINE5(D, X5_coord, Y5_coord)


        pygame.draw.line(D, PINDLER, (303, 302), (307, 306), 1)
        pygame.draw.line(D, PINDLER, (307, 302), (303, 306), 1)

    pygame.display.flip()

    clock.tick(60)

pygame.quit()

结果:

enter image description here