lil star icon for the last dropped tile
This commit is contained in:
parent
41cecfc5ee
commit
b4e5e6a5b1
|
|
@ -38,4 +38,6 @@ Both game modes include:
|
||||||
|
|
||||||
- Add the CPU
|
- Add the CPU
|
||||||
- animations
|
- animations
|
||||||
- highlight the last dropped tile for the ppl who arent paying attention
|
|
||||||
|
|
||||||
|
(Cement-4, PyConnect-4 + Dementris where you forget the tiles lmao)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import pygame
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
class Button:
|
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.rect = pygame.Rect(x, y, width, height)
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.img = img
|
||||||
self.colour = colour
|
self.colour = colour
|
||||||
self.hover_colour = hover_colour
|
self.hover_colour = hover_colour
|
||||||
self.text_colour = text_colour
|
self.text_colour = text_colour
|
||||||
|
|
@ -36,6 +37,9 @@ class Button:
|
||||||
text_rect = text_surface.get_rect(center=self.rect.center)
|
text_rect = text_surface.get_rect(center=self.rect.center)
|
||||||
screen.blit(text_surface, text_rect)
|
screen.blit(text_surface, text_rect)
|
||||||
|
|
||||||
|
if self.img:
|
||||||
|
screen.blit(self.img, self.rect)
|
||||||
|
|
||||||
def update_colour(self):
|
def update_colour(self):
|
||||||
if self.rect.collidepoint(pygame.mouse.get_pos()):
|
if self.rect.collidepoint(pygame.mouse.get_pos()):
|
||||||
self.current_colour = self.hover_colour
|
self.current_colour = self.hover_colour
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ tile_colour = (200, 200, 200)
|
||||||
tile_hover = (170, 170, 170)
|
tile_hover = (170, 170, 170)
|
||||||
tile_text = (50, 50, 50)
|
tile_text = (50, 50, 50)
|
||||||
bg_colour = (30, 30, 40)
|
bg_colour = (30, 30, 40)
|
||||||
|
win_outline_colour = (0, 255, 0)
|
||||||
|
|
||||||
red_tile = (255, 0, 0)
|
red_tile = (255, 0, 0)
|
||||||
red_tile_hover = (220, 0, 0)
|
red_tile_hover = (220, 0, 0)
|
||||||
|
|
@ -52,6 +53,8 @@ winner = None
|
||||||
# cursor state
|
# cursor state
|
||||||
cursor_col = COLS // 2
|
cursor_col = COLS // 2
|
||||||
|
|
||||||
|
last_tile = None
|
||||||
|
|
||||||
# repeat cursor move
|
# repeat cursor move
|
||||||
key_held = None
|
key_held = None
|
||||||
key_held_time = 0
|
key_held_time = 0
|
||||||
|
|
@ -95,7 +98,6 @@ def drop_tile(col_index):
|
||||||
target_tile.colour = yellow_tile
|
target_tile.colour = yellow_tile
|
||||||
target_tile.hover_colour = yellow_tile_hover
|
target_tile.hover_colour = yellow_tile_hover
|
||||||
return r
|
return r
|
||||||
return None
|
|
||||||
|
|
||||||
def check_win():
|
def check_win():
|
||||||
global tiles, player
|
global tiles, player
|
||||||
|
|
@ -129,7 +131,7 @@ def is_board_full():
|
||||||
|
|
||||||
# drop a tile in a column
|
# drop a tile in a column
|
||||||
def play_move(col_index: int):
|
def play_move(col_index: int):
|
||||||
global board_full, winner, player
|
global board_full, winner, player, last_tile
|
||||||
if board_full or not tiles:
|
if board_full or not tiles:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -137,12 +139,16 @@ def play_move(col_index: int):
|
||||||
if row_dropped is None:
|
if row_dropped is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if last_tile:
|
||||||
|
tiles[last_tile[0]][last_tile[1]].img = None
|
||||||
|
last_tile = (col_index, row_dropped)
|
||||||
|
|
||||||
wins = check_win()
|
wins = check_win()
|
||||||
if wins:
|
if wins:
|
||||||
winner = player
|
winner = player
|
||||||
for winX, winY in wins:
|
for winX, winY in wins:
|
||||||
tiles[winX][winY].outline_width = 5
|
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
|
board_full = True
|
||||||
elif is_board_full():
|
elif is_board_full():
|
||||||
winner = None
|
winner = None
|
||||||
|
|
@ -211,7 +217,6 @@ def lowest_empty_row(c: int):
|
||||||
for r in reversed(range(ROWS)):
|
for r in reversed(range(ROWS)):
|
||||||
if tiles[c][r].colour == tile_colour:
|
if tiles[c][r].colour == tile_colour:
|
||||||
return r
|
return r
|
||||||
return None
|
|
||||||
|
|
||||||
# ghost preview tile
|
# ghost preview tile
|
||||||
def draw_ghost_piece(display):
|
def draw_ghost_piece(display):
|
||||||
|
|
@ -273,6 +278,10 @@ def draw_game(display):
|
||||||
draw_cursor(display)
|
draw_cursor(display)
|
||||||
draw_ghost_piece(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 init
|
||||||
menu_manager = MenuManager(display, bg_colour)
|
menu_manager = MenuManager(display, bg_colour)
|
||||||
|
|
||||||
|
|
|
||||||
BIN
gui/star.png
Normal file
BIN
gui/star.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue
Block a user