diff --git a/READ.ME b/READ.ME new file mode 100644 index 0000000..bf83747 --- /dev/null +++ b/READ.ME @@ -0,0 +1,39 @@ +Brief Explanation of all files and classes and pygame + + +Button CLass: +Button(position_x, position_y, width, height, font key phrase/word (see dictionary), the function which should be executed, and if the function should be executed while holding the button or only once per press) + +fonts = { + 'medieval': 'medieval.ttf', + 'minecraft': 'Minecraft Evenings.otf', + '3dpixel': '3D-Pixel.ttf', + '8bit': '8bitlim.ttf', + '8bito': '8blimro.ttf', + 'arcade': 'ARCADECLASSIC.ttf', + 'modern_game': 'astron boy video.otf', + 'modern': 'astron boy.otf', + 'wonder': 'Beyond Wonderland.ttf', + 'curved': 'Digitag.ttf', + 'simple': 'DisposableDroidBB.ttf', + 'rounded': 'dpcomic.ttf', + 'playfull': 'Endalian Script.ttf', + 'blocky': 'FREAKSOFNATURE.ttf', + 'catchy': 'Future TimeSplitters.otf', + 'simple_wide': 'Halo3.ttf', + 'simple_fat': 'INVASION2000.ttf', + 'very_gamy': 'ka1.ttf', + 'simple_round': 'Karma Suture.otf', + 'mono': 'manaspc.ttf', + 'damaged': 'Merchant Copy.ttf', + 'big_natural': 'MorialCitadel.TTF', + 'spacy': 'nasalization-rg.otf', + 'sci-fi': 'neuropol.otf', + 'hollow_big_edge': 'papercut.ttf', + 'space_shuttle': 'pdark.ttf', + 'thin': 'PixelFJVerdana12pt.ttf', + 'random': 'Seattle Avenue.ttf', + 'pixel': 'yoster.ttf' +} + +Pygame window: (0, 0) is in the top left corner, the height and width are stored in HEIGHT and WIDTH \ No newline at end of file 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..fba9775 100644 --- a/classes.py +++ b/classes.py @@ -1,9 +1,41 @@ import pygame -font = pygame.font.SysFont('Arial', 40) +pygame.font.init() +fonts = { + 'medieval': 'medieval.ttf', + 'minecraft': 'Minecraft Evenings.otf', + '3dpixel': '3D-Pixel.ttf', + '8bit': '8bitlim.ttf', + '8bito': '8blimro.ttf', + 'arcade': 'ARCADECLASSIC.ttf', + 'modern_game': 'astron boy video.otf', + 'modern': 'astron boy.otf', + 'wonder': 'Beyond Wonderland.ttf', + 'curved': 'Digitag.ttf', + 'simple': 'DisposableDroidBB.ttf', + 'rounded': 'dpcomic.ttf', + 'playfull': 'Endalian Script.ttf', + 'blocky': 'FREAKSOFNATURE.ttf', + 'catchy': 'Future TimeSplitters.otf', + 'simple_wide': 'Halo3.ttf', + 'simple_fat': 'INVASION2000.ttf', + 'very_gamy': 'ka1.ttf', + 'simple_round': 'Karma Suture.otf', + 'mono': 'manaspc.ttf', + 'damaged': 'Merchant Copy.ttf', + 'big_natural': 'MorialCitadel.TTF', + 'spacy': 'nasalization-rg.otf', + 'sci-fi': 'neuropol.otf', + 'hollow_big_edge': 'papercut.ttf', + 'space_shuttle': 'pdark.ttf', + 'thin': 'PixelFJVerdana12pt.ttf', + 'random': 'Seattle Avenue.ttf', + 'pixel': 'yoster.ttf' +} class Button(): - def __init__(self, x, y, width, height, buttonText='Button', onclickFunction=None, onePress=False): + def __init__(self, x, y, width, height, font, buttonText='Button', onclickFunction=None, onePress=False): + font = pygame.font.Font(f'fonts/{fonts[font]}', 48) self.x = x self.y = y self.width = width @@ -12,14 +44,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/3D-Pixel.ttf b/fonts/3D-Pixel.ttf new file mode 100644 index 0000000..15a051c Binary files /dev/null and b/fonts/3D-Pixel.ttf differ diff --git a/fonts/8bitlim.ttf b/fonts/8bitlim.ttf new file mode 100644 index 0000000..f8051e4 Binary files /dev/null and b/fonts/8bitlim.ttf differ diff --git a/fonts/8bitlimo.ttf b/fonts/8bitlimo.ttf new file mode 100644 index 0000000..fbd4d88 Binary files /dev/null and b/fonts/8bitlimo.ttf differ diff --git a/fonts/8bitlimr.ttf b/fonts/8bitlimr.ttf new file mode 100644 index 0000000..c66935d Binary files /dev/null and b/fonts/8bitlimr.ttf differ diff --git a/fonts/8blimro.ttf b/fonts/8blimro.ttf new file mode 100644 index 0000000..1f9da76 Binary files /dev/null and b/fonts/8blimro.ttf differ diff --git a/fonts/ARCADECLASSIC.TTF b/fonts/ARCADECLASSIC.TTF new file mode 100644 index 0000000..394a9f7 Binary files /dev/null and b/fonts/ARCADECLASSIC.TTF differ diff --git a/fonts/Beyond Wonderland.ttf b/fonts/Beyond Wonderland.ttf new file mode 100644 index 0000000..8cf093b Binary files /dev/null and b/fonts/Beyond Wonderland.ttf differ diff --git a/fonts/Digitag.ttf b/fonts/Digitag.ttf new file mode 100644 index 0000000..ea523e9 Binary files /dev/null and b/fonts/Digitag.ttf differ diff --git a/fonts/DisposableDroidBB.ttf b/fonts/DisposableDroidBB.ttf new file mode 100644 index 0000000..84f98c5 Binary files /dev/null and b/fonts/DisposableDroidBB.ttf differ diff --git a/fonts/DisposableDroidBB_bld.ttf b/fonts/DisposableDroidBB_bld.ttf new file mode 100644 index 0000000..9748e29 Binary files /dev/null and b/fonts/DisposableDroidBB_bld.ttf differ diff --git a/fonts/DisposableDroidBB_bldital.ttf b/fonts/DisposableDroidBB_bldital.ttf new file mode 100644 index 0000000..5544fe4 Binary files /dev/null and b/fonts/DisposableDroidBB_bldital.ttf differ diff --git a/fonts/DisposableDroidBB_ital.ttf b/fonts/DisposableDroidBB_ital.ttf new file mode 100644 index 0000000..596d523 Binary files /dev/null and b/fonts/DisposableDroidBB_ital.ttf differ diff --git a/fonts/Endalian Script.ttf b/fonts/Endalian Script.ttf new file mode 100644 index 0000000..1304f00 Binary files /dev/null and b/fonts/Endalian Script.ttf differ diff --git a/fonts/FREAKSOFNATURE.ttf b/fonts/FREAKSOFNATURE.ttf new file mode 100644 index 0000000..335c851 Binary files /dev/null and b/fonts/FREAKSOFNATURE.ttf differ diff --git a/fonts/FREAKSOFNATUREMASSIVE.ttf b/fonts/FREAKSOFNATUREMASSIVE.ttf new file mode 100644 index 0000000..f9b49d8 Binary files /dev/null and b/fonts/FREAKSOFNATUREMASSIVE.ttf differ diff --git a/fonts/Future TimeSplitters.otf b/fonts/Future TimeSplitters.otf new file mode 100644 index 0000000..f28a9a9 Binary files /dev/null and b/fonts/Future TimeSplitters.otf differ diff --git a/fonts/Halo3.ttf b/fonts/Halo3.ttf new file mode 100644 index 0000000..daeb3f2 Binary files /dev/null and b/fonts/Halo3.ttf differ diff --git a/fonts/INVASION2000.TTF b/fonts/INVASION2000.TTF new file mode 100644 index 0000000..87f629b Binary files /dev/null and b/fonts/INVASION2000.TTF differ diff --git a/fonts/Karma Future.otf b/fonts/Karma Future.otf new file mode 100644 index 0000000..c05849b Binary files /dev/null and b/fonts/Karma Future.otf differ diff --git a/fonts/Karma Suture.otf b/fonts/Karma Suture.otf new file mode 100644 index 0000000..31279ea Binary files /dev/null and b/fonts/Karma Suture.otf differ diff --git a/fonts/Merchant Copy Doublesize.ttf b/fonts/Merchant Copy Doublesize.ttf new file mode 100644 index 0000000..6651f4b Binary files /dev/null and b/fonts/Merchant Copy Doublesize.ttf differ diff --git a/fonts/Merchant Copy Wide.ttf b/fonts/Merchant Copy Wide.ttf new file mode 100644 index 0000000..74527d2 Binary files /dev/null and b/fonts/Merchant Copy Wide.ttf differ diff --git a/fonts/Merchant Copy.ttf b/fonts/Merchant Copy.ttf new file mode 100644 index 0000000..a095272 Binary files /dev/null and b/fonts/Merchant Copy.ttf differ diff --git a/fonts/Minecraft Evenings.otf b/fonts/Minecraft Evenings.otf new file mode 100644 index 0000000..ada43f1 Binary files /dev/null and b/fonts/Minecraft Evenings.otf differ diff --git a/fonts/MoriaCitadel.TTF b/fonts/MoriaCitadel.TTF new file mode 100644 index 0000000..7a63981 Binary files /dev/null and b/fonts/MoriaCitadel.TTF differ diff --git a/fonts/PixelFJVerdana12pt.ttf b/fonts/PixelFJVerdana12pt.ttf new file mode 100644 index 0000000..5531267 Binary files /dev/null and b/fonts/PixelFJVerdana12pt.ttf differ diff --git a/fonts/Seattle Avenue.ttf b/fonts/Seattle Avenue.ttf new file mode 100644 index 0000000..21f3099 Binary files /dev/null and b/fonts/Seattle Avenue.ttf differ diff --git a/fonts/SeattleAvenue.otf b/fonts/SeattleAvenue.otf new file mode 100644 index 0000000..57f51c1 Binary files /dev/null and b/fonts/SeattleAvenue.otf differ diff --git a/fonts/astron boy italic.otf b/fonts/astron boy italic.otf new file mode 100644 index 0000000..25f5c1f Binary files /dev/null and b/fonts/astron boy italic.otf differ diff --git a/fonts/astron boy video.otf b/fonts/astron boy video.otf new file mode 100644 index 0000000..78a3c9d Binary files /dev/null and b/fonts/astron boy video.otf differ diff --git a/fonts/astron boy wonder.otf b/fonts/astron boy wonder.otf new file mode 100644 index 0000000..72c7e49 Binary files /dev/null and b/fonts/astron boy wonder.otf differ diff --git a/fonts/astron boy.otf b/fonts/astron boy.otf new file mode 100644 index 0000000..d27810f Binary files /dev/null and b/fonts/astron boy.otf differ diff --git a/fonts/dpcomic.ttf b/fonts/dpcomic.ttf new file mode 100644 index 0000000..a0776ae Binary files /dev/null and b/fonts/dpcomic.ttf differ diff --git a/fonts/ka1.ttf b/fonts/ka1.ttf new file mode 100644 index 0000000..d1df852 Binary files /dev/null and b/fonts/ka1.ttf differ diff --git a/fonts/kirbyss.ttf b/fonts/kirbyss.ttf new file mode 100644 index 0000000..018853f Binary files /dev/null and b/fonts/kirbyss.ttf differ diff --git a/fonts/manaspc.ttf b/fonts/manaspc.ttf new file mode 100644 index 0000000..0c56733 Binary files /dev/null and b/fonts/manaspc.ttf differ 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/fonts/nasalization-rg.otf b/fonts/nasalization-rg.otf new file mode 100644 index 0000000..ce4625f Binary files /dev/null and b/fonts/nasalization-rg.otf differ diff --git a/fonts/neuropol.otf b/fonts/neuropol.otf new file mode 100644 index 0000000..5732517 Binary files /dev/null and b/fonts/neuropol.otf differ diff --git a/fonts/papercut.ttf b/fonts/papercut.ttf new file mode 100644 index 0000000..4f47ef4 Binary files /dev/null and b/fonts/papercut.ttf differ diff --git a/fonts/pcsenior.ttf b/fonts/pcsenior.ttf new file mode 100644 index 0000000..0bb46c4 Binary files /dev/null and b/fonts/pcsenior.ttf differ diff --git a/fonts/pdark.ttf b/fonts/pdark.ttf new file mode 100644 index 0000000..0eace6e Binary files /dev/null and b/fonts/pdark.ttf differ diff --git a/fonts/yoster.ttf b/fonts/yoster.ttf new file mode 100644 index 0000000..bbbeb51 Binary files /dev/null and b/fonts/yoster.ttf differ diff --git a/main.py b/main.py index d44a2c6..d68cad2 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, '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) 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()