]> Skullheadx's Git Forge - word-hunt.git/commitdiff
confirmation screen + status in main
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sat, 26 Nov 2022 04:30:43 +0000 (23:30 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sat, 26 Nov 2022 04:30:43 +0000 (23:30 -0500)
need to make buttons

Main/Button.py [new file with mode: 0644]
Main/__pycache__/game.cpython-310.pyc
Main/__pycache__/setup.cpython-310.pyc
Main/confirmation.py [new file with mode: 0644]
Main/game.py
Main/main.py
Main/setup.py

diff --git a/Main/Button.py b/Main/Button.py
new file mode 100644 (file)
index 0000000..aecb1b3
--- /dev/null
@@ -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
index 8274f661699d71b86769b7a8f1c1eca85847dfaf..38268556db1abb26f80a9c03399c2a80a42233c2 100644 (file)
Binary files a/Main/__pycache__/game.cpython-310.pyc and b/Main/__pycache__/game.cpython-310.pyc differ
index 524abc3af29794362089951fb6332221300a6685..f980017ae3c56a637eee85c4916a6c4af1b33882 100644 (file)
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 (file)
index 0000000..8291492
--- /dev/null
@@ -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
index d1454d590e33efb2d1b9a2c860d751755fa6a931..79f9ec7a2436d256e169c0eed3e9a64d4c8125f9 100644 (file)
@@ -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)
index a41195d91efc08c2a8ed2ff50ce3f4e431c9c0fb..05a1fa29a54d62caef0a4e220f8568d8e3c9d1fb 100644 (file)
@@ -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()
index 4d782e58157374d2540413c5ba7c1e65368eee10..ac34d616e39195be8e9b8fc2935a5bb638540435 100644 (file)
@@ -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,