diff --git a/InfoProjekt.xlsx b/.idea/InfoProjekt.xlsx similarity index 100% rename from InfoProjekt.xlsx rename to .idea/InfoProjekt.xlsx diff --git a/ideas.txt b/.idea/ideas.txt similarity index 100% rename from ideas.txt rename to .idea/ideas.txt diff --git a/storyline.txt b/.idea/storyline.txt similarity index 100% rename from storyline.txt rename to .idea/storyline.txt diff --git a/art/exit.png b/art/image files/exit.png similarity index 100% rename from art/exit.png rename to art/image files/exit.png diff --git a/art/image files/field.kra b/art/image files/field.kra new file mode 100644 index 0000000..f99eaf6 Binary files /dev/null and b/art/image files/field.kra differ diff --git a/art/image files/field.png b/art/image files/field.png new file mode 100644 index 0000000..008cb35 Binary files /dev/null and b/art/image files/field.png differ diff --git a/art/mauer.png b/art/image files/mauer.png similarity index 100% rename from art/mauer.png rename to art/image files/mauer.png diff --git a/art/mauer_down-left.png b/art/image files/mauer_down-left.png similarity index 100% rename from art/mauer_down-left.png rename to art/image files/mauer_down-left.png diff --git a/art/mauer_down-right.png b/art/image files/mauer_down-right.png similarity index 100% rename from art/mauer_down-right.png rename to art/image files/mauer_down-right.png diff --git a/art/mauer_down.png b/art/image files/mauer_down.png similarity index 100% rename from art/mauer_down.png rename to art/image files/mauer_down.png diff --git a/art/mauer_left.png b/art/image files/mauer_left.png similarity index 100% rename from art/mauer_left.png rename to art/image files/mauer_left.png diff --git a/art/mauer_right.png b/art/image files/mauer_right.png similarity index 100% rename from art/mauer_right.png rename to art/image files/mauer_right.png diff --git a/art/mauer_top-left.png b/art/image files/mauer_top-left.png similarity index 100% rename from art/mauer_top-left.png rename to art/image files/mauer_top-left.png diff --git a/art/mauer_top-right.png b/art/image files/mauer_top-right.png similarity index 100% rename from art/mauer_top-right.png rename to art/image files/mauer_top-right.png diff --git a/art/mauer_top.png b/art/image files/mauer_top.png similarity index 100% rename from art/mauer_top.png rename to art/image files/mauer_top.png diff --git a/art/new_game.png b/art/image files/new_game.png similarity index 100% rename from art/new_game.png rename to art/image files/new_game.png diff --git a/art/options.png b/art/image files/options.png similarity index 100% rename from art/options.png rename to art/image files/options.png diff --git a/art/set1.png b/art/image files/set1.png similarity index 100% rename from art/set1.png rename to art/image files/set1.png diff --git a/art/textbox.png b/art/image files/textbox.png similarity index 100% rename from art/textbox.png rename to art/image files/textbox.png diff --git a/classes.py b/classes.py index fba9775..8231fcd 100644 --- a/classes.py +++ b/classes.py @@ -34,8 +34,8 @@ fonts = { } class Button(): - def __init__(self, x, y, width, height, font, buttonText='Button', onclickFunction=None, onePress=False): - font = pygame.font.Font(f'fonts/{fonts[font]}', 48) + def __init__(self, x, y, width, height, font, font_size, buttonText='Button', onclickFunction=None, onePress=False): + self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) self.x = x self.y = y self.width = width @@ -51,14 +51,12 @@ class Button(): self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height) - self.buttonSurf = font.render(buttonText, True, '#baab80') + self.buttonSurf = self.font.render(buttonText, True, '#baab80') def process(self, screen): mousePos = pygame.mouse.get_pos() if self.buttonRect.collidepoint(mousePos): - #self.buttonSurface.fill(self.fillColors['hover']) if pygame.mouse.get_pressed(num_buttons=3)[0]: - #self.buttonSurface.fill(self.fillColors['pressed']) if self.onePress: self.onclickFunction() elif not self.alreadyPressed: @@ -70,4 +68,69 @@ class Button(): self.buttonRect.width/2 - self.buttonSurf.get_rect().width/2, self.buttonRect.height/2 - self.buttonSurf.get_rect().height/2 ]) - screen.blit(self.box, self.buttonRect) \ No newline at end of file + screen.blit(self.box, self.buttonRect) + + +class DropDown(): + def __init__(self, x, y, width, height, font, font_size, color_menu, color_option, main, options): + self.rect = pygame.Rect(x, y, width, height) + self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) + self.main = main + self.options = options + self.draw_menu = False + self.menu_active = False + self.active_option = -1 + + with open('art/textbox.png', 'r') as tb: + self.box = pygame.image.load(tb) + self.box = pygame.transform.scale(self.box, (width, height)) + + def draw(self, screen): + #pygame.draw.rect(screen, self.color_menu[self.menu_active], self.rect, 0) + surface = self.font.render(self.main, 1, (0, 0, 0)) + self.box.blit(surface, [ + self.rect.width/2 - surface.get_rect().width/2, + self.rect.height/2 - surface.get_rect().height/2 + ]) + screen.blit(self.box, surface.get_rect(center = self.rect.center)) + + if self.draw_menu: + for i, text in enumerate(self.options): + rect = self.rect.copy() + rect.y += (i+1) * self.rect.height + rect.x = self.rect.x + #pygame.draw.rect(screen, self.color_option[1 if i == self.active_option else 0], rect, 0) + #msg = self.font.render(text, 1, (0, 0, 0)) + #screen.blit(msg, msg.get_rect(center = rect.center)) + surface = self.font.render(text, 1, (0, 0, 0)) + self.box.blit(surface, [ + rect.width/2 - surface.get_rect().width/2, + rect.height/2 - surface.get_rect().height/2 + ]) + screen.blit(self.box, rect) + + def update(self, event_list): + mpos = pygame.mouse.get_pos() + self.menu_active = self.rect.collidepoint(mpos) + self.active_option = -1 + for i in range(len(self.options)): + rect = self.rect.copy() + rect.y += (i+1) * self.rect.height + if rect.collidepoint(mpos): + self.active_option = i + break + + if not self.menu_active and self.active_option == -1: + self.draw_menu = False + #self.draw_menu = True + #return -1 + if pygame.mouse.get_pressed(num_buttons=3)[0]: + if self.menu_active: + self.draw_menu = not self.draw_menu + elif self.draw_menu and self.active_option >= 0: + self.draw_menu = False + return self.active_option + return -1 + + + diff --git a/main.py b/main.py index d68cad2..e7a7046 100644 --- a/main.py +++ b/main.py @@ -27,20 +27,77 @@ def quitGame(): def uwu(): print('uwu') -def main(): - config = readConfig() - screen, clock, running, isblack, background, objects = setUp(config["screen"]) - WIDTH, HEIGHT = screen.get_size() - objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', "Exit game", quitGame)) - objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', "Options", uwu)) - objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', "Play", uwu)) - print(objects) +def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): + objects = [] + # List that is displayed while selecting the window resolution level + resolution = [("1920x1080", "1920x1080"), + ("1920x1200", "1920x1200"), + ("1280x720", "1280x720"), + ("2560x1440", "2560x1440"), + ("3840x2160", "3840x2160")] + + # This function displays the currently selected options + + def printSettings(): + print("\n\n") + # getting the data using "get_input_data" method of the Menu class + settingsData = settings.get_input_data() + + for key in settingsData.keys(): + print(f"{key}\t:\t{settingsData[key]}") while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False - + # RENDER YOUR GAME HERE + with open(background, 'r') as i: + bg = pygame.image.load(i) + bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) + # fill the screen with an image to clear the screen + screen.blit(bg, (0, 0)) + for obj in objects: + obj.process(screen) + + # flip() the display to put your work on screen + pygame.display.flip() + + clock.tick(60) # limits FPS to 60 + +def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): + objects = [] + objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) + objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu)) + objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", uwu)) + while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + # RENDER YOUR GAME HERE + with open(background, 'r') as i: + bg = pygame.image.load(i) + bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) + # fill the screen with an image to clear the screen + screen.blit(bg, (0, 0)) + for obj in objects: + obj.process(screen) + + # flip() the display to put your work on screen + pygame.display.flip() + + clock.tick(60) # limits FPS to 60 + +def main(): + config = readConfig() + screen, clock, running, isblack, background, objects = setUp(config["screen"]) + WIDTH, HEIGHT = screen.get_size() + list1 = DropDown(50, 50, 128, 48, 'simple', 32, ['#881188', '#220044'], ['#991122', '#33ff11'], 'Test', ['Test 2', 'Test 17', '982']) + + while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + #menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) if not isblack: with open(background, 'r') as i: bg = pygame.image.load(i) @@ -51,7 +108,11 @@ def main(): # RENDER YOUR GAME HERE else: + selected_option = list1.update(pygame.event.get()) + if selected_option >= 0: + list1.main = list1.options[selected_option] screen.fill('#000000') + list1.draw(screen) for obj in objects: obj.process(screen) # flip() the display to put your work on screen