From 806b8315f773408cd5b76f95f478617c10604cce Mon Sep 17 00:00:00 2001 From: AngelVI13 Date: Sun, 5 May 2019 09:04:33 +0300 Subject: [PATCH] - Changed main UI colors - Added menu background animation - Added media folder to put all UI related images. --- gui/colors.py | 23 ++++++++++++++++----- gui/constants.py | 11 +++++----- gui/gui_app.py | 16 +++++++------- gui/gui_board.py | 6 ++++++ gui/menu_background.py | 46 +++++++++++++++++++++++++++++++++++++++++ media/button.png | Bin 0 -> 1435 bytes media/button.xcf | Bin 0 -> 6522 bytes media/hashtag.xcf | Bin 0 -> 3750 bytes media/hashtag_1.png | Bin 0 -> 852 bytes 9 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 gui/menu_background.py create mode 100644 media/button.png create mode 100644 media/button.xcf create mode 100644 media/hashtag.xcf create mode 100644 media/hashtag_1.png diff --git a/gui/colors.py b/gui/colors.py index 5bc7f37..64dea3d 100644 --- a/gui/colors.py +++ b/gui/colors.py @@ -1,15 +1,28 @@ # colors.py # Contains color definitions in the form of tuples (length 3 -> RGB representation) +# blue - 3b d6 ff +# blue highlight - 31 b0 d1 +# red - ff 10 53 +# red highlight - d1 0E 44 +# grey - 7b 81 89 + BLACK = (0, 0, 0) WHITE = (255, 255, 255) -RED = (255, 94, 88) -RED_HIGHLIGHT = (255, 219, 212) +# RED = (255, 94, 88) +RED = (0xff, 0x10, 0x53) +# RED_HIGHLIGHT = (255, 219, 212) +RED_HIGHLIGHT = (0xd1, 0x0e, 0x44) GREEN = (0, 200, 0) GREEN_HIGHLIGHT = (0, 255, 0) -BLUE = (59, 214, 255) -BLUE_HIGHLIGHT = (164, 217, 221) -GREY = (170, 191, 193) +PURPLE = (0x6c, 0x6e, 0xA0) +PURPLE_HIGHLIGHT = (0x59, 0x5b, 0x83) +# BLUE = (59, 214, 255) +BLUE = (0x3b, 0xd6, 0xff) +# BLUE_HIGHLIGHT = (164, 217, 221) +BLUE_HIGHLIGHT = (0x31, 0xb0, 0xd1) +# GREY = (170, 191, 193) +GREY = (0x7b, 0x81, 0x89) YELLOW = (0, 250, 250) HIGHLIGHT_LOW = 140 HIGHLIGHT_HIGH = 200 diff --git a/gui/constants.py b/gui/constants.py index 69ee5f6..e4b8dda 100644 --- a/gui/constants.py +++ b/gui/constants.py @@ -50,13 +50,13 @@ class GameType(Enum): BUTTON_WIDTH, BUTTON_HEIGHT = 300, 50 BUTTON_Y_SPACING = 1.5 -MENU_BUTTON_POSITIONS = { +MENU_BUTTON_PROPERTIES = { 0: {'x': (DISPLAY_WIDTH-BUTTON_WIDTH) / 2, 'y': (DISPLAY_HEIGHT / 3) + 1*BUTTON_HEIGHT*BUTTON_Y_SPACING, - 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': GREEN, 'ac': GREEN_HIGHLIGHT}, + 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': PURPLE, 'ac': PURPLE_HIGHLIGHT}, 1: {'x': (DISPLAY_WIDTH-BUTTON_WIDTH) / 2, 'y': (DISPLAY_HEIGHT / 3) + 2*BUTTON_HEIGHT*BUTTON_Y_SPACING, - 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': GREEN, 'ac': GREEN_HIGHLIGHT}, + 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': PURPLE, 'ac': PURPLE_HIGHLIGHT}, 2: {'x': (DISPLAY_WIDTH-BUTTON_WIDTH) / 2, 'y': (DISPLAY_HEIGHT / 3) + 3*BUTTON_HEIGHT*BUTTON_Y_SPACING, - 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': GREEN, 'ac': GREEN_HIGHLIGHT}, + 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': PURPLE, 'ac': PURPLE_HIGHLIGHT}, 3: {'x': (DISPLAY_WIDTH-BUTTON_WIDTH) / 2, 'y': (DISPLAY_HEIGHT / 3) + 4*BUTTON_HEIGHT*BUTTON_Y_SPACING, 'w': BUTTON_WIDTH, 'h': BUTTON_HEIGHT, 'ic': RED, 'ac': RED_HIGHLIGHT}, } @@ -103,7 +103,8 @@ class GameType(Enum): 'w': MAIN_BOX_WIDTH, 'h': MAIN_BOX_HEIGHT}, ] -FRAMES_PER_SECOND = 60 +GAME_FRAMES_PER_SECOND = 60 +MENU_FRAMES_PER_SECOND = 30 # after entering game loop pause for some time before allowing the user to click # fixes issues with accidental clicks PAUSE_BEFORE_USER_INPUT = 1 diff --git a/gui/gui_app.py b/gui/gui_app.py index 2c48d18..026855e 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -104,12 +104,11 @@ def do_nothing(self): def get_game_input(self, game_type, mouse_pos): if game_type == GameType.SINGLE_PLAYER: + # self.click_random_cell() used for debugginh if self.board.playerJustMoved == PLAYER_O: # X's turn todo allow user to select side to play - # self.click_random_cell() todo used to testing if mouse_pos is not None: self.click_cell_under_mouse(mouse_pos) else: - # self.click_random_cell() # todo replace with AI board, move = self.get_best_engine_move() for cell in self.allowed_cells: if cell.board_idx == board and cell.cell_idx == move: @@ -160,7 +159,7 @@ def game_loop(self, game_type): self.draw_side_to_move(-self.board.playerJustMoved) pygame.display.update() - self.clock.tick(FRAMES_PER_SECOND) + self.clock.tick(GAME_FRAMES_PER_SECOND) def menu_loop(self): while True: @@ -169,18 +168,19 @@ def menu_loop(self): self.quit_game() self.gameDisplay.fill(WHITE) + self.draw_menu_animation() self.message_display("Ultimate Tic Tac Toe", pos=(DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 3), font='comicsansms', size=40, update=False) - self.button("Single Player", **MENU_BUTTON_POSITIONS[0], + self.button("Single Player", **MENU_BUTTON_PROPERTIES[0], action=partial(self.game_loop, GameType.SINGLE_PLAYER)) - self.button("Two Player", **MENU_BUTTON_POSITIONS[1], + self.button("Two Player", **MENU_BUTTON_PROPERTIES[1], action=partial(self.game_loop, GameType.MULTI_PLAYER)) - self.button("Settings", **MENU_BUTTON_POSITIONS[2], action=self.do_nothing) - self.button("Quit", **MENU_BUTTON_POSITIONS[3], action=self.quit_game) + self.button("Settings", **MENU_BUTTON_PROPERTIES[2], action=self.do_nothing) + self.button("Quit", **MENU_BUTTON_PROPERTIES[3], action=self.quit_game) pygame.display.update() - self.clock.tick(15) + self.clock.tick(MENU_FRAMES_PER_SECOND) if __name__ == '__main__': diff --git a/gui/gui_board.py b/gui/gui_board.py index 00da08f..9a94f06 100644 --- a/gui/gui_board.py +++ b/gui/gui_board.py @@ -3,6 +3,7 @@ import pygame from gui.constants import * from board.ultimate_board import * +from gui.menu_background import Background @total_ordering @@ -48,6 +49,7 @@ def __init__(self): self.gameDisplay = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT)) pygame.display.set_caption('Ultimate Tic Tac Toe') self.clock = pygame.time.Clock() + self.background = Background(self.gameDisplay) @staticmethod def get_text_objects(text, font): @@ -165,3 +167,7 @@ def draw_side_to_move(self, player_to_move): pygame.draw.rect(self.gameDisplay, BLACK, (OFFSET_X+8, OFFSET_Y-22, 24, 14)) pygame.draw.rect(self.gameDisplay, self.colors[player_to_move], (OFFSET_X+10, OFFSET_Y-20, 20, 10)) self.message_display(text=' to move', pos=(OFFSET_X+60, OFFSET_Y-15), font='comicsansms', size=14) + + def draw_menu_animation(self): + self.background.update() + diff --git a/gui/menu_background.py b/gui/menu_background.py new file mode 100644 index 0000000..2152d1a --- /dev/null +++ b/gui/menu_background.py @@ -0,0 +1,46 @@ +import pygame +import random +from gui.constants import * + + +class Animation: + __slots__ = ['img', 'x', 'y', 'x_increment', 'y_increment'] + + def __init__(self, img, x, y, x_increment, y_increment): + self.img = img + self.x = x + self.y = y + self.x_increment = x_increment + self.y_increment = y_increment + + +class Background: + num_animations = 10 + + def __init__(self, game_display): + self.game_display = game_display + x_coords = (random.randrange(0, DISPLAY_WIDTH) for _ in range(self.num_animations)) + y_coords = (random.randrange(0, DISPLAY_HEIGHT) for _ in range(self.num_animations)) + increment_padding = [0] * (self.num_animations//2) + x_increment = [random.randrange(2, 5) for _ in range(self.num_animations // 2)] + x_increment.extend(increment_padding) + y_increment = increment_padding[:] + y_increment.extend([random.randrange(2, 5) for _ in range(self.num_animations // 2)]) + self.animations = [] + for x, y, increment_x, increment_y in zip(x_coords, y_coords, x_increment, y_increment): + hashtag_img = pygame.image.load('../media/hashtag_1.png') + self.animations.append(Animation(img=hashtag_img, x=x, y=y, + x_increment=increment_x, y_increment=increment_y)) + + def update(self): + for idx in range(len(self.animations)): + animation = self.animations[idx] + self.game_display.blit(animation.img, (animation.x, animation.y)) + + self.animations[idx].x += self.animations[idx].x_increment + if self.animations[idx].x > DISPLAY_WIDTH: + self.animations[idx].x = 0 + + self.animations[idx].y += self.animations[idx].y_increment + if self.animations[idx].y > DISPLAY_HEIGHT: + self.animations[idx].y = 0 diff --git a/media/button.png b/media/button.png new file mode 100644 index 0000000000000000000000000000000000000000..9845c8c8ebef85b698bfc4bb661c6c3f1334a45b GIT binary patch literal 1435 zcmV;M1!Ve(P)WFU8GbZ8()Nlj2>E@cM*00jR@L_t(|+U=a(Yg1<& z$3G`cnncsayi!HGHkJ6YmzHj(9h;lruB=4yYO6yAyBLEC`3Jo6TIkI#R`6zEL1bg3 zxG}0T;tMXsifqN&*_uQqeM_b3OOht>?4oU&lea1+YUuNUK%OVR=Y;&e&+q)6-;;BW zB+D{_w+EGQfe=I>1gRd>#Xgu1h2;Cay^Qwv6Pub6o+=Zq9uKV^4;Kdqal75v?RF{q zbE!~L4-O2-m)&mRy$aIh^>Vtek27b^;BvX7qJqqaLh?^dO_{a^umHwV;UsurBCD?? za4Hz2yQhcq=g(&%B`=5E@9oXJuLGQ`f(S9ngJspHby>dldcDPy`e=WDCNdg@|0+f! z@b85S0Qh{q;)1LtaEtI+#i^g324HS(ZsTRIQTVIk7+Pd&6wTJuP#@ny={J;Z?9i}q2v5`_%I84{Y(EYLoCL3SFcu&AW^NB%kAwv zwd8Nc#B@4hIvo=x6Mlz-_E3n=hli;V5mGrZ`VSstQKwt!kYx^xjnNtmvNe%lx~`6! z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LF)=oE|C!v({^?=RGtg8c3k4{E=9?oGlOzN`UR1NHhV!FCw=!zq^cz+DV)EZQJa!xh#4HjHd z95r9jZME#`mMI&qO?Efd9&PB@)a1zFsha`H=JAH(>eZHPs8yG`OI9;qw<;<o!BTsdm`D07?ixlSja0eglSf|!;Z~L{m|N1@*ko?ycOyv!_Ii!q}y3I zIUC2#h<%&~S3u|s?06}3JPjSJeplpjHiU@Sn-!6_;*G+(94Gt(gmdAY!sL)1+z5%|jJ=9dpUjR}b0c{u6WW70 zh!i-qlhT@WX{(;1z1^y(C=*-twDo?%8|MG>e!3K-0{=NW@B9ydR>(Q8a~%-xGq3wk zz)8HSj}r3!-hsE=F~HwDz&?fXPhkHH&;^`-7l2svL!eb?W`6@@%^uc#0Ms>e!zY6vR{$89bw?H(n z37szx53hX@YrhNbe4L{-teyD<AKbf*2dH;uwMoG7@BVZ zy$tR>py#2P`T=kenweh#`47mUARYL3LXy?Jen{3a{0+>X0Qy{_qmu(0h(m0TD8x5l z@gi(RQpugG;7(!X^v{6vSma(pp1%uAj{(x=6RTnTOPF(9pCX#q!My~I<9Y$yci>J# zGW8=MpRD&FnB7nuCeFLw3&kpizlOC1^ck#Q19}DAn?UEleGBv$D}E1Hgz?=_qyt#; z4-)5H@8h$V{>~*o+O{88%4ap(YMA^j^U+eiOh}u7O&{2T^ literal 0 HcmV?d00001 diff --git a/media/hashtag_1.png b/media/hashtag_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3adaaf3582c5f1507860455246d1373253cbc59d GIT binary patch literal 852 zcmV-a1FQUrP)WFU8GbZ8()Nlj2>E@cM*00Ov4L_t(&-tCyVZt74F zhUburP!J-aNEHOK06{S1QPLn%A{rW=fHD*mv^+oxpn}&(Ne7rkEI~n(fW*F-xgEJS zv9SgCa3h~?tdZr%|IHB25vT+@0S}4;P?9_|8Bir$L)5z zw@oG!xLhtm9pv8>0RV8j-Eez*E9qY@mj$-Z=L4hBNIxRt4?C77YW+0<*>1N`uh&)S zLyev^18KEdxLU0g>!Vhy3G`t!8o}f75b7W_^>J2^N~Jo)_rD>-CaTzJVMYtm5%FetmsW@1@?~-{Ilmf#}_@4x;fPr!F6g z#Uf_2*}cs$3}iAH$z0Cma#$!7_V)AhGo(@}LOmkl`f=LB7a{PFP-Y&IJ!(Bv0SzwUQ45x&*$IdE)Tue(m}4ZX-ucn`0??vw_jdfAQp>B-ayG@5=*7h-afVu z)+{1w3gJ)l{HgQ#SwQ;zK90v@abbIv^6zvy2lG73vV=N_xPCaDPOw_7MWy~OmrHiv zMGfTGK1%JrOEVBP`ar~kM)4{@`u#qRMkBF4B-5(f?c!`U`@SLxk==J`1|m)?yWI}= z_xG=A^kFue=|@CuzH6nAi-P>5k4w}K)gXhx0Efe&;=!ob>)~WF5$NL*_2Z-#MQ<8) e5FO