我试图让闪烁的文字告诉玩家左键单击以开始游戏,但问题是每当我移动鼠标时,文本完全消失,然后当我停止移动它时恢复闪烁。为什么这样,我该如何解决?提前谢谢。
elif V == 3:
D.fill(MEXON)
x_coord = 0
y_coord = 0
#B(LMOL, (37, 10))
B(L1, (37, 30))
B(L2, (37, 70))
B(L2C, (55, 90))
B(L3, (37, 120))
B(L3C, (37, 140))
B(L3F, (37, 160))
B(L4, (37, 190))
B(L4C, (37, 210))
B(L5, (37, 240))
B(L5C, (37, 260))
B(L6, (37, 290))
B(L6C, (37, 310))
B(L6F, (37, 330))
B(L7, (37, 360))
B(L7C, (37, 380))
B(L7F, (37, 400))
if event.type == event_250ms:
if STHB == 1:
B(SFGL, (60, 434))
STHB = 2
elif STHB == 2:
STHB = 1
这是使用规则和闪烁开始文本处理开始屏幕的代码部分。下一个代码是整个程序,需要它。你可以在第600行左右找到大约3/4的上述片段。再次感谢。
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
SH = 0
AAC = 2
CHBP = 0
STHB = 1
CC = 0
CM = 1
PL = pygame.draw.line
PE = pygame.draw.ellipse
GMFT = 0
HTT = 0
CO = 2
V = 3
PFO = 0
CL = 0
Blue = 1
Red = 1
LEVEL = 1
event_250ms = pygame.USEREVENT + 1
pygame.time.set_timer(event_250ms, 250)
pygame.display.set_caption("Moline")
myfont1 = pygame.font.SysFont("monospace", 40)
myfont2 = pygame.font.SysFont("monospace", 60)
myfont3 = pygame.font.SysFont("monospace", 20)
T1 = myfont1.render
T2 = myfont2.render
T3 = myfont3.render
MOL = "MOLINE"
M1S = "DIRECTIONS:"
M2S = "1. Use the arrow keys to control the four characters"
M2F = " off of the track to move them."
M3S = "2. To win a level, line up the four characters on"
M3F = " the crossmark before the runner on the track"
M3C = " reaches the finish line."
M4S = "3. If the runner reaches the finish line, then"
M4F = " you lose."
M5S = "4. When you lose you go back to level one. There"
M5F = " are eight levels."
M6S = "5. Key input makes the runner move slightly"
M6F = " faster, but he will move without input."
M6C = " Additionally, mouse movement makes him even faster."
M7S = "6. It should be noted that whenever you click to"
M7F = " start, the game will immediately begin so have"
M7C = " your arrow keys ready to go."
ISC = "Left-Click to Start Game"
LEST = "Level: "
LU1 = "1"
LU2 = "2"
LU3 = "3"
LU4 = "4"
LU5 = "5"
LU6 = "6"
LU7 = "7"
LU8 = "8"
VTC2 = "Left-Click To Begin Next Level"
VTC3 = "Left-Click To Start Over"
VTC1 = "Left-Click to Start Over"
VT3 = "YOU WIN!!!"
VT2 = "LEVEL COMPLETE"
VT1 = "GAME OVER"
LMOL = T2(MOL, 1, (255, 255, 0))
L1 = T3(M1S, 1, (255, 255, 0))
L2 = T3(M2S, 1, (255, 255, 0))
L2C = T3(M2F, 1, (255, 255, 0))
L3 = T3(M3S, 1, (255, 255, 0))
L3C = T3(M3F, 1, (255, 255, 0))
L3F = T3(M3C, 1, (255, 255, 0))
L4 = T3(M4S, 1, (255, 255, 0))
L4C = T3(M4F, 1, (255, 255, 0))
L5 = T3(M5S, 1, (255, 255, 0))
L5C = T3 (M5F, 1, (255, 255, 0))
L6 = T3(M6S, 1, (255, 255, 0))
L6C = T3(M6F, 1, (255, 255, 0))
L6F = T3(M6C, 1, (255, 255, 0))
L7 = T3(M7S, 1, (255, 255, 0))
L7C = T3(M7F, 1, (255, 255, 0))
L7F = T3(M7C, 1, (255, 255, 0))
SFGL = T1(ISC, 1, (255, 255, 0))
LES = T3(LEST, 1, (255, 255, 0))
LAS1 = T3(LU1, 1, (255, 255, 0))
LAS2 = T3(LU2, 1, (255, 255, 0))
LAS3 = T3(LU3, 1, (255, 255, 0))
LAS4 = T3(LU4, 1, (255, 255, 0))
LAS5 = T3(LU5, 1, (255, 255, 0))
LAS6 = T3(LU6, 1, (255, 255, 0))
LAS7 = T3(LU7, 1, (255, 255, 0))
LAS8 = T3(LU8, 1, (255, 255, 0))
V3CB = T3(VTC3, 1, (255, 255, 0))
V3CY = T3(VTC3, 1, ( 0, 0, 255))
V2CB = T3(VTC2, 1, (255, 255, 0))
V2CY = T3(VTC2, 1, ( 0, 0, 255))
V1CB = T3(VTC1, 1, ( 0, 0, 0))
V1CR = T3(VTC1, 1, (255, 0, 0))
V3B = T2(VT3, 1, (255, 255, 0))
V3Y = T2(VT3, 1, ( 0, 0, 0))
V2B = T2(VT2, 1, (255, 255, 0))
V2Y = T2(VT2, 1, ( 0, 0, 255))
V1R = T2(VT1, 1, ( 0, 0, 0))
V1B = T2(VT1, 1, (255, 0, 0))
B = D.blit
Fx = 10
Fy = 10
def MOLINE1(D, x, y):
PE(D, BLACK, (1 + x, y, 10, 10), 0)
PL(D, BLACK, (5 + x, 17 + y), (10 + x, 27 + y), 2)
PL(D, BLACK, (5 + x, 17 + y), (x, 27 + y), 2)
PL(D, PINDLER, (5 + x, 17 + y), (5 + x, 7 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (9 + x, 17 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (1 + x, 17 + y), 2)
def MOLINE2(D, x, y):
PE(D, BLACK, (1 + x, y, 10, 10), 0)
PL(D, BLACK, (5 + x, 17 + y), (10 + x, 27 + y), 2)
PL(D, BLACK, (5 + x, 17 + y), (x, 27 + y), 2)
PL(D, PINDLER, (5 + x, 17 + y), (5 + x, 7 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (9 + x, 17 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (1 + x, 17 + y), 2)
def MOLINE3(D, x, y):
PE(D, BLACK, (1 + x, y, 10, 10), 0)
PL(D, BLACK, (5 + x, 17 + y), (10 + x, 27 + y), 2)
PL(D, BLACK, (5 + x, 17 + y), (x, 27 + y), 2)
PL(D, PINDLER, (5 + x, 17 + y), (5 + x, 7 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), [9 + x, 17 + y], 2)
PL(D, PINDLER, (5 + x, 7 + y), (1 + x, 17 + y), 2)
def MOLINE4(D, x, y):
PE(D, BLACK, (1 + x, y, 10, 10), 0)
PL(D, BLACK, (5 + x, 17 + y), (10 + x, 27 + y), 2)
PL(D, BLACK, (5 + x, 17 + y), (x, 27 + y), 2)
PL(D, PINDLER, (5 + x, 17 + y), (5 + x, 7 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (9 + x, 17 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (1 + x, 17 + y), 2)
def MOLINE5(D, x, y):
PE(D, BLACK, (1 + x, y, 10, 10), 0)
PL(D, BLACK, (5 + x, 17 + y), (10 + x, 27 + y), 2)
PL(D, BLACK, (5 + x, 17 + y), (x, 27 + y), 2)
PL(D, PINDLER, (5 + x, 17 + y), (5 + x, 7 + y), 2)
PL(D, PINDLER, (5 + x, 7 + y), (9 + x, 17 + y), 2)
PL(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 = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
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
LEVEL = 8
if GMT % 2:
GM = 2
CL = 1
else:
GM = 1
CL = 0
HTT = 1
if HTT == 1 and GMFT == 1:
V = 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 and LEVEL == 1:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 30
Y5_coord = 10
direction = 'right'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 1:
X5_coord = 30
Y5_coord = 10
direction = 'right'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 2:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 330
Y5_coord = 10
direction = 'right'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 2:
X5_coord = 330
Y5_coord = 10
direction = 'right'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 3:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 670
Y5_coord = 10
direction = 'down'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 3:
X5_coord = 670
Y5_coord = 10
direction = 'down'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 4:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 670
Y5_coord = 220
direction = 'down'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 4:
X5_coord = 670
Y5_coord = 220
direction = 'down'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 5:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 670
Y5_coord = 460
direction = 'left'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 5:
X5_coord = 670
Y5_coord = 460
direction = 'left'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 6:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 330
Y5_coord = 460
direction = 'left'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 6:
X5_coord = 330
Y5_coord = 460
direction = 'left'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 7:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 10
Y5_coord = 460
direction = 'up'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 7:
X5_coord = 10
Y5_coord = 460
direction = 'up'
elif event.type == MOUSEBUTTONDOWN and LEVEL == 8:
x_coord = 0
y_coord = 0
x2_coord = 0
y2_coord = 0
x3_coord = 0
y3_coord = 0
x4_coord = 0
y4_coord = 0
X5_coord = 10
Y5_coord = 250
direction = 'up'
D.fill(BLACK)
G = random.randrange(1, 10)
CO = 2
V = 0
PFO = 0
GMFT = 0
HTT = 0
elif event.type == MOUSEBUTTONUP and LEVEL == 8:
X5_coord = 10
Y5_coord = 250
direction = 'up'
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 Y5_coord == 20 and X5_coord == 10:
GMFT = 1
if Y5_coord == 20 and X5_coord == 10 and CL == 0 and V != 3:
V = 1
Y5_coord = 0
X5_coord = 0
PFO = 1
if x_coord == 300 and y_coord == 300 and PFO == 0 and CL == 0:
V = 2
CC = 1
Y5_coord = 0
X5_coord = 0
x_speed = 0
y_speed = 0
x_coord = 0
y_coord = 0
direction = 'left'
if V == 2:
if V == 2 and LEVEL == 1 and CC == 1:
LEVEL = 2
CC = 0
if V == 2 and LEVEL == 2 and CC == 1:
LEVEL = 3
CC = 0
if V == 2 and LEVEL == 3 and CC == 1:
LEVEL = 4
CC = 0
if V == 2 and LEVEL == 4 and CC == 1:
LEVEL = 5
CC = 0
if V == 2 and LEVEL == 5 and CC == 1:
LEVEL = 6
CC = 0
if V == 2 and LEVEL == 6 and CC == 1:
LEVEL = 7
CC = 0
if V == 2 and LEVEL == 7 and CC == 1:
LEVEL = 8
CC = 0
if V == 2 and LEVEL == 8 and CC == 1:
LEVEL = 9
CC = 0
if event.type == event_250ms:
if Blue == 1:
D.fill(BLUE)
Blue = 2
if LEVEL != 9:
B(V2B, (100, 175))
B(V2CB, (170, 260))
elif LEVEL == 9:
B(V3B, (180, 175))
B(V3CB, (205, 280))
elif Blue == 2:
D.fill(YELLOW)
Blue = 1
if LEVEL != 9:
B(V2Y, (100, 175))
B(V2CY, (170, 260))
elif LEVEL == 9:
B(V3Y, (180, 175))
B(V3CY, (205, 280))
elif V == 1:
if event.type == event_250ms:
if Red == 1:
D.fill(RED)
Red = 2
B(V1R, (190, 175))
B(V1CB, (210, 260))
elif Red == 2:
D.fill(BLACK)
Red = 1
B(V1B, (190, 175))
B(V1CR, (210, 260))
elif V == 3:
D.fill(MEXON)
x_coord = 0
y_coord = 0
#B(LMOL, (37, 10))
B(L1, (37, 30))
B(L2, (37, 70))
B(L2C, (55, 90))
B(L3, (37, 120))
B(L3C, (37, 140))
B(L3F, (37, 160))
B(L4, (37, 190))
B(L4C, (37, 210))
B(L5, (37, 240))
B(L5C, (37, 260))
B(L6, (37, 290))
B(L6C, (37, 310))
B(L6F, (37, 330))
B(L7, (37, 360))
B(L7C, (37, 380))
B(L7F, (37, 400))
if event.type == event_250ms:
if STHB == 1:
B(SFGL, (60, 434))
STHB = 2
elif STHB == 2:
STHB = 1
if V != 2 and V != 1 and V != 3:
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 == 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 = 180
y_coord = 309
x2_coord = 420
y2_coord = 291
x3_coord = 309
y3_coord = 180
x4_coord = 291
y4_coord = 420
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(LES, (299, 60))
if V != 2 and V != 1 and LEVEL == 1:
B(LAS1, (372, 60))
elif V != 2 and V != 1 and LEVEL == 2:
B(LAS2, (372, 60))
elif V != 2 and V != 1 and LEVEL == 3:
B(LAS3, (372, 60))
elif V != 2 and V != 1 and LEVEL == 4:
B(LAS4, (372, 60))
elif V != 2 and V != 1 and LEVEL == 5:
B(LAS5, (372, 60))
elif V != 2 and V != 1 and LEVEL == 6:
B(LAS6, (372, 60))
elif V != 2 and V != 1 and LEVEL == 7:
B(LAS7, (372, 60))
elif V != 2 and V != 1 and LEVEL == 8:
B(LAS8, (372, 60))
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)
PL(D, PINDLER, (303, 302), (307, 306), 1)
PL(D, PINDLER, (307, 302), (303, 306), 1)
pygame.display.flip()
clock.tick(60)
pygame.quit()