aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoisis <moisis.george@yahoo.com>2023-04-24 01:27:30 +0200
committerMoisis <moisis.george@yahoo.com>2023-04-24 01:27:30 +0200
commit1c33c06df4d40e708d526cd00d3b8392d931b7c2 (patch)
tree100233aede0f4071b957e9fe047a4f96400323d7
parent7194ca65ae23d96960fe7edb619efb100db0a49c (diff)
downloadMacpan-1c33c06df4d40e708d526cd00d3b8392d931b7c2.tar.xz
Macpan-1c33c06df4d40e708d526cd00d3b8392d931b7c2.zip
Added Basic GUI
-rw-r--r--assets/Background.pngbin0 -> 1440004 bytes
-rw-r--r--assets/Options Rect.pngbin0 -> 1569 bytes
-rw-r--r--assets/PAC-FONT.TTFbin0 -> 44236 bytes
-rw-r--r--assets/Play Rect.pngbin0 -> 1023 bytes
-rw-r--r--assets/Quit Rect.pngbin0 -> 1003 bytes
-rw-r--r--assets/icon.pngbin0 -> 357274 bytes
-rw-r--r--src/GUI.py126
-rw-r--r--src/GUIbutton.py29
-rw-r--r--src/game.py10
9 files changed, 164 insertions, 1 deletions
diff --git a/assets/Background.png b/assets/Background.png
new file mode 100644
index 0000000..03a6383
--- /dev/null
+++ b/assets/Background.png
Binary files differ
diff --git a/assets/Options Rect.png b/assets/Options Rect.png
new file mode 100644
index 0000000..2e8642b
--- /dev/null
+++ b/assets/Options Rect.png
Binary files differ
diff --git a/assets/PAC-FONT.TTF b/assets/PAC-FONT.TTF
new file mode 100644
index 0000000..fd0391e
--- /dev/null
+++ b/assets/PAC-FONT.TTF
Binary files differ
diff --git a/assets/Play Rect.png b/assets/Play Rect.png
new file mode 100644
index 0000000..6d144eb
--- /dev/null
+++ b/assets/Play Rect.png
Binary files differ
diff --git a/assets/Quit Rect.png b/assets/Quit Rect.png
new file mode 100644
index 0000000..0481ec0
--- /dev/null
+++ b/assets/Quit Rect.png
Binary files differ
diff --git a/assets/icon.png b/assets/icon.png
new file mode 100644
index 0000000..30a7420
--- /dev/null
+++ b/assets/icon.png
Binary files differ
diff --git a/src/GUI.py b/src/GUI.py
new file mode 100644
index 0000000..21cec17
--- /dev/null
+++ b/src/GUI.py
@@ -0,0 +1,126 @@
+import pygame
+import sys
+from GUIbutton import Button
+from src.game import Game
+import ctypes
+
+# icon on taskbar
+
+myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
+ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
+
+
+pygame.init()
+
+SCREEN = pygame.display.set_mode((1280, 720))
+pygame.display.set_caption("Mac-Pan")
+
+BG = pygame.image.load("../assets/Background.png")
+
+icon = pygame.image.load("../assets/icon.png")
+pygame.display.set_icon(icon)
+
+
+
+def get_font(size): # Returns Press-Start-2P in the desired size
+ return pygame.font.Font("../assets/PAC-FONT.TTF", size)
+
+
+# def play():
+# while True:
+# PLAY_MOUSE_POS = pygame.mouse.get_pos()
+#
+# SCREEN.fill("black")
+#
+# PLAY_TEXT = get_font(45).render("This is the PLAY screen.", True, "White")
+# PLAY_RECT = PLAY_TEXT.get_rect(center=(640, 260))
+# SCREEN.blit(PLAY_TEXT, PLAY_RECT)
+#
+# PLAY_BACK = Button(image=None, pos=(640, 460),
+# text_input="BACK", font=get_font(75), base_color="White", hovering_color="Green")
+#
+# PLAY_BACK.changeColor(PLAY_MOUSE_POS)
+# PLAY_BACK.update(SCREEN)
+#
+# for event in pygame.event.get():
+# if event.type == pygame.QUIT:
+# pygame.quit()
+# sys.exit()
+# if event.type == pygame.MOUSEBUTTONDOWN:
+# if PLAY_BACK.checkForInput(PLAY_MOUSE_POS):
+# main_menu()
+#
+# pygame.display.update()
+
+## Todo options sound options here ??
+def options():
+ while True:
+ OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
+
+ SCREEN.fill("white")
+
+ OPTIONS_TEXT = get_font(45).render("This is the OPTIONS screen.", True, "Black")
+ OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
+ SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
+
+ OPTIONS_BACK = Button(image=None, pos=(640, 460),
+ text_input="BACK", font=get_font(75), base_color="Black", hovering_color="Green")
+
+ OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
+ OPTIONS_BACK.update(SCREEN)
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ pygame.quit()
+ sys.exit()
+ if event.type == pygame.MOUSEBUTTONDOWN:
+ if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
+ main_menu()
+
+ pygame.display.update()
+
+
+def main_menu():
+ while True:
+ SCREEN.blit(BG, (0, 0))
+
+ MENU_MOUSE_POS = pygame.mouse.get_pos()
+
+ MENU_TEXT = get_font(100).render("Mac-Pan", True, "#b68f40")
+ MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
+
+ PLAY_BUTTON = Button(image=pygame.image.load("../assets/Play Rect.png"), pos=(640, 250),
+ text_input="PLAY", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
+ OPTIONS_BUTTON = Button(image=pygame.image.load("../assets/Options Rect.png"), pos=(640, 400),
+ text_input="OPTIONS", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
+ QUIT_BUTTON = Button(image=pygame.image.load("../assets/Quit Rect.png"), pos=(640, 550),
+ text_input="QUIT", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
+
+ SCREEN.blit(MENU_TEXT, MENU_RECT)
+
+ for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
+ button.changeColor(MENU_MOUSE_POS)
+ button.update(SCREEN)
+
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ pygame.quit()
+ sys.exit()
+ if event.type == pygame.MOUSEBUTTONDOWN:
+ if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
+ #play()
+ game = Game()
+ game.run()
+
+ if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
+ options()
+ if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
+ pygame.quit()
+ sys.exit()
+
+ pygame.display.update()
+
+
+
+
+main_menu()
diff --git a/src/GUIbutton.py b/src/GUIbutton.py
new file mode 100644
index 0000000..794f693
--- /dev/null
+++ b/src/GUIbutton.py
@@ -0,0 +1,29 @@
+class Button():
+ def __init__(self, image, pos, text_input, font, base_color, hovering_color):
+ self.image = image
+ self.x_pos = pos[0]
+ self.y_pos = pos[1]
+ self.font = font
+ self.base_color, self.hovering_color = base_color, hovering_color
+ self.text_input = text_input
+ self.text = self.font.render(self.text_input, True, self.base_color)
+ if self.image is None:
+ self.image = self.text
+ self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
+ self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
+
+ def update(self, screen):
+ if self.image is not None:
+ screen.blit(self.image, self.rect)
+ screen.blit(self.text, self.text_rect)
+
+ def checkForInput(self, position):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
+ return True
+ return False
+
+ def changeColor(self, position):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
+ self.text = self.font.render(self.text_input, True, self.hovering_color)
+ else:
+ self.text = self.font.render(self.text_input, True, self.base_color) \ No newline at end of file
diff --git a/src/game.py b/src/game.py
index 5b85c39..37739e3 100644
--- a/src/game.py
+++ b/src/game.py
@@ -167,4 +167,12 @@ class Game():
pygame.display.flip()
# Quit Pygame
- pygame.quit()
+
+ #pygame.quit()
+ screen = pygame.display.set_mode((1280, 720))
+ pygame.mixer.music.stop()
+ siren_sound.stop()
+
+
+
+