I've been working on a simple main menu in Python 3.1 and PyGame 2.7. When the mouse cursor is within a certain area, text on the screen should become white in color. I'm using functions to blit the screen. The first function blits the main menu normally, and the other two functions blit the menu with some text highlighted. Here are the functions:
def draw_main_menu(): #draw main menu normally
screen.fill(BLACK) #clears screen
#set up text
new_text = menu_font.render('NEW GAME', 1, (100, 100, 100))
load_text = menu_font.render('LOAD GAME', 1, (100, 100, 100))
options_text = menu_font.render('OPTIONS', 1, (100, 100, 100))
quit_text = menu_font.render('QUIT', 1, (100, 100, 100))
#blit text
screen.blit(new_text, (340, 425))
screen.blit(load_text, (335, 455))
screen.blit(options_text, (350, 485))
screen.blit(quit_text, (373, 515))
def draw_main_menu_ng(): #draw main menu with new game text in white
screen.fill(BLACK)
new_text = menu_font.render('NEW GAME', 1, (255, 255, 255))
load_text = menu_font.render('LOAD GAME', 1, (100, 100, 100))
options_text = menu_font.render('OPTIONS', 1, (100, 100, 100))
quit_text = menu_font.render('QUIT', 1, (100, 100, 100))
screen.blit(new_text, (340, 425))
screen.blit(load_text, (335, 455))
screen.blit(options_text, (350, 485))
screen.blit(quit_text, (373, 515))
def draw_main_menu_lg(): #draw main menu with load game text in white
screen.fill(BLACK)
new_text = menu_font.render('NEW GAME', 1, (100, 100, 100))
load_text = menu_font.render('LOAD GAME', 1, (255, 255, 255))
options_text = menu_font.render('OPTIONS', 1, (100, 100, 100))
quit_text = menu_font.render('QUIT', 1, (100, 100, 100))
screen.blit(new_text, (340, 425))
screen.blit(load_text, (335, 455))
screen.blit(options_text, (350, 485))
screen.blit(quit_text, (373, 515))
Below, I'm using the variables x and y to check if the mouse is hovering over the buttons. The first set of two numbers is the range of the x coordinate, and the second set of two is the range for the y coordinate.
x,y = pygame.mouse.get_pos()
#set up new game mouse positions
if x >= 340 and x <= 465:
new_game_x_pos = True
if x < 340 or x > 465:
new_game_x_pos = False
if y >= 425 and y <= 445:
new_game_y_pos = True
if y < 425 or y > 445:
new_game_y_pos = False
if new_game_x_pos == True and new_game_y_pos == True:
draw_main_menu_ng()
if new_game_x_pos == False or new_game_y_pos == False:
draw_main_menu()
#set up load game mouse positions
if x >= 335 and x <= 470:
load_game_x_pos = True
if x < 335 or x > 470:
load_game_x_pos = False
if y >= 455 and y <= 475:
load_game_y_pos = True
if y < 455 or y > 475:
load_game_y_pos = False
if load_game_x_pos == True and load_game_y_pos == True:
draw_main_menu_lg()
if load_game_x_pos == False or load_game_y_pos == False:
draw_main_menu()
For some reason, when the mouse is over "NEW GAME" it won't change color. When the mouse is over "LOAD GAME" it will change color. Before I added the load game stuff, it would change color, but now only load game will. Any ideas on why it isn't working?
By the way, I do have code in the game loop that updates the screen. I also have code to set up the font.