我正在为python类的最终项目工作。我正在使用pygame库制作游戏。我想创建一个启动屏幕,用户可以单击开始或进入“商店”以进行游戏内购买。但是,我不知道该如何构造。我已经创建了商店,但我不知道将其放置在何处。我是否将其放入while循环中?到目前为止,这是我所做的...
我应该单击鼠标按钮进行初始化吗?如果color == red,我应该将代码放在哪里? (这是“商店”按钮的颜色)...现在,当我运行该程序时,由于没有单击任何地方,它会立即跳入游戏。
while playing:
num_spikes = []
num_walls = []
keys = pygame.key.get_pressed()
store = Button(600, 500, display)
store.paint_button()
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
carryOn = False
if event.type == pygame.MOUSEBUTTONDOWN:
xpos, ypos = event.pos
color = display.get_at((xpos, ypos))[:3]
if color == red:
display.fill((0,0,0))
pygame.draw.rect(display, blue, [100, 100, 800, 500], 0)
pygame.draw.rect(display, white, [150, 150, 350, 350], 0)
pygame.draw.rect(display, white, [375, 150, 575, 350], 0)
display.blit(pygame.image.load("spike.png"), (160, 160))
display.blit(pygame.image.load("brick.png"), (385, 160))
text_input_spikes = pygame_textinput.TextInput()
text_input_spikes.update(pygame.event.get())
display.blit(text_input_spikes.get_surface(), (120,160))
pygame.display.update()
display.fill(white)
if keys[pygame.K_LEFT]:
s1.moveLeft(15)
if keys[pygame.K_RIGHT]:
s1.moveRight(15)
if keys[pygame.K_UP]:
s1.moveUp(15)
if keys[pygame.K_DOWN]:
s1.moveDown(15)
if keys[pygame.K_ESCAPE]:
exit()
if m1.rect.y > 600:
m1.changeSpeed(random.randint(50,100))
m1.repaint(random.choice(colorList))
m1.rect.y = -200
crashes = pygame.sprite.spritecollide(s1, monsters, False)
for crash in crashes:
carryOn=False
exit()
m1.draw(display)
s1.draw(display)
m1.update(s1)
s1.update()
pygame.display.update()
pygame.display.flip()
pygame.quit()