кнопка, которую я сделал, пропускает поверхность в Pygame - PullRequest
0 голосов
/ 05 июня 2018

Я изучаю функциональность кнопки в Pygame, и я связал кнопку «Play» в главном меню со второй последовательностью (игровой цикл), но вместо перехода ко второй последовательности, она переходит прямо к третьей (вы выигрываете / проигрываете)или меню паузы), пропуская кнопку на второй последовательности, которая приводит к меню «Вы выиграли / проиграли».пожалуйста помогите !!

import pygame as pg
import time

pg.init()

display_height = 900
display_width = 600

black = (0,0,0)
white = (255,255,255)
green = (0, 255, 12)
red = (255,0,0)
blue = (0,97,255)

gd = pg.display.set_mode((display_height,display_width))
pg.display.set_caption('For-Get-Ful')
clock = pg.time.Clock()
gd.fill(white)
pg.display.flip()

def text_objects(text, font, color):
    textSurface = font.render(text, True, color)
    return textSurface, textSurface.get_rect()

def intro_button(msg,x,y,w,h,ic,ac,action=None):
    mouse1 = pg.mouse.get_pos()
    click = pg.mouse.get_pressed()
    if x+w > mouse1[0] > x and y+h > mouse1[1] > y:
        pg.draw.rect(gd,ac,(x,y,w,h))
        smalltext = pg.font.Font("freesansbold.ttf",20)
        textsurf, textrect = text_objects (msg,smalltext,black)
        textrect.center = ( (x+(w/2)), (y+(h/2)) )
        gd.blit(textsurf,textrect)
        if click[0] == 1 and action != None:
            if action == "play":
                second_seq()
            elif action == "quit":
                third_seq()

    else:
        pg.draw.rect(gd,ic,(x,y,w,h))
        smalltext = pg.font.Font("freesansbold.ttf",20)
        textsurf, textrect = text_objects (msg,smalltext,black)
        textrect.center = ( (x+(w/2)), (y+(h/2)) )
        gd.blit(textsurf,textrect)
        gd.blit(textsurf,textrect)

def first_seq():
    fs = True

    # To keep the game running longer than 1 frame
    while fs:
      for event in pg.event.get():
          if event.type == pg.QUIT:
              pg.quit()
              quit()

      gd.fill(black)
      pg.draw.rect(gd,blue,(400,400,400,400))
      intro_button("Play",100,100,100,100,green,green,"play")
      pg.display.update()
      clock.tick(15)

def second_seq():
    ss = True

    # To keep the game running longer than 1 frame
    while ss:
      for event in pg.event.get():
          if event.type == pg.QUIT:
              pg.quit()
              quit()

      gd.fill(black)
      pg.draw.rect(gd,blue,(190,130,530,130))
      intro_button("quit",100,100,100,100,red,red,"quit")
      pg.display.update()
      clock.tick(15)

def third_seq():
    ts = True

    # To keep the game running longer than 1 frame
    while ts:
      for event in pg.event.get():
          if event.type == pg.QUIT:
              pg.quit()
              quit()

      gd.fill(black)
      intro_button("sweet",100,100,100,100,red,red,"sweet")
      pg.display.update()
      clock.tick(15)

first_seq()
second_seq()
third_seq()
pg.quit()
quit()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...