From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sat, 26 Nov 2022 04:30:43 +0000 (-0500) Subject: confirmation screen + status in main X-Git-Url: http://git.skullheadx.com/projects/dotfiles.html?a=commitdiff_plain;h=7bc76a884f3e7ff657b56504259a627d2f6ff2a2;p=word-hunt.git confirmation screen + status in main need to make buttons --- diff --git a/Main/Button.py b/Main/Button.py new file mode 100644 index 0000000..aecb1b3 --- /dev/null +++ b/Main/Button.py @@ -0,0 +1,45 @@ +import pygame.mouse + +from setup import * + + +class Button: + font = pygame.font.Font("font/Silkscreen-Regular.ttf", 20) + + edge_radius = 5 + bezel = 3 + + inset = 5 + + cooldown_time = 250 + + def __init__(self, position, text, colour): + self.colour = colour + self.text = self.font.render(text,True, self.colour) + self.position = position + self.selected = False + + self.width = self.text.get_width() + self.inset * 2 + self.height = self.text.get_height() + + self.time = 0 + self.cooldown = 0 + + def update(self, delta, new_text=None): + if new_text is not None: + self.text = self.font.render(new_text, True, self.colour) + self.cooldown = max(self.cooldown - delta, 0) + if self.cooldown == 0: + if pygame.mouse.get_pressed(3)[0] and self.get_rect().collidepoint(pygame.mouse.get_pos()): + self.selected = True + self.cooldown = self.cooldown_time + else: + self.selected = False + + def get_rect(self): + return pygame.Rect(self.position.x - self.width/2,self.position.y - self.height/2, self.width,self.height) + + def draw(self,surf): + pygame.draw.rect(surf,Colour.LIGHT_GRAY,self.get_rect(),border_radius=self.edge_radius) + pygame.draw.rect(surf,Colour.DARK_GRAY,self.get_rect(),border_radius=self.edge_radius,width=self.bezel) + surf.blit(self.text,self.text.get_rect(center=self.position)) \ No newline at end of file diff --git a/Main/__pycache__/game.cpython-310.pyc b/Main/__pycache__/game.cpython-310.pyc index 8274f66..3826855 100644 Binary files a/Main/__pycache__/game.cpython-310.pyc and b/Main/__pycache__/game.cpython-310.pyc differ diff --git a/Main/__pycache__/setup.cpython-310.pyc b/Main/__pycache__/setup.cpython-310.pyc index 524abc3..f980017 100644 Binary files a/Main/__pycache__/setup.cpython-310.pyc and b/Main/__pycache__/setup.cpython-310.pyc differ diff --git a/Main/confirmation.py b/Main/confirmation.py new file mode 100644 index 0000000..8291492 --- /dev/null +++ b/Main/confirmation.py @@ -0,0 +1,41 @@ +from setup import * +from button import Button + + +class Confirmation: + font = pygame.font.Font("font/Silkscreen-Regular.ttf", 25) + edge_radius = 10 + bezel = 4 + separation_distance = 10 + inset = 15 + + def __init__(self): + self.position = center.copy() + self.text = self.font.render("Show Solutions?",True,Colour.BLACK) + self.accept_button = Button(self.position, "Accept",Colour.BLACK) + self.deny_button = Button(self.position, "Cancel",Colour.BLACK) + self.width = self.inset * 2 + self.accept_button.get_rect().width + self.deny_button.get_rect().width + self.separation_distance + self.height = self.inset * 2 + self.accept_button.get_rect().height + self.text.get_rect().height + self.separation_distance + + + def update(self, delta): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return COMMAND_EXIT + + + if self.accept_button.update(delta): + return COMMAND_CONFIRMATION + if self.deny_button.update(delta): + return COMMAND_GAME + pass + + def get_rect(self): + return pygame.Rect(self.position.x-self.width/2,self.position.y -self.height/2,self.width,self.height) + + def draw(self,surf): + pygame.draw.rect(surf,Colour.LIGHT_GRAY,self.get_rect(),border_radius=self.edge_radius) + pygame.draw.rect(surf,Colour.LIGHT_GRAY,self.get_rect(),width=self.bezel,border_radius=self.edge_radius) + surf.blit(self.text, self.text.get_rect(center = (self.position.x,self.position.y - self.text.get_rect().height/2 - self.separation_distance/2))) + self.accept_button.draw(surf) + self.deny_button.draw(surf) \ No newline at end of file diff --git a/Main/game.py b/Main/game.py index d1454d5..79f9ec7 100644 --- a/Main/game.py +++ b/Main/game.py @@ -51,16 +51,21 @@ class Game: self.unknown_word_display = UnknownWordDisplay((SCREEN_WIDTH*2/3-UnknownWordDisplay.inset,self.board.position.y),self.word_frequency) self.timer = Timer(self.unknown_word_display.position +pygame.Vector2(0,self.unknown_word_display.get_rect().height-self.unknown_word_display.inset + self.word_disp_separation_distance/2)) def update(self, delta): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return COMMAND_EXIT + elif event.type == pygame.K_ESCAPE: # for testing purposes + return COMMAND_PAUSE self.word += self.board.update(delta, self.bg_colour, self.points) self.word_connector.update(self.board.grid.last_selected, self.colour_converter[self.bg_colour]) if not pygame.mouse.get_pressed(3)[0]: # mouse not down if self.word in word_list and self.word not in self.seen: self.seen.add(self.word) - # self.points += 10 ** (len(self.word) - 2) - if len(self.word) == 3: - self.points += 100 - else: - self.points += 100 * 2 ** (len(self.word) - 2) + self.points += 100 * 2 ** (len(self.word) - 3) + # if len(self.word) == 3: + # self.points += 100 + # else: + # self.points += 100 * 2 ** (len(self.word) - 2) # self.points_display = self.text_font.render(f"Score: {self.points}", True, Colour.BLACK) self.word = "" @@ -77,6 +82,9 @@ class Game: self.word_display = self.font.render(self.word, True, Colour.BLACK) self.timer.update(delta, self.unknown_word_display.position +pygame.Vector2(0,self.unknown_word_display.get_rect().height-self.unknown_word_display.inset + self.word_disp_separation_distance/2)) + def get_next_scene(self): + return COMMAND_CONFIRMATION + def draw(self, surf): surf.fill(Palette.primary_shade1) diff --git a/Main/main.py b/Main/main.py index a41195d..05a1fa2 100644 --- a/Main/main.py +++ b/Main/main.py @@ -1,5 +1,6 @@ from setup import * from game import Game +from confirmation import Confirmation puzzle = f"puzzles/PuzzlePack{4}/puzzle{13}.txt" print(puzzle) @@ -8,13 +9,28 @@ scene = Game(puzzle) is_running = True delta = 1000/fps +paused = False +paused_scene = None + while is_running: - # screen.fill(Colour.WHITE) - if pygame.event.peek(pygame.QUIT): + status = scene.update(delta) + + if status == COMMAND_EXIT: is_running = False + elif status == COMMAND_PAUSE: + paused = not paused + if paused: + paused_scene = scene + status = scene.get_next_scene() + else: + scene = paused_scene + paused_scene = None + # Switching scenes + if status == COMMAND_CONFIRMATION: + scene = Confirmation() + - scene.update(delta) scene.draw(screen) pygame.display.update() diff --git a/Main/setup.py b/Main/setup.py index 4d782e5..ac34d61 100644 --- a/Main/setup.py +++ b/Main/setup.py @@ -20,6 +20,13 @@ pygame.display.set_icon(pygame.image.load("assets/logo.png")) clock = pygame.time.Clock() fps = 60 +COMMAND_START = 0 # go to level select +COMMAND_EXIT = 1 # quit +COMMAND_GAME_OVER = 2 # go to game over screen +COMMAND_PAUSE = 3 # Pause game +COMMAND_CONFIRMATION = 4 # Confirm show solutions +COMMAND_GAME = 5 # switch to actual game + alphabet = string.ascii_lowercase weights = [8.464812190575197, 1.8290213382006486, 4.377463842181293, 3.238497204031964, 10.77374340292079, 1.1220794892410257, 2.3639146242995768, 2.64283880414943, 8.95783107183879, 0.15584834882323761,