Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main_screen():
- # creating input rectangle
- active_text_rect_1 = False
- active_text_rect_2 = False
- range_max_input_rect = pygame.Rect(280, 375, 50, 30)
- answer_input_rect = pygame.Rect(280, 575, 50, 30)
- input_font = pygame.font.Font('PKMN RBYGSC.ttf', 20)
- user_text_input_range_max = ""
- user_text_input_guess = ""
- # necessary text
- title_text = main_font.render('Wheel Of Monotony', True, pygame.Color('black'))
- max_range_input_request_text_1 = description_font.render("In the box below, please enter what you would like",
- True, pygame.Color('black'))
- max_range_input_request_text_2 = description_font.render("the max. of the range you have to guess to be:", True,
- pygame.Color('black'))
- guess_input_request_text_1 = description_font.render("In the box below, please enter what you would think",
- True, pygame.Color('black'))
- guess_input_request_text_2 = description_font.render("the number I'm thinking of is: ", True, pygame.Color('black'))
- color_active_rect_1 = pygame.Color('black')
- color_active_rect_2 = pygame.Color('black')
- color_passive_rect_1 = pygame.Color('white')
- color_passive_rect_2 = pygame.Color('white')
- color_for_rect_1 = color_passive_rect_1
- color_for_rect_2 = color_passive_rect_2
- while True:
- # puts the background variable into the BG of the screen
- screen.blit(background_image, [0, 0])
- # text showing
- screen.blit(title_text, (75, 200))
- screen.blit(max_range_input_request_text_1, (75, 275))
- screen.blit(max_range_input_request_text_2, (75, 290))
- screen.blit(guess_input_request_text_1, (75, 500))
- screen.blit(guess_input_request_text_2, (75, 525))
- # handling events
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- # if selected/hovering over the box, it changes color
- if event.type == pygame.MOUSEBUTTONDOWN:
- if range_max_input_rect.collidepoint(event.pos):
- active_text_rect_1 = True
- if answer_input_rect.collidepoint(event.pos):
- active_text_rect_2 = True
- else:
- active_text_rect_1 = False
- active_text_rect_2 = False
- if event.type == pygame.KEYDOWN:
- # Check for backspace
- if event.key == pygame.K_BACKSPACE:
- # get text input from 0 to -1 i.e. end.
- user_text_input_range_max = user_text_input_range_max[:-1]
- user_text_input_guess = user_text_input_guess[:-1]
- # Unicode standard is used for string formation
- else:
- user_text_input_range_max += event.unicode
- user_text_input_guess += event.unicode
- # draw rectangle and argument passed which should be on screen
- if active_text_rect_1:
- color_for_rect_1 = color_active_rect_1
- else:
- color_for_rect_1 = color_passive_rect_1
- if active_text_rect_2:
- color_for_rect_2 = color_active_rect_2
- else:
- color_for_rect_2 = color_passive_rect_2
- # drawing rect 1
- pygame.draw.rect(screen, color_for_rect_1, range_max_input_rect)
- text_surface_range_max = input_font.render(user_text_input_range_max, True, pygame.Color('white'))
- # drawing rect 2
- pygame.draw.rect(screen, color_for_rect_2, answer_input_rect)
- text_surface_guess_input = input_font.render(user_text_input_guess, True, pygame.Color('white'))
- # render at position stated in arguments
- screen.blit(text_surface_range_max, (range_max_input_rect.x + 18, range_max_input_rect.y + 5))
- screen.blit(text_surface_guess_input, (answer_input_rect.x + 18, answer_input_rect.y + 5))
- # set width of textfield so that text cannot get outside of user's text input
- range_max_input_rect.w = max(75, 10)
- answer_input_rect.w = max(75, 10)
- # updates screen
- pygame.display.flip()
- clock.tick(60)
- return user_text_input_range_max, user_text_input_guess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement