diff --git a/README.md b/README.md index 3910205..3e9eb02 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,6 @@ Both game modes include: - Add the CPU - animations -- highlight the last dropped tile for the ppl who arent paying attention \ No newline at end of file + + +(Cement-4, PyConnect-4 + Dementris where you forget the tiles lmao) diff --git a/gui/button.py b/gui/button.py index 89f06dc..682f4c4 100644 --- a/gui/button.py +++ b/gui/button.py @@ -2,9 +2,10 @@ import pygame from pathlib import Path class Button: - def __init__(self, x, y, width, height, text, colour, hover_colour, text_colour, action, font, font_size, extra_data=None, rounding=0, outline_colour=None, outline_width=0, hover_action = None): + def __init__(self, x, y, width, height, text, colour, hover_colour, text_colour, action, font, font_size, extra_data=None, rounding=0, outline_colour=None, outline_width=0, hover_action=None, img=None): self.rect = pygame.Rect(x, y, width, height) self.text = text + self.img = img self.colour = colour self.hover_colour = hover_colour self.text_colour = text_colour @@ -36,6 +37,9 @@ class Button: text_rect = text_surface.get_rect(center=self.rect.center) screen.blit(text_surface, text_rect) + if self.img: + screen.blit(self.img, self.rect) + def update_colour(self): if self.rect.collidepoint(pygame.mouse.get_pos()): self.current_colour = self.hover_colour diff --git a/gui/gui_game.py b/gui/gui_game.py index f066c97..b5bc77e 100644 --- a/gui/gui_game.py +++ b/gui/gui_game.py @@ -37,6 +37,7 @@ tile_colour = (200, 200, 200) tile_hover = (170, 170, 170) tile_text = (50, 50, 50) bg_colour = (30, 30, 40) +win_outline_colour = (0, 255, 0) red_tile = (255, 0, 0) red_tile_hover = (220, 0, 0) @@ -52,6 +53,8 @@ winner = None # cursor state cursor_col = COLS // 2 +last_tile = None + # repeat cursor move key_held = None key_held_time = 0 @@ -95,8 +98,7 @@ def drop_tile(col_index): target_tile.colour = yellow_tile target_tile.hover_colour = yellow_tile_hover return r - return None - + def check_win(): global tiles, player @@ -129,7 +131,7 @@ def is_board_full(): # drop a tile in a column def play_move(col_index: int): - global board_full, winner, player + global board_full, winner, player, last_tile if board_full or not tiles: return @@ -137,12 +139,16 @@ def play_move(col_index: int): if row_dropped is None: return + if last_tile: + tiles[last_tile[0]][last_tile[1]].img = None + last_tile = (col_index, row_dropped) + wins = check_win() if wins: winner = player for winX, winY in wins: tiles[winX][winY].outline_width = 5 - tiles[winX][winY].outline_colour = (0, 255, 0) + tiles[winX][winY].outline_colour = win_outline_colour board_full = True elif is_board_full(): winner = None @@ -211,8 +217,7 @@ def lowest_empty_row(c: int): for r in reversed(range(ROWS)): if tiles[c][r].colour == tile_colour: return r - return None - + # ghost preview tile def draw_ghost_piece(display): if not tiles or GRID_ORIGIN_X is None: @@ -273,6 +278,10 @@ def draw_game(display): draw_cursor(display) draw_ghost_piece(display) + if last_tile: + img = pygame.image.load(str(ROOT_PATH / "star.png")) + tiles[last_tile[0]][last_tile[1]].img = img + # menu manager init menu_manager = MenuManager(display, bg_colour) diff --git a/gui/star.png b/gui/star.png new file mode 100644 index 0000000..a7d7f28 Binary files /dev/null and b/gui/star.png differ