Skip to content

Commit

Permalink
Added display scaling option
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel Iliev committed Feb 14, 2020
1 parent 37b3266 commit 3f889c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from gui.gui_app import Gui


if __name__ == '__main__':
g = Gui()
g.menu_loop()
20 changes: 10 additions & 10 deletions gui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from gui.colors import *
from board.constants import PLAYER_X, PLAYER_O, DRAW


DISPLAY_WIDTH = 600
DISPLAY_HEIGHT = 600
BOARD_WIDTH = 480
BOARD_HEIGHT = 480
DISPLAY_SCALING = 3
DISPLAY_WIDTH = 600 * DISPLAY_SCALING
DISPLAY_HEIGHT = 600 * DISPLAY_SCALING
BOARD_WIDTH = 480 * DISPLAY_SCALING
BOARD_HEIGHT = 480 * DISPLAY_SCALING

# noinspection PyTypeChecker
# Create an enum of values starting from 0
Expand Down Expand Up @@ -48,7 +48,7 @@ class GameType(Enum):
OFFSET_X, OFFSET_Y = (DISPLAY_WIDTH - BOARD_WIDTH) / 2, (DISPLAY_HEIGHT - BOARD_HEIGHT) / 2

# Menu buttons
BUTTON_WIDTH, BUTTON_HEIGHT = 300, 50
BUTTON_WIDTH, BUTTON_HEIGHT = 300 * DISPLAY_SCALING, 50 * DISPLAY_SCALING
BUTTON_Y_SPACING = 1.5
BUTTON_X_SPACING = 0.5

Expand Down Expand Up @@ -105,16 +105,16 @@ class GameType(Enum):
'w': MAIN_BOX_WIDTH, 'h': MAIN_BOX_HEIGHT},
]

GAME_FRAMES_PER_SECOND = 60
GAME_FRAMES_PER_SECOND = 30
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

COLOR_BOX_SIZE = 20
COLOR_BOX_BORDER_THICKNESS = 2
COLOR_BOX_SIZE = 20 * DISPLAY_SCALING
COLOR_BOX_BORDER_THICKNESS = 2 * DISPLAY_SCALING

OVERLAY_W, OVERLAY_H = 140, 80
OVERLAY_W, OVERLAY_H = 140 * DISPLAY_SCALING, 80 * DISPLAY_SCALING
RESULT_OVERLAY = {
'x': DISPLAY_WIDTH / 2 - OVERLAY_W / 2,
'y': DISPLAY_HEIGHT / 2 - OVERLAY_H / 2,
Expand Down
4 changes: 2 additions & 2 deletions gui/gui_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def message_display(self, text, pos=None, font='freesansbold.ttf', size=60, upda
else:
pos_x, pos_y = pos

large_text = pygame.font.SysFont(font, size)
large_text = pygame.font.SysFont(font, size * DISPLAY_SCALING)
text_surf, text_rect = self.get_text_objects(text, large_text)
text_rect.center = (pos_x, pos_y)
self.gameDisplay.blit(text_surf, text_rect)
Expand All @@ -88,7 +88,7 @@ def button(self, msg, x, y, w, h, ic, ac, action=None):
else:
pygame.draw.rect(self.gameDisplay, ic, (x, y, w, h))

small_text = pygame.font.SysFont("comicsansms", 20)
small_text = pygame.font.SysFont("comicsansms", 20 * DISPLAY_SCALING)
text_surf, text_rect = self.get_text_objects(msg, small_text)
text_rect.center = ((x + (w / 2)), (y + (h / 2)))
self.gameDisplay.blit(text_surf, text_rect)
Expand Down
2 changes: 1 addition & 1 deletion gui/menu_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, game_display):
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')
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))

Expand Down

0 comments on commit 3f889c7

Please sign in to comment.