diff --git a/resources/graphics/track1.jpg b/resources/graphics/track1.jpg index d08b12f..fc8ab6c 100644 Binary files a/resources/graphics/track1.jpg and b/resources/graphics/track1.jpg differ diff --git a/resources/graphics/track2.jpg b/resources/graphics/track2.jpg new file mode 100644 index 0000000..a488b71 Binary files /dev/null and b/resources/graphics/track2.jpg differ diff --git a/resources/graphics/track3.jpg b/resources/graphics/track3.jpg new file mode 100644 index 0000000..f10a806 Binary files /dev/null and b/resources/graphics/track3.jpg differ diff --git a/src/main.py b/src/main.py index a3efebb..44bb131 100644 --- a/src/main.py +++ b/src/main.py @@ -57,6 +57,7 @@ def main_no_ui() -> None: while True: sleep(sleep_time) car.tick(track, sleep_time) + car.go_brrrr() def main() -> None: @@ -85,7 +86,12 @@ def main() -> None: "Track2": Action(ActionType.CHANGE_VIEW, 3), "Track3": Action(ActionType.CHANGE_VIEW, 4), } - options_menu = OptionsMenu(tracks=track_options) + track_images = [ + pygame.image.load("resources/graphics/track1.jpg"), + pygame.image.load("resources/graphics/track2.jpg"), + pygame.image.load("resources/graphics/track3.jpg") + ] + options_menu = OptionsMenu(tracks=track_options, tracks_thumbnails=track_images) options_menu.background_image = pygame.image.load( "resources/graphics/menu-background.png" ) diff --git a/src/view/colors.py b/src/view/colors.py index e7cfdff..eb53608 100644 --- a/src/view/colors.py +++ b/src/view/colors.py @@ -5,5 +5,6 @@ WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) +ORANGE = (255, 176, 21) BIZARRE_MASKING_PURPLE = (240, 0, 240) LIME = (50, 205, 50) diff --git a/src/view/menu.py b/src/view/menu.py index 4a89f11..28dc0d1 100644 --- a/src/view/menu.py +++ b/src/view/menu.py @@ -12,6 +12,11 @@ class Menu(View): + FONT_COLOR = colors.ORANGE + SELECTED_FONT_COLOR = colors.WHITE + BUTTON_COLOR = colors.WHITE + SELECTED_BUTTON_COLOR = colors.ORANGE + def __init__(self, menu_options: Dict[str, Action]): super().__init__() pygame.font.init() @@ -47,12 +52,25 @@ def draw( ofset_y = int(pos * 1.5 * self.button_dims[1]) shifted_button_rect = self._button_rect.move(0, ofset_y) color = ( - self.button_highlight + self.SELECTED_BUTTON_COLOR if pos == self.selected_item - else self.button_color + else self.BUTTON_COLOR ) + + if pos == self.selected_item: + shifted_button_rect = shifted_button_rect.inflate(20, 20) + else: + pygame.draw.rect(destination, colors.ORANGE, shifted_button_rect, 4) + pygame.draw.rect(destination, color, shifted_button_rect) - label = self.font.render(button, True, self.font_color) + + font_color = ( + self.SELECTED_FONT_COLOR + if pos == self.selected_item + else self.FONT_COLOR + ) + + label = self.font.render(button, True, font_color) destination.blit( label, ( @@ -89,4 +107,4 @@ def _process_events(self, events: List[EventType]) -> bool: self.selected_item = (self.selected_item + 1) % len(self._options) elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: return True - return False + return False \ No newline at end of file diff --git a/src/view/options_menu.py b/src/view/options_menu.py index 56d740a..701f14d 100644 --- a/src/view/options_menu.py +++ b/src/view/options_menu.py @@ -1,4 +1,4 @@ -from typing import List, Optional, Dict, Tuple +from typing import List, Optional, Dict, Tuple, Any from collections import OrderedDict import pygame @@ -13,22 +13,22 @@ class OptionsMenu(View): - def __init__(self, tracks: Dict[str, Action]) -> None: + ARROW_COLOR = colors.ORANGE + FONT_COLOR = colors.WHITE + LOGO_IMAGE = pygame.image.load("resources/graphics/logo.png") + DIVIDER = 0.4 + + def __init__(self, tracks: Dict[str, Action], tracks_thumbnails: List[Any]) -> None: super().__init__() pygame.font.init() self.font = pygame.font.SysFont("Verdana", 30) self.main_font = pygame.font.SysFont("comicsansms", 60) self.selected_item = 0 self._options = OrderedDict(tracks) - self.font_color = colors.WHITE - self.button_highlight = colors.GREEN - self.button_color = colors.LIGHTGRAY self._background: Optional[Tuple[Surface, Tuple[int, int]]] = None self.background_image: Optional[Surface] = None - self.divider = 0.4 self.selected_action: Optional[Action] = None - self.img = pygame.image.load("resources/graphics/track1.jpg") - self.logo_image = pygame.image.load("resources/graphics/logo.png") + self.thumbnails = tracks_thumbnails def draw(self, destination: Surface, events: List[EventType], delta_time: float) -> Optional[Action]: size = destination.get_size() @@ -43,15 +43,16 @@ def draw(self, destination: Surface, events: List[EventType], delta_time: float) destination.blit(*self._logo) mini_track = self._button_rect - thumbnail_image = pygame.transform.scale(self.img, (mini_track.w, mini_track.h)) + thumbnail_image = pygame.transform.scale(self.thumbnails[self.selected_item], (mini_track.w, mini_track.h)) thumbnail = (thumbnail_image, mini_track) destination.blit(*thumbnail) + pygame.draw.rect(destination, colors.WHITE, mini_track, 4) - main_label = self.main_font.render("Select track", True, self.font_color) + main_label = self.main_font.render("Select track", True, self.FONT_COLOR) destination.blit(main_label, (size[0] // 2 - 185, size[1] // 10)) track_label = self.font.render( - list(self._options.keys())[self.selected_item], True, self.font_color + list(self._options.keys())[self.selected_item], True, self.FONT_COLOR ) destination.blit( track_label, @@ -61,42 +62,36 @@ def draw(self, destination: Surface, events: List[EventType], delta_time: float) ), ) - info_label = self.font.render("PRESS ENTER TO START", True, self.font_color) - destination.blit(info_label, (size[0] - 380, size[1] - 40)) - left_arrow_points = ( - (self.ofset_x - size[0] // 20, self.ofset_y + mini_track.h // 2), - (self.ofset_x - 10, self.ofset_y + mini_track.h // 2 - size[0] // 40), - (self.ofset_x - 10, self.ofset_y + mini_track.h // 2 + size[0] // 40), + (self.offset_x - size[0] // 20, self.offset_y + mini_track.h // 2), + (self.offset_x - 10, self.offset_y + mini_track.h // 2 - size[0] // 40), + (self.offset_x - 10, self.offset_y + mini_track.h // 2 + size[0] // 40), ) right_arrow_points = ( - (3 * self.ofset_x + size[0] // 20, self.ofset_y + mini_track.h // 2), - (3 * self.ofset_x + 10, self.ofset_y + mini_track.h // 2 - size[0] // 40), - (3 * self.ofset_x + 10, self.ofset_y + mini_track.h // 2 + size[0] // 40), + (3 * self.offset_x + size[0] // 20, self.offset_y + mini_track.h // 2), + (3 * self.offset_x + 10, self.offset_y + mini_track.h // 2 - size[0] // 40), + (3 * self.offset_x + 10, self.offset_y + mini_track.h // 2 + size[0] // 40), ) if self.selected_item != 0: - pygame.draw.polygon(destination, self.font_color, left_arrow_points) + pygame.draw.polygon(destination, self.ARROW_COLOR, left_arrow_points) if self.selected_item != len(self._options) - 1: - pygame.draw.polygon(destination, self.font_color, right_arrow_points) + pygame.draw.polygon(destination, self.ARROW_COLOR, right_arrow_points) return None def _update_geometry(self, size: Tuple[int, int]) -> None: - self.ofset_y = int(self.divider * size[1]) - self.ofset_x = size[0] // 4 + self.offset_y = int(self.DIVIDER * size[1]) + self.offset_x = size[0] // 4 self.button_dims = size[0] // 2, size[1] // 2 background_shape = Rect((0, 0), size) background_image = pygame.transform.scale(self.background_image, size) self._background = (background_image, background_shape) - self._button_rect = Rect((self.ofset_x, self.ofset_y), self.button_dims) - - if not self.logo_image: - return + self._button_rect = Rect((self.offset_x, self.offset_y), self.button_dims) logo_image = pygame.transform.scale( - self.logo_image, (size[0] // 6, size[1] // 12) + self.LOGO_IMAGE, (size[1] // 3, size[1] // 12) ) logo_shape = Rect((10, 10), (size[0] // 8, size[1] // 8)) self._logo = (logo_image, logo_shape) @@ -107,15 +102,15 @@ def _process_events(self, events: List[EventType]) -> bool: if event.key == pygame.K_LEFT and self.selected_item != 0: self.selected_item = self.selected_item - 1 elif ( - event.key == pygame.K_RIGHT - and self.selected_item != len(self._options) - 1 + event.key == pygame.K_RIGHT + and self.selected_item != len(self._options) - 1 ): self.selected_item = self.selected_item + 1 elif event.key == pygame.K_a and self.selected_item != 0: self.selected_item = self.selected_item - 1 elif ( - event.key == pygame.K_d - and self.selected_item != len(self._options) - 1 + event.key == pygame.K_d + and self.selected_item != len(self._options) - 1 ): self.selected_item = self.selected_item + 1 elif event.key == pygame.K_RETURN: