diff --git a/art/textbox.png b/art/textbox.png index 09a258c..be01aef 100644 Binary files a/art/textbox.png and b/art/textbox.png differ diff --git a/classes.py b/classes.py index 0d2ac25..311fec3 100644 --- a/classes.py +++ b/classes.py @@ -1,6 +1,7 @@ import pygame -font = pygame.font.SysFont('Arial', 40) +pygame.font.init() +font = pygame.font.Font('fonts/medieval.ttf', 48) class Button(): def __init__(self, x, y, width, height, buttonText='Button', onclickFunction=None, onePress=False): @@ -12,14 +13,30 @@ class Button(): self.onePress = onePress self.alreadyPressed = False - self.fillColors = { - 'normal': '#ffffff', - 'hover': '#666666', - 'pressed': '#333333', - } + with open('art/textbox.png', 'r') as tb: + self.box = pygame.image.load(tb) + self.box = pygame.transform.scale(self.box, (width, height)) + - self.buttonSurface = pygame.Surface((self.width, self.height)) self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height) - self.buttonSurf = font.render(buttonText, True, (20, 20, 20)) - return self \ No newline at end of file + self.buttonSurf = 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: + self.onclickFunction() + self.alreadyPressed = True + else: + self.alreadyPressed = False + self.box.blit(self.buttonSurf, [ + 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 diff --git a/fonts/medieval.ttf b/fonts/medieval.ttf new file mode 100644 index 0000000..5337005 Binary files /dev/null and b/fonts/medieval.ttf differ diff --git a/main.py b/main.py index d44a2c6..b8d191e 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import pygame import sys import json import time +from classes import * def setUp(config): pygame.init() @@ -10,18 +11,30 @@ def setUp(config): else: screen = pygame.display.set_mode(config["res"]) clock = pygame.time.Clock() - with open('art/textbox.png', 'r') as tb: - box = pygame.image.load(tb) - return screen, clock, True, True, "start.png", box + + return screen, clock, True, True, "start.png", [] def readConfig(): with open('config.json', 'r') as c: json_data = c.read() return json.loads(json_data) +def quitGame(): + #save progress somehow, if needed + pygame.quit() + sys.exit() + +def uwu(): + print('uwu') + def main(): config = readConfig() - screen, clock, running, background, isblack, box = setUp(config["screen"]) + 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, "Exit game", quitGame)) + objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, "Options", uwu)) + objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, "Play", uwu)) + print(objects) while running: for event in pygame.event.get(): @@ -31,7 +44,7 @@ def main(): if not isblack: with open(background, 'r') as i: bg = pygame.image.load(i) - bg = pygame.transform.scale(bg, screen.get_size()) + bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) # fill the screen with a color to wipe away anything from last frame screen.blit(bg, (0, 0)) @@ -39,6 +52,8 @@ def main(): else: screen.fill('#000000') + for obj in objects: + obj.process(screen) # flip() the display to put your work on screen pygame.display.flip()