def __init__(self, rect, shadow_dist, sys_font): self.rect = rect self.sys_font = sys_font self.shadow_dist = shadow_dist self.in_focus = False # render stuff edge_buffer = rect.width * 0.05 self.rect_edge_buffer = rect.width * 0.01 max_text_size = (sys_font.size("AAAAAAAA")[0] * 4, sys_font.size("AAAAAAAA")[1] * 4) player_rect_width = max_text_size[0] + self.rect_edge_buffer * 2 self.background = pygame.Surface(rect.size, pygame.SRCALPHA) self.background.fill((0, 0, 0, 100)) self.bounding_rect = pygame.Rect( (edge_buffer, edge_buffer * 2), (self.background.get_width() - edge_buffer * 2, self.background.get_height() - edge_buffer * 3)) self.player_rect = pygame.Rect( (self.bounding_rect.centerx - player_rect_width / 2, self.bounding_rect.top), (player_rect_width, max_text_size[1])) self.title_text = TextRenderer( sys_font, 2, (rect.centerx, rect.top + max_text_size[1] / 2), shadow_dist) plus_text, plus_text_shadow = ShadowedPressable.make_pressable_key( "[+] to add", sys_font, 1) self.plus_text = ShadowedPressable( plus_text.convert_alpha(), plus_text_shadow, (rect.centerx * 1.75, rect.height * 0.45), shadow_dist / 2) minus_text, minus_text_shadow = ShadowedPressable.make_pressable_key( "[-] to subtract", sys_font, 1) self.minus_text = ShadowedPressable( minus_text.convert_alpha(), minus_text_shadow, (rect.centerx * 1.75, rect.height * 0.5), shadow_dist / 2) enter_text, enter_text_shadow = ShadowedPressable.make_pressable_key( "[ENTER] to proceed", sys_font, 1) self.enter_text = ShadowedPressable( enter_text.convert_alpha(), enter_text_shadow, (rect.centerx * 1.75, rect.height * 0.6), shadow_dist / 2) # list stuff self.list = [] self.addEntry() self.addEntry() self.selected = self.list[0] # sound stuff self.press_sound = pygame.mixer.Sound("SFX/press_soft.wav") self.release_sound = pygame.mixer.Sound("SFX/release.wav") # outward facing stuff self.pf = self.list[0] self.pj = self.list[1]
def render(self, target, string, color=None): if color is None: color = self.color text, shadow = ShadowedPressable.make_pressable_key(string, self.font, self.scale, color=color) ShadowedPressable(text, shadow, self.center, self.shadow_dist).render(target)
def __init__(self, top_rect, bottom_rect, shadow_dist, sys_font): self.top_rect = top_rect self.bottom_rect = bottom_rect self.shadow_dist = shadow_dist self.timer_text = TextRenderer(sys_font, 2, (top_rect.centerx, top_rect.bottom - top_rect.height * 0.2), shadow_dist / 2) self.perc_f_text = TextRenderer(sys_font, 4, (top_rect.width / 4, top_rect.centery), shadow_dist, color = GameColor.J.Med) self.perc_j_text = TextRenderer(sys_font, 4, (top_rect.width * 3 / 4, top_rect.centery), shadow_dist, color = GameColor.F.Med) menu_text, menu_text_shadow = ShadowedPressable.make_pressable_key("[1] menu", sys_font, 1, GameColor.F.Dark) self.menu_text = ShadowedPressable(menu_text.convert_alpha(), menu_text_shadow, (top_rect.width * 0.05, top_rect.height * 0.13), 0)
def __init__(self, sys_font, shadow_dist, key, title, hold_time, callback, color=None): self.sys_font = sys_font self.shadow_dist = shadow_dist self.title = title self.hold_time = hold_time self.callback = callback self.color = color self.hold_timer = 1 key, key_shadow = ShadowedPressable.make_pressable_key( key, sys_font, 4) self.key_text = ShadowedPressable(key.convert_alpha(), key_shadow, (0, 0), shadow_dist) self.title_text = TextRenderer(sys_font, 4, (0, 0), shadow_dist)
def __init__(self, AGREE_TIME, WIN_TIME, COOLDOWN_TIME, STALE_TIME, TOTAL_TIME, FAILURE_TIME, NUM_WINS, keys, p_list_rect, scoreboard_rect, top_rect, top_rect_left, top_rect_right, game_rect, bottom_rect, shadow_dist, sys_font): # -- IMPORTS -- self.keys = keys self.top_rect_left = top_rect_left self.top_rect_right = top_rect_right self.bottom_rect = bottom_rect self.AGREE_TIME = AGREE_TIME self.NUM_WINS = NUM_WINS self.shadow_dist = shadow_dist # -- MATCH INFO -- self.match_num = 0 self.big_f_agree = self.big_j_agree = 0 self.f_wins = self.j_wins = 0 self.score_streak = 0 # -- NECESSARY CLASSES -- self.p_list = PlayerList(p_list_rect, shadow_dist, sys_font) self.game = Game(WIN_TIME, COOLDOWN_TIME, STALE_TIME, TOTAL_TIME, FAILURE_TIME, self.keys, game_rect, shadow_dist, sys_font) self.wheel = Wheel(game_rect, shadow_dist, sys_font) self.hud = Hud(top_rect, bottom_rect, shadow_dist, sys_font) self.scoreboard = Scoreboard(scoreboard_rect, shadow_dist, sys_font, self.p_list) self.menu = Menu(p_list_rect, self.keys, shadow_dist, sys_font) self.match_state = MatchState(MatchState.PLAYER_LIST, self.state_response) # -- MENU ACTIONS -- self.menu.add_item( "[2]", "PRACTICE MODE", 0.5, lambda: self.match_state.set_state(MatchState.PRACTICE_MODE)) self.menu.add_item( "[3]", "RESET MATCHUP", 0.5, lambda: self.match_state.set_state(MatchState.NEW_OPPONENT, same_match=True)) self.menu.add_item( "[4]", "NEXT OPPONENT", 0.5, lambda: self.match_state.set_state(MatchState.NEW_OPPONENT, next=True)) self.menu.add_item( "[5]", "CHANGE PLAYERS", 0.5, lambda: self.match_state.set_state(MatchState.PLAYER_LIST)) # -- RENDERING -- # bottom bar self.f_name_text = TextRenderer( sys_font, 2, (top_rect_left.centerx, bottom_rect.centery), shadow_dist) self.j_name_text = TextRenderer( sys_font, 2, (top_rect_right.centerx, bottom_rect.centery), shadow_dist) self.streak_text = TextRenderer( sys_font, 1, (bottom_rect.width * 0.08, bottom_rect.centery + bottom_rect.height * 0.25), shadow_dist) self.practice_mode_text = TextRenderer(sys_font, 2, bottom_rect.center, 0) self.practice_inst_rect = Rect( (game_rect.left + game_rect.height * 0.05, game_rect.top + game_rect.height * 0.05), (game_rect.width, game_rect.height * 0.25)) self.practice_inst_0 = ShadowedPressable.make_pressable_key( "1. Hold your key to build your bar.", sys_font, 1, GameColor.Pink)[0].convert_alpha() self.practice_inst_1 = ShadowedPressable.make_pressable_key( "2. Press [SPACE] to reset moving bars.", sys_font, 1, GameColor.Cyan)[0].convert_alpha() self.practice_inst_2 = ShadowedPressable.make_pressable_key( "3. Build the biggest bar to win!", sys_font, 1, GameColor.Yellow)[0].convert_alpha() # vs self.new_match_text = TextRenderer( sys_font, 4, (game_rect.centerx, game_rect.top + game_rect.height / 6), shadow_dist, GameColor.White) self.vs_left_bar = Rect((0, game_rect.y + game_rect.height / 3), (top_rect_left.width, game_rect.height / 5)) self.vs_right_bar = Rect( (game_rect.centerx, self.vs_left_bar.bottom), (self.vs_left_bar.width, self.vs_left_bar.height)) vs_par_width = game_rect.height / 7 self.vs_parallelogram = ((game_rect.centerx, self.vs_left_bar.top), (game_rect.centerx - vs_par_width, self.vs_right_bar.bottom), (game_rect.centerx, self.vs_right_bar.bottom), (game_rect.centerx + vs_par_width, self.vs_left_bar.top)) self.f_name_big_text = TextRenderer( sys_font, 4, (top_rect_left.centerx + shadow_dist, self.vs_left_bar.centery + shadow_dist), shadow_dist, GameColor.F.Dark) self.j_name_big_text = TextRenderer( sys_font, 4, (top_rect_right.centerx + shadow_dist, self.vs_right_bar.centery + shadow_dist), shadow_dist, GameColor.J.Dark) self.vs_text = TextRenderer(sys_font, 2, (game_rect.centerx + shadow_dist, self.vs_left_bar.bottom + shadow_dist), shadow_dist) self.vs_left_bar.move_ip((top_rect_left.width, 0)) big_f, big_f_shadow = ShadowedPressable.make_pressable_key( "[F]", sys_font, 4) self.big_f = ShadowedPressable( big_f.convert_alpha(), big_f_shadow, (top_rect_left.centerx, game_rect.top + game_rect.height * 0.85), shadow_dist) big_j, big_j_shadow = ShadowedPressable.make_pressable_key( "[J]", sys_font, 4) self.big_j = ShadowedPressable( big_j.convert_alpha(), big_j_shadow, (top_rect_right.centerx, game_rect.top + game_rect.height * 0.85), shadow_dist) # counter self.counter = TextRenderer(sys_font, 4, game_rect.center, shadow_dist) self.ready_text = TextRenderer( sys_font, 2, (game_rect.centerx, game_rect.top + game_rect.height * 0.35), shadow_dist) # win rects win_rect_size = top_rect.height * 0.15 self.win_rect = Rect(top_rect.centerx - win_rect_size / 2, win_rect_size, win_rect_size, win_rect_size) self.win_rect_shadows = [ self.win_rect.move(self.win_rect.width * 2 * idx, 0) for idx in [-3, -2, -1, 1, 2, 3] ] self.f_win_rects = [] self.j_win_rects = [] # win text self.f_win_loss_text = TextRenderer( sys_font, 4, (top_rect_left.centerx, game_rect.top + game_rect.height * 0.35), shadow_dist) self.j_win_loss_text = TextRenderer( sys_font, 4, (top_rect_right.centerx, game_rect.top + game_rect.height * 0.35), shadow_dist) self.f_plus_minus_text = TextRenderer( sys_font, 4, (top_rect_left.centerx, game_rect.top + game_rect.height * 0.65), shadow_dist) self.j_plus_minus_text = TextRenderer( sys_font, 4, (top_rect_right.centerx, game_rect.top + game_rect.height * 0.65), shadow_dist) self.f_enc_cons_text = TextRenderer( sys_font, 1, (top_rect_left.centerx, game_rect.top + game_rect.height * 0.5), shadow_dist / 8) self.j_enc_cons_text = TextRenderer( sys_font, 1, (top_rect_right.centerx, game_rect.top + game_rect.height * 0.5), shadow_dist / 8) # tweens self.vs_bar_w = Tweener( { "retracted": 0, "extended": top_rect_left.width }, "retracted") self.f_name_big_x = Tweener( { "out": 0, "in": self.f_name_big_text.center[0] }, "out") self.j_name_big_x = Tweener( { "out": game_rect.right, "in": self.j_name_big_text.center[0] }, "out") # -- SOUND -- self.vs_sound = pygame.mixer.Sound("SFX/VS.wav") self.timer_sound = pygame.mixer.Sound("SFX/beep.wav") self.begin_sound = pygame.mixer.Sound("SFX/begin_game.wav") self.climax_sound = pygame.mixer.Sound("SFX/climax.wav") self.victory_sounds = [ pygame.mixer.Sound("SFX/vic{0}.wav".format(i)) for i in range(3) ] self.win_sound = pygame.mixer.Sound("SFX/win.wav") self.reset()