Advertisement
bitwise_gamgee

Untitled

Jun 8th, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.73 KB | None | 0 0
  1.     def main_screen():
  2.         # creating input rectangle
  3.         active_text_rect_1 = False
  4.         active_text_rect_2 = False
  5.         range_max_input_rect = pygame.Rect(280, 375, 50, 30)
  6.         answer_input_rect = pygame.Rect(280, 575, 50, 30)
  7.         input_font = pygame.font.Font('PKMN RBYGSC.ttf', 20)
  8.         user_text_input_range_max = ""
  9.         user_text_input_guess = ""
  10.  
  11.         # necessary text
  12.         title_text = main_font.render('Wheel Of Monotony', True, pygame.Color('black'))
  13.         max_range_input_request_text_1 = description_font.render("In the box below, please enter what you would like",
  14.                                                                   True, pygame.Color('black'))
  15.         max_range_input_request_text_2 = description_font.render("the max. of the range you have to guess to be:", True,
  16.                                                                   pygame.Color('black'))
  17.         guess_input_request_text_1 = description_font.render("In the box below, please enter what you would think",
  18.                                                              True, pygame.Color('black'))
  19.         guess_input_request_text_2 = description_font.render("the number I'm thinking of is: ", True, pygame.Color('black'))
  20.         color_active_rect_1 = pygame.Color('black')
  21.         color_active_rect_2 = pygame.Color('black')
  22.         color_passive_rect_1 = pygame.Color('white')
  23.         color_passive_rect_2 = pygame.Color('white')
  24.         color_for_rect_1 = color_passive_rect_1
  25.         color_for_rect_2 = color_passive_rect_2
  26.  
  27.         while True:
  28.             # puts the background variable into the BG of the screen
  29.             screen.blit(background_image, [0, 0])
  30.  
  31.             # text showing
  32.             screen.blit(title_text, (75, 200))
  33.             screen.blit(max_range_input_request_text_1, (75, 275))
  34.             screen.blit(max_range_input_request_text_2, (75, 290))
  35.             screen.blit(guess_input_request_text_1, (75, 500))
  36.             screen.blit(guess_input_request_text_2, (75, 525))
  37.  
  38.             # handling events
  39.             for event in pygame.event.get():
  40.                 if event.type == pygame.QUIT:
  41.                     pygame.quit()
  42.                     sys.exit()
  43.  
  44.                 # if selected/hovering over the box, it changes color
  45.                 if event.type == pygame.MOUSEBUTTONDOWN:
  46.                     if range_max_input_rect.collidepoint(event.pos):
  47.                         active_text_rect_1 = True
  48.                     if answer_input_rect.collidepoint(event.pos):
  49.                         active_text_rect_2 = True
  50.                     else:
  51.                         active_text_rect_1 = False
  52.                         active_text_rect_2 = False
  53.  
  54.                 if event.type == pygame.KEYDOWN:
  55.                     # Check for backspace
  56.                     if event.key == pygame.K_BACKSPACE:
  57.                         # get text input from 0 to -1 i.e. end.
  58.                         user_text_input_range_max = user_text_input_range_max[:-1]
  59.                         user_text_input_guess = user_text_input_guess[:-1]
  60.  
  61.                     # Unicode standard is used for string formation
  62.                     else:
  63.                         user_text_input_range_max += event.unicode
  64.                         user_text_input_guess += event.unicode
  65.  
  66.             # draw rectangle and argument passed which should be on screen
  67.             if active_text_rect_1:
  68.                 color_for_rect_1 = color_active_rect_1
  69.             else:
  70.                 color_for_rect_1 = color_passive_rect_1
  71.  
  72.             if active_text_rect_2:
  73.                 color_for_rect_2 = color_active_rect_2
  74.             else:
  75.                 color_for_rect_2 = color_passive_rect_2
  76.  
  77.             # drawing rect 1
  78.             pygame.draw.rect(screen, color_for_rect_1, range_max_input_rect)
  79.             text_surface_range_max = input_font.render(user_text_input_range_max, True, pygame.Color('white'))
  80.  
  81.             # drawing rect 2
  82.             pygame.draw.rect(screen, color_for_rect_2, answer_input_rect)
  83.             text_surface_guess_input = input_font.render(user_text_input_guess, True, pygame.Color('white'))
  84.  
  85.             # render at position stated in arguments
  86.             screen.blit(text_surface_range_max, (range_max_input_rect.x + 18, range_max_input_rect.y + 5))
  87.             screen.blit(text_surface_guess_input, (answer_input_rect.x + 18, answer_input_rect.y + 5))
  88.  
  89.             # set width of textfield so that text cannot get outside of user's text input
  90.             range_max_input_rect.w = max(75, 10)
  91.             answer_input_rect.w = max(75, 10)
  92.  
  93.             # updates screen
  94.             pygame.display.flip()
  95.             clock.tick(60)
  96.  
  97.         return user_text_input_range_max, user_text_input_guess
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement