def open_login(logged_in): clock = pygame.time.Clock() login_win = pygame.display.set_mode((1920, 1080)) pygame.display.set_caption("Log In") game_background = pygame.image.load("assets/game/game_background.jpg") username_text = Text(500, 375, "freesansbold", 70) username_text.set_text("Username: "******"freesansbold", 70) password_text.set_text("Password: "******"Login", 66) texts_to_draw = [username_text, password_text] input_boxes = [username_input, password_input] login_run = True while login_run: clock.tick(60) login_win.blit(game_background, (0, 0)) events = pygame.event.get() for event in events: pos = pygame.mouse.get_pos() if event.type == pygame.MOUSEBUTTONDOWN: if login_button.isOver(pos): print(f"username - {username_input.text}") print(f"password - {password_input.actual_text}") user = db.log_in(username_input.text, password_input.actual_text) if not user: logged_in = False else: logged_in = True print("Logged in is {}".format(logged_in)) mixer.fadeout(1) run_menu(user, logged_in, music=False) exit() if event.type == pygame.MOUSEMOTION: if login_button.isOver(pos): login_button.color = (54, 150, 90) else: login_button.color = (53, 189, 103) if event.type == pygame.QUIT: login_run = False for box in input_boxes: box.handle_event(event) #exit() for box in input_boxes: box.draw(login_win) for text in texts_to_draw: text.draw(login_win) login_button.draw(login_win, outline=True) pygame.display.update()
def run(self): if not self.resume: self.playing = False self.running = True self.gameover = False self.paused = False self.last_answer = -1 self.last_answer_index = -1 question_dirty = True pygame.display.init() display_info = pygame.display.Info() background_color = Color.SKYBLUE screen = pygame.display.get_surface() screen_size = screen.get_size() ground = pygame.Surface((screen_size[0], screen_size[1] / 3)) ground = ground.convert() ground.fill(Color.BROWN) button_panel = pygame.Surface((screen_size[0] / 3, screen_size[1] / 7)) self.buttons = [ Button(str(self.question.choices[i]), self.lg_font, Color.BLACK, button_panel.get_width() / 2, button_panel.get_height() / 2, Color.WHITE, Color.BLACK, -2) for i in range(4) ] grass = pygame.draw.line(ground, Color.GREEN, (0, 0), (ground.get_width(), 0), int(ground.get_height() / 2)) points_label = self.lg_font.render('POINTS', 1, Color.BLACK) sun = Sun() sun.rect.topleft = (screen_size[0] - sun.image.get_width(), 0) horse = Horse() horse.rect.x = display_info.current_h / 3 horse.rect.y = display_info.current_h - \ horse.image.get_height() - ground.get_height() hurdle = pygame.image.load('./assets/images/hurdle.png') hurdle = pygame.transform.scale( hurdle, (int(hurdle.get_height() / 3), int(hurdle.get_width() / 3))) hurdle_y = display_info.current_h - \ hurdle.get_height() - (2 * ground.get_height() / 3) question_board = pygame.Surface( (screen_size[0] / 3, screen_size[1] / 5)) question_board = question_board.convert() question_board.fill(Color.WHITE) play_button = Button('Play', self.lg_font, Color.BLACK, 200, 100, Color.WHITE, Color.BLACK, -2) menu_label = self.xlg_font.render('MATH HURDLER', 1, Color.BLACK) gameover_label = self.xlg_font.render('GAME OVER', 1, Color.BLACK) pygame.mixer.music.load(self.songs[0]) pygame.mixer.music.play(-1) def reset(): question_dirty = True self.points = 0 self.hurdle_number = 0 self.x = -100 self.vx = 0 self.direction = -1 horse.set_horse(Horse.BASE) set_answer(-1) def generate_question(): next(self.question) self.buttons[0].set_text(str(self.question.choices[0])) self.buttons[1].set_text(str(self.question.choices[1])) self.buttons[2].set_text(str(self.question.choices[2])) self.buttons[3].set_text(str(self.question.choices[3])) self.buttons[0].set_color(self.buttons[0].color, False) self.buttons[1].set_color(self.buttons[0].color, False) self.buttons[2].set_color(self.buttons[0].color, False) self.buttons[3].set_color(self.buttons[0].color, False) self.question_text_label = self.lg_font.render( str(self.question), 1, Color.BLACK) self.hurdle_number += 1 self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK) self.question_label = self.font.render( "Hurdle #" + str(self.hurdle_number), 1, Color.BLACK) question_board.fill(Color.WHITE) self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK) def set_answer(answer_index): # unselect the previous answer button if self.last_answer_index >= 0: self.buttons[self.last_answer_index].set_selected(False) if answer_index >= 0: self.last_answer = Fraction(self.buttons[answer_index].text) self.buttons[answer_index].set_selected(True) self.last_answer_index = answer_index else: self.last_answer = -1 self.last_answer_index = -1 def evaluate_answer(answer): if self.question.is_answer(answer): self.points += 100 self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK) self.jump_sfx.play() else: self.set_gameover(True) if self.last_answer_index >= 0: self.buttons[self.last_answer_index].set_color( Color.RED, False) self.buttons[self.question.answer_index].set_color( Color.GREEN, False) while self.running: # Processing Gtk Events while Gtk.events_pending(): Gtk.main_iteration() if self.playing: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_p: self.paused = not self.paused elif event.key == pygame.K_c: set_answer(self.question.answer_index) elif event.type == pygame.MOUSEBUTTONDOWN: if not self.gameover: for i in range(0, 4): self.buttons[i].mouse_click( pygame.mouse.get_pos(), set_answer, i) screen_size = screen.get_size() if not self.paused and not self.gameover: # start at vx=5 and accelerate towards vx=10 self.vx = 4 + (self.hurdle_number * 6) / \ (self.hurdle_number + 5) self.x += self.vx * self.direction if self.direction == 1 and self.x > screen.get_width() \ + 50: self.x = -50 elif self.direction == -1 and self.x < -50: self.x = screen.get_width() + 50 hurdle_rect = hurdle.get_rect(topleft=(self.x, hurdle_y)) if (horse.active_horse == Horse.JUMP) and ( not horse.rect.colliderect(hurdle_rect)): horse.set_horse(Horse.BASE) if (self.horse_change == self.horse_change_semaphore): horse.gallop() self.horse_change = 0 self.horse_change += 1 horse.rect.x = display_info.current_w / 3 horse.rect.y = display_info.current_h - \ hurdle.get_height() - (3 * ground.get_height() / 4) # Check if hurdle and horse in same spot. if horse.rect.colliderect(hurdle_rect): # evaluate answer on first frame of hurdle collision if not question_dirty: evaluate_answer(self.last_answer) question_dirty = True # if not gameover, jump the hurdle if not self.gameover: horse.set_horse(Horse.JUMP) horse.rect.x = display_info.current_w / 3 horse.rect.y = display_info.current_h \ - horse.image.get_height() \ - ground.get_height() \ - 100 # if not colliding with hurdle and question still dirty, # generate new question elif question_dirty: generate_question() question_dirty = False set_answer(-1) if self.gameover: # spin the horse horse.set_horse(Horse.DEAD) # Set the "sky" color to blue screen.fill(background_color) sun.rect.topleft = (screen_size[0] - sun.image.get_width(), 0) screen.blit(question_board, (screen_size[0] / 4, screen_size[1] / 5)) question_board.blit(self.question_label, (10, 10)) question_board.blit( self.question_text_label, (10, self.question_label.get_height() + 10)) screen.blit(ground, (0, screen_size[1] - ground.get_height())) button_panel_x = ground.get_width() / 4 button_panel_y = screen_size[1] - \ ground.get_height() + ground.get_height() / 3 + 10 screen.blit(button_panel, (button_panel_x, button_panel_y)) self.buttons[0].rect.x = button_panel_x self.buttons[0].rect.y = button_panel_y self.buttons[0].draw(screen) self.buttons[1].rect.x = button_panel_x + \ self.buttons[0].image.get_width() self.buttons[1].rect.y = button_panel_y self.buttons[1].draw(screen) self.buttons[2].rect.x = button_panel_x self.buttons[2].rect.y = button_panel_y + \ self.buttons[0].image.get_height() self.buttons[2].draw(screen) self.buttons[3].rect.x = button_panel_x + \ self.buttons[2].image.get_width() self.buttons[3].rect.y = button_panel_y + \ self.buttons[2].image.get_height() self.buttons[3].draw(screen) screen.blit(hurdle, (self.x, hurdle_y)) allsprites = pygame.sprite.RenderPlain(sun, horse) allsprites.draw(screen) screen.blit(self.score_label, (sun.rect.x + sun.image.get_width() / 4, sun.rect.y + sun.image.get_height() / 3)) screen.blit(points_label, (sun.rect.x + sun.image.get_width() / 4, sun.rect.y + sun.image.get_height() / 3 + self.score_label.get_height())) if self.gameover: screen.blit(gameover_label, ( (screen_size[0] - gameover_label.get_width()) / 2, (screen_size[1] - gameover_label.get_height()) / 2, )) # Draw the frame pygame.display.flip() if self.gameover: pygame.time.delay(6000) self.set_playing(False) reset() # Try to stay at 30 FPS self.clock.tick(18) else: def start_game(): reset() self.set_playing(True) # in the menu for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) elif event.type == pygame.MOUSEBUTTONDOWN: play_button.mouse_click(pygame.mouse.get_pos(), start_game) screen_size = screen.get_size() if (self.horse_change == self.horse_change_semaphore): horse.gallop() self.horse_change = 0 self.horse_change += 1 # draw rainbow background fill screen.fill( (math.floor( math.sin(pygame.time.get_ticks() * .001) * 55 + 200), math.floor( math.sin(pygame.time.get_ticks() * .001 + math.pi) * 55 + 200), math.floor( math.sin(pygame.time.get_ticks() * .001 + math.pi * .5) * 55 + 200))) # draw menu horse horse.rect.x = (screen_size[0] - horse.image.get_width()) / 2 horse.rect.y = (screen_size[1] - horse.image.get_height()) / 2 + 200 menu_sprites = pygame.sprite.RenderPlain(horse) menu_sprites.draw(screen) # draw play button play_button.rect.x = (screen_size[0] - play_button.rect.width) / 2 play_button.rect.y = (screen_size[1] - play_button.rect.height) / 2 play_button.draw(screen) # draw menu label screen.blit(menu_label, ( (screen_size[0] - menu_label.get_width()) / 2, (screen_size[1] - menu_label.get_height()) / 2 - 200, )) pygame.display.flip() # Try to stay at 30 FPS self.clock.tick(30)
def start_play(user): """start_play starts the game screen """ #print(mixer.music.get_busy()) mixer.music.play(-1) mixer.music.set_volume(0.15) CLOCK = pygame.time.Clock() FPS = 60 textinput = InputBox(20, 20, 200, 50, '', True) textinput2 = InputBox(500, 500, 200, 50, '', False) game_win = pygame.display.set_mode((1920, 1080)) game_background = pygame.image.load("assets\\game\\game_background.jpg") player = Player("assets\\player\\snake.png", 700, 700) language1 = Language() language2 = Language() language3 = Language() language4 = Language() language5 = Language() current_lang_to_blit_index = 0 time_counter = 3 first_image = True time_to_blit = 80 failed = False images_to_blit = [[game_background, (0, 0)]] languages = [language1, language2, language3, language4, language5] input_boxes = [textinput, textinput2] best_score_text = Text(800, 200, "freesans", 40) score_text = Text(30, 25, "freesans", 30) score_text.set_text("Score: ") try_again_button = Button((255, 255, 255), 1185, 155, 350, 127, "Play Again!", 72) running = True while running: CLOCK.tick(FPS) current_fps = CLOCK.get_fps() events = pygame.event.get() for event in events: if event.type == pygame.QUIT: running = False for box in input_boxes: box.handle_event(event) if event.type == pygame.MOUSEMOTION: if try_again_button.isOver(pygame.mouse.get_pos()): try_again_button.color = (12, 152, 245) else: try_again_button.color = (255, 255, 255) for image in images_to_blit: game_win.blit(image[0], (image[1][0], image[1][1])) player.move(game_win) if time_counter % time_to_blit == 0: if first_image: first_image = False time_counter = 0 if languages[current_lang_to_blit_index].isOnScreen == False: languages[current_lang_to_blit_index].isOnScreen = True if current_lang_to_blit_index == len(languages) - 1: current_lang_to_blit_index = 0 # for lang in languages: # lang.set_on_screen() else: current_lang_to_blit_index += 1 time_counter += 1 for lang in languages: if lang.isOnScreen: if is_collided(player.x + 100, player.y, lang.x, lang.y): catch_sound.play() lang.reset_place() player.update_score() if not failed: if lang.move(game_win, player, languages) == False: failed = True score_text.replace(345, 100, 190) #! if db.update_bestscore(user, player.score): #! best_score_text.set_text("new record!") for lang in languages: lang.isOnScreen = False mixer.music.stop() failed_sound.play() for heart in player.hearts: heart.draw(game_win) best_score_text.draw(game_win) score_text.set_text(f"Score: {player.score}") score_text.draw(game_win) if failed: try_again_button.draw(game_win, True) pygame.display.update()
def run(self): self.running = True self.playing = False self.gameover = False self.paused = False self.last_answer = -1 self.last_answer_index = -1 question_dirty = True display_info = pygame.display.Info() background_color = Color.SKYBLUE screen = pygame.display.get_surface() screen_size = screen.get_size() ground = pygame.Surface((screen_size[0], screen_size[1] / 3)) ground = ground.convert() ground.fill(Color.BROWN) button_panel = pygame.Surface((screen_size[0]/3, screen_size[1] / 7)) self.buttons = [ Button( str(self.question.choices[i]), self.lg_font, Color.BLACK, button_panel.get_width() / 2, button_panel.get_height() / 2, Color.WHITE, Color.BLACK, -2 ) for i in range(4) ] grass = pygame.draw.line( ground, Color.GREEN, (0, 0), (ground.get_width(), 0), ground.get_height() / 2 ) points_label = self.lg_font.render('POINTS', 1, Color.BLACK) sun = Sun() sun.rect.topleft = (screen_size[0]- sun.image.get_width(),0) horse = Horse() horse.rect.x = display_info.current_h/3 horse.rect.y = display_info.current_h - horse.image.get_height() - ground.get_height() hurdle = pygame.image.load('./assets/images/hurdle.png') hurdle = pygame.transform.scale(hurdle,(hurdle.get_height()/3,hurdle.get_width()/3)) hurdle_y = display_info.current_h - hurdle.get_height() - (2*ground.get_height()/3) question_board = pygame.Surface((screen_size[0]/3, screen_size[1] / 5)) question_board = question_board.convert() question_board.fill(Color.WHITE) play_button = Button( 'Play', self.lg_font, Color.BLACK, 200, 100, Color.WHITE, Color.BLACK, -2 ) menu_label = self.xlg_font.render('MATH HURDLER', 1, Color.BLACK) gameover_label = self.xlg_font.render('GAME OVER', 1, Color.BLACK) pygame.mixer.music.load(self.songs[0]) pygame.mixer.music.play(-1) def reset(): question_dirty = True self.points = 0 self.hurdle_number = 0 self.x = -100 self.vx = 0 self.direction = -1 horse.set_horse(Horse.BASE) set_answer(-1) def generate_question(): self.question.next() self.buttons[0].set_text(str(self.question.choices[0])) self.buttons[1].set_text(str(self.question.choices[1])) self.buttons[2].set_text(str(self.question.choices[2])) self.buttons[3].set_text(str(self.question.choices[3])) self.buttons[0].set_color(self.buttons[0].color, False) self.buttons[1].set_color(self.buttons[0].color, False) self.buttons[2].set_color(self.buttons[0].color, False) self.buttons[3].set_color(self.buttons[0].color, False) self.question_text_label = self.lg_font.render(str(self.question), 1, Color.BLACK) self.hurdle_number += 1 self.score_label = self.lg_font.render(str(self.points),1,Color.BLACK) self.question_label = self.font.render("Hurdle #" + str(self.hurdle_number), 1, Color.BLACK) question_board.fill(Color.WHITE) self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK) def set_answer(answer_index): #unselect the previous answer button if self.last_answer_index >= 0: self.buttons[self.last_answer_index].set_selected(False) if answer_index >= 0: self.last_answer = Fraction(self.buttons[answer_index].text) self.buttons[answer_index].set_selected(True) self.last_answer_index = answer_index else: self.last_answer = -1 self.last_answer_index = -1 def evaluate_answer(answer): if self.question.is_answer(answer): self.points += 100 self.score_label = self.lg_font.render(str(self.points), 1, Color.BLACK) self.jump_sfx.play() else: self.set_gameover(True) if self.last_answer_index >= 0: self.buttons[self.last_answer_index].set_color(Color.RED, False) self.buttons[self.question.answer_index].set_color(Color.GREEN, False) while self.running: if self.playing: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_p: self.paused = not self.paused elif event.key == pygame.K_c: set_answer(self.question.answer_index) elif event.type == pygame.MOUSEBUTTONDOWN: if not self.gameover: for i in range(0, 4): self.buttons[i].mouse_click( pygame.mouse.get_pos(), set_answer, i ) screen_size = screen.get_size() if not self.paused and not self.gameover: #start at vx=5 and accelerate towards vx=10 self.vx = 4 + (self.hurdle_number * 6) / (self.hurdle_number + 5) self.x += self.vx * self.direction if self.direction == 1 and self.x > screen.get_width() + 50: self.x = -50 elif self.direction == -1 and self.x < -50: self.x = screen.get_width() + 50 hurdle_rect = hurdle.get_rect(topleft=(self.x,hurdle_y)) if (horse.active_horse == Horse.JUMP) and (not horse.rect.colliderect(hurdle_rect)): horse.set_horse(Horse.BASE) if (self.horse_change == self.horse_change_semaphore): horse.gallop() self.horse_change = 0 self.horse_change += 1 horse.rect.x = display_info.current_w / 3 horse.rect.y = display_info.current_h - hurdle.get_height() - (3*ground.get_height()/4) # Check if hurdle and horse in same spot. if horse.rect.colliderect(hurdle_rect): #evaluate answer on first frame of hurdle collision if not question_dirty: evaluate_answer(self.last_answer) question_dirty = True #if not gameover, jump the hurdle if not self.gameover: horse.set_horse(Horse.JUMP) horse.rect.x = display_info.current_w / 3 horse.rect.y = display_info.current_h - horse.image.get_height() - ground.get_height() - 100 #if not colliding with hurdle and question still dirty, generate new question elif question_dirty: generate_question() question_dirty = False set_answer(-1) if self.gameover: #spin the horse horse.set_horse(Horse.DEAD) # Set the "sky" color to blue screen.fill(background_color) sun.rect.topleft = (screen_size[0]- sun.image.get_width(),0) screen.blit(question_board, (screen_size[0] / 4, screen_size[1] / 5)) question_board.blit(self.question_label, (10,10)) question_board.blit(self.question_text_label, (10,self.question_label.get_height()+10)) screen.blit(ground, (0, screen_size[1] - ground.get_height())) button_panel_x = ground.get_width()/4 button_panel_y = screen_size[1] - ground.get_height() + ground.get_height() / 3 + 10 screen.blit(button_panel, (button_panel_x, button_panel_y)) self.buttons[0].rect.x = button_panel_x self.buttons[0].rect.y = button_panel_y self.buttons[0].draw(screen) self.buttons[1].rect.x = button_panel_x + self.buttons[0].image.get_width() self.buttons[1].rect.y = button_panel_y self.buttons[1].draw(screen) self.buttons[2].rect.x = button_panel_x self.buttons[2].rect.y = button_panel_y + self.buttons[0].image.get_height() self.buttons[2].draw(screen) self.buttons[3].rect.x = button_panel_x + self.buttons[2].image.get_width() self.buttons[3].rect.y = button_panel_y + self.buttons[2].image.get_height() self.buttons[3].draw(screen) screen.blit(hurdle,(self.x,hurdle_y)) allsprites = pygame.sprite.RenderPlain(sun,horse) allsprites.draw(screen) screen.blit( self.score_label, ( sun.rect.x + sun.image.get_width() / 4, sun.rect.y + sun.image.get_height() / 3 ) ) screen.blit( points_label, ( sun.rect.x + sun.image.get_width() / 4, sun.rect.y + sun.image.get_height() / 3 + self.score_label.get_height() ) ) if self.gameover: screen.blit( gameover_label, ( (screen_size[0] - gameover_label.get_width()) / 2, (screen_size[1] - gameover_label.get_height()) / 2, ) ) # Draw the frame pygame.display.flip() if self.gameover: pygame.time.delay(6000) self.set_playing(False) reset() # Try to stay at 30 FPS self.clock.tick(30) else: def start_game(): reset() self.set_playing(True) #in the menu for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) elif event.type == pygame.MOUSEBUTTONDOWN: play_button.mouse_click( pygame.mouse.get_pos(), start_game ) screen_size = screen.get_size() if (self.horse_change == self.horse_change_semaphore): horse.gallop() self.horse_change = 0 self.horse_change += 1 #draw rainbow background fill screen.fill( ( math.floor(math.sin(pygame.time.get_ticks()*.001)*55 + 200), math.floor(math.sin(pygame.time.get_ticks()*.001+math.pi)*55 + 200), math.floor(math.sin(pygame.time.get_ticks()*.001+math.pi*.5)*55 + 200) ) ) #draw menu horse horse.rect.x = (screen_size[0] - horse.image.get_width()) / 2 horse.rect.y = (screen_size[1] - horse.image.get_height()) / 2 + 200 menu_sprites = pygame.sprite.RenderPlain(horse) menu_sprites.draw(screen) #draw play button play_button.rect.x = (screen_size[0] - play_button.rect.width) / 2 play_button.rect.y = (screen_size[1] - play_button.rect.height) / 2 play_button.draw(screen) #draw menu label screen.blit( menu_label, ( (screen_size[0] - menu_label.get_width()) / 2, (screen_size[1] - menu_label.get_height()) / 2 - 200, ) ) pygame.display.flip() # Try to stay at 30 FPS self.clock.tick(30)
def run_menu(user=None, logged_in=False, music=True): """run_menu starts the menu """ if music: mixer.music.play(-1) mixer.music.set_volume(0.25) CLOCK = pygame.time.Clock() FPS = 60 white = (255, 255, 255) green = (0, 255, 0) blue = (0, 0, 128) started_playing = False # assigning values to X and Y variable menu_win = pygame.display.set_mode((1920, 1080)) pygame.display.set_caption("Main Menu") game_background = pygame.image.load("assets/game/game_background.jpg") # create a font object. # 1st parameter is the font file # which is present in pygame. # 2nd parameter is size of the font # create a text suface object, # on which text is drawn on it. if user is not None: user_text = Text(100, 100, "arial", 42) user_text.set_text(f"Welcome Back - {user['username']}") title_text = Text(830, 370, "arial", 80) title_text.set_text("Snake It!", bold=True) play_button = Button((0, 0, 0), 850, 500, 200, 100, "Play!", 46) login_button = Button((0, 0, 0), 400, 650, 200, 100, "Login", 42) signup_button = Button((0, 0, 0), 1325, 650, 200, 100, "Sign Up", 42) # set the center of the rectangular object. images_to_blit = [[game_background, (0, 0)]] #input_boxes = [textinput, textinput2] # create the display surface object # of specific dimension..e(X, Y). # set the pygame window name menu_run = True while menu_run: title_text.draw(menu_win) CLOCK.tick(FPS) current_fps = CLOCK.get_fps() events = pygame.event.get() for event in events: pos = pygame.mouse.get_pos() if event.type == pygame.MOUSEBUTTONDOWN: if play_button.isOver(pos) and logged_in: menu_run = False start_play(user) mixer.music.fadeout(1) exit() if login_button.isOver(pos): menu_run = False open_login(logged_in) exit() if event.type == pygame.MOUSEMOTION: #if play_button.isOver(pos) and logged_in: if play_button.isOver(pos): play_button.color = (92, 176, 86) else: play_button.color = (255, 255, 255) if login_button.isOver(pos) and not logged_in: login_button.color = (17, 63, 143) else: login_button.color = (255, 255, 255) if signup_button.isOver(pos) and not logged_in: signup_button.color = (76, 29, 145) else: signup_button.color = (255, 255, 255) if event.type == pygame.QUIT: menu_run = False menu_win.blit(game_background, (0, 0)) title_text.draw(menu_win) if user is not None: user_text.draw(menu_win) if logged_in == True: play_button.draw(menu_win, outline=(0, 0, 0)) else: login_button.draw(menu_win, (0, 0, 0)) signup_button.draw(menu_win, (0, 0, 0)) pygame.display.update()