| 33 | |
| 34 | |
| 35 | class Menu: |
| 36 | def __init__(self): |
| 37 | self.text_list = [] |
| 38 | self.selected = 1 |
| 39 | |
| 40 | def text(self): |
| 41 | # Text on the main menu |
| 42 | text_list = ["Main Menu", "Start", "Exit"] |
| 43 | # Size for the text |
| 44 | size_list = [70, 40, 40] |
| 45 | |
| 46 | # Create text class and append to list |
| 47 | self.text_list = [ |
| 48 | Text(text_list[i], size_list[i]) for i in range(len(text_list)) |
| 49 | ] |
| 50 | # Select the first option |
| 51 | self.text_list[1].selected = True |
| 52 | |
| 53 | def controls(self, event: pygame.event): |
| 54 | if event.type == pygame.KEYDOWN: |
| 55 | if event.key == pygame.K_w or event.key == pygame.K_UP: |
| 56 | self.select(1) |
| 57 | if event.key == pygame.K_s or event.key == pygame.K_DOWN: |
| 58 | self.select(2) |
| 59 | |
| 60 | def select(self, code: int): |
| 61 | # Go down the list |
| 62 | if code == 1: |
| 63 | if self.selected == 1: |
| 64 | self.selected = 2 |
| 65 | self.text_list[1].selected = False |
| 66 | else: |
| 67 | self.selected -= 1 |
| 68 | self.text_list[self.selected + 1].selected = False |
| 69 | |
| 70 | # Go up the list |
| 71 | if code == 2: |
| 72 | if self.selected == 2: |
| 73 | self.selected = 1 |
| 74 | self.text_list[2].selected = False |
| 75 | else: |
| 76 | self.selected += 1 |
| 77 | self.text_list[self.selected - 1].selected = False |
| 78 | |
| 79 | self.text_list[self.selected].selected = True |
| 80 | |
| 81 | def buttons_function(self, event: pygame.event): |
| 82 | if event.type == pygame.KEYDOWN: |
| 83 | if event.key == pygame.K_RETURN: |
| 84 | # Start button |
| 85 | if self.selected == 1: |
| 86 | Start().execute() |
| 87 | # Exit button |
| 88 | if self.selected == 2: |
| 89 | exit() |
| 90 | |
| 91 | def objects(self): |
| 92 | spacing = 50 |