def show_game_finished(self, milestone=None): FONT_s = pygame.font.Font('freesansbold.ttf', 15) FONT_m = pygame.font.Font('freesansbold.ttf', 20) FONT_l = pygame.font.Font('freesansbold.ttf', 80) text_obj_0 = FONT_m.render("CONGRATULATIONS!! YOU WON !!", True, F.white, None) text_obj_1 = FONT_s.render( "Press <ENTER> to continue the INFINITE mode", True, F.white, None) text_obj_2 = FONT_s.render("Press <Q>to quit the game.", True, F.white, None) text_obj_3 = FONT_s.render("Press <R> to start over the game.", True, F.white, None) if milestone is not None: text_obj_0 = INvFONT.render("MILESTONE [%d] REACHED" % milestone, True, F.white, None) text_obj_1 = GFONT.render("Press <ENTER> to continue.", True, F.white, F.black) text_obj_2 = GFONT.render("", True, F.white, F.black) #pygame.draw.rect(self.DISPLAYSUR, F.blue, F.menu_rect) self.draw_pop_up_menu_bg_rect(F.blue2, size=None) y_offset = 150 self.DISPLAYSUR.blit( text_obj_0, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 20)) self.DISPLAYSUR.blit( text_obj_1, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 60)) self.DISPLAYSUR.blit( text_obj_2, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 90)) self.DISPLAYSUR.blit( text_obj_3, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 120)) GenUI.draw_text_with_outline(self.DISPLAYSUR, FONT_l, "YOU WIN", F.orange, F.red, 5, (F.center_x, F.center_y - 150), if8=True, if_center=True) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: self.quit_game() elif event.type == KEYDOWN: if event.unicode == 'r': self.reset_game() if event.unicode == 'q': self.quit_game() if event.key == pygame.K_RETURN: self.resume_game() else: pass
def show_main_menu(self): #self.game_status = 1 #pass FONT_m = pygame.font.Font('freesansbold.ttf', 20) FONT_l = pygame.font.Font('freesansbold.ttf', 100) text_obj_0 = FONT_m.render("Press <ENTER> to start", True, F.white, None) text_obj_1 = FONT_m.render("Press <Q> to quit.", True, F.white, None) #pygame.draw.rect(self.DISPLAYSUR, F.red, F.menu_rect) self.draw_pop_up_menu_bg_rect(F.red, size=F.menu_size) y_offset = 200 self.DISPLAYSUR.blit(text_obj_0, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 20)) self.DISPLAYSUR.blit(text_obj_1, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 50)) # Game Tile fg_color = F.white bg_color = F.orange if F.blink_title: if self.title_counter >= 10000: self.title_counter = 0 color_idx = int(self.title_counter / F.blink_tile_fps) % 10 fg_color = [ F.black, F.grey1, F.blue, F.red, F.white, F.green, F.blue2, F.grey2, F.yellow, F.blue ][color_idx] self.title_counter += 1 GenUI.draw_text_with_outline(self.DISPLAYSUR, FONT_l, F.game_name, fg_color, bg_color, 5, (F.center_x, F.center_y - 100), if8=True, if_center=True) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: self.quit_game() elif event.type == KEYDOWN: #if event.key == pygame.K_ESCAPE or event.unicode == 'q': if event.unicode == 'q': self.quit_game() if event.key == pygame.K_RETURN: self.reset_game() else: pass
def show_option(self): FONT_s = pygame.font.Font('freesansbold.ttf', 15) FONT_m = pygame.font.Font('freesansbold.ttf', 20) FONT_l = pygame.font.Font('freesansbold.ttf', 65) text_obj_0 = FONT_m.render(" ", True, F.white, None) text_obj_1 = FONT_s.render("Press <F1> or <ESC> to resume the game.", True, F.white, None) text_obj_2 = FONT_s.render("Press <Q> to quit the game.", True, F.white, None) text_obj_3 = FONT_s.render("Press <R> to start over the game.", True, F.white, None) text_obj_4 = FONT_s.render("To play: ", True, F.white, None) text_obj_4a = FONT_s.render( " Arrow Key / W,A,S,D / H,J,K,L to move ", True, F.white, None) text_obj_4b = FONT_s.render( " * LEFT board: merge two blocks of opposite signs, ", True, F.white, None) text_obj_4c = FONT_s.render( " with same values to cancel them and move them ", True, F.white, None) text_obj_4d = FONT_s.render(" to the RIGHT board. ", True, F.white, None) text_obj_4e = FONT_s.render( " * RIGHT board: play like a normal 2048 game. ", True, F.white, None) text_obj_4f = FONT_s.render( " creat a 2048 tile on RIGHT to win. ", True, F.white, None) self.draw_pop_up_menu_bg_rect(F.green, size=F.menu_size + 10) y_offset = 90 self.DISPLAYSUR.blit(text_obj_0, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 20)) self.DISPLAYSUR.blit(text_obj_1, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 20)) self.DISPLAYSUR.blit(text_obj_2, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 40)) self.DISPLAYSUR.blit(text_obj_3, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 60)) self.DISPLAYSUR.blit(text_obj_4, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 110)) self.DISPLAYSUR.blit(text_obj_4a, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 130)) self.DISPLAYSUR.blit(text_obj_4b, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 150)) self.DISPLAYSUR.blit(text_obj_4c, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 170)) self.DISPLAYSUR.blit(text_obj_4d, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 190)) self.DISPLAYSUR.blit(text_obj_4e, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 210)) self.DISPLAYSUR.blit(text_obj_4f, (F.center_x - F.menu_size + 20, F.center_y - F.menu_size + y_offset + 230)) GenUI.draw_text_with_outline(self.DISPLAYSUR, FONT_l, "OPTION MENU", F.white, F.orange, 5, (F.center_x, F.center_y - 170), if8=True, if_center=True) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: self.quit_game() elif event.type == KEYDOWN: if event.unicode == 'r': self.reset_game() if event.unicode == 'q': self.quit_game() if event.key == pygame.K_ESCAPE or event.key == pygame.K_F1: self.resume_game() else: pass
action = 'down' elif eventkey in [K_UP, K_k, K_w]: action = 'up' else: #print("bad event key!!") pass return action # Starting the game components pygame.init() pygame.display.set_caption(F.game_name) board_0 = Board() board_1 = RightBoard() status_bar = StatusBar() gen_ui = GenUI() DISPLAYSUR = pygame.display.set_mode((F.window_w, F.window_h)) controller = Controller(DISPLAYSUR) sound_player = SoundPlayer(pygame) clock = pygame.time.Clock() # setup a font for displaying block numbers GFONT = pygame.font.Font('freesansbold.ttf', F.block_font_size) GFONT_GG = pygame.font.Font('freesansbold.ttf', 66) GFONTS = [ pygame.font.Font('freesansbold.ttf', int(F.block_font_size * F.block_font_size_perc[0])), pygame.font.Font('freesansbold.ttf', int(F.block_font_size * F.block_font_size_perc[1])), pygame.font.Font('freesansbold.ttf', int(F.block_font_size * F.block_font_size_perc[2])),
def show_option(self): FONT_s = pygame.font.Font('freesansbold.ttf', 15) FONT_m = pygame.font.Font('freesansbold.ttf', 20) FONT_l = pygame.font.Font('freesansbold.ttf', 65) text_obj_0 = FONT_m.render(" ", True, F.white, None) text_obj_1 = FONT_s.render("Press <F1> or <ESC> to resume the game.", True, F.white, None) text_obj_2 = FONT_s.render("Press <Q> to quit the game.", True, F.white, None) text_obj_3 = FONT_s.render("Press <R> to start over the game.", True, F.white, None) text_obj_4 = FONT_s.render("To play: ", True, F.white, None) text_obj_4a = FONT_s.render( " Arrow Key / W,A,S,D / H,J,K,L to move ", True, F.white, None) text_obj_4b = FONT_s.render( " Upgrade the castle in the middle to win ", True, F.white, None) self.draw_pop_up_menu_bg_rect(F.green, size=None) y_offset = 90 self.DISPLAYSUR.blit( text_obj_0, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 20)) self.DISPLAYSUR.blit( text_obj_1, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 20)) self.DISPLAYSUR.blit( text_obj_2, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 40)) self.DISPLAYSUR.blit( text_obj_3, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 60)) self.DISPLAYSUR.blit( text_obj_4, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 90)) self.DISPLAYSUR.blit( text_obj_4a, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 110)) self.DISPLAYSUR.blit( text_obj_4b, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 130)) GenUI.draw_text_with_outline(self.DISPLAYSUR, FONT_l, "OPTION MENU", F.white, F.orange, 5, (F.center_x, F.center_y - 170), if8=True, if_center=True) # draw the trophies text_obj_5 = FONT_s.render("Achievements", True, F.white, None) self.DISPLAYSUR.blit( text_obj_5, (F.menu_rect[0] + 20, F.menu_rect[1] + y_offset + 165)) trophy_pos = (F.menu_rect[0] + 40, F.menu_rect[1] + y_offset + 185, 300, 100) self.trophy.draw_trophy(self.DISPLAYSUR, trophy_pos) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: self.quit_game() elif event.type == KEYDOWN: if event.unicode == 'r': self.reset_game() if event.unicode == 'q': self.quit_game() if event.key == pygame.K_ESCAPE or event.key == pygame.K_F1: self.resume_game() else: pass