diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..7cbf5cb --- /dev/null +++ b/__init__.py @@ -0,0 +1,39 @@ +import logging +import pygame +#import NoPELib +#import PDOLib + +class Game: + def __init__(self, surface, size): + """ + Ran when the game starts. + + Args: + surface (pygame.Surface): The surface you draw to. + size (list[int, int]): The size of the surface. + """ + + pygame.init() + self.surface = surface + self.size = size + + def onEvent(self, event): + """ + Ran when an event is fired. + + Args: + event (pygame.Event): The event that was fired + """ + pass + + def draw(self): + """ + Ran once per frame, put your drawing code in here + """ + pass + + def close(self): + """ + Ran when the game closes + """ + pass diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..b98f690 --- /dev/null +++ b/__main__.py @@ -0,0 +1,58 @@ +# Import the game code +import __init__ + +import argparse +import tomllib +import pathlib +import pygame +import os + +# Store the current working directory +# This is used to revert the cd change +originalCWD = os.getcwd() + +# Get the path of the game +basePath = pathlib.Path(__file__).parent.resolve() + +# Set the current working directory +# to the base path of the game +os.chdir(basePath) + +# Load the game.toml data +with open('game.toml', 'r') as f: + gameData = tomllib.loads(f.read()) + +# Parse command line arguments +parser = argparse.ArgumentParser(prog=gameData['name']) +parser.add_argument('-sw', '--width', type=int, default=1280) +parser.add_argument('-sh', '--height', type=int, default=720) +parser.add_argument('-f', '--fullscreen', action='store_true') +args = parser.parse_args() + +# Initialise screen +flags = 0 +if args.fullscreen: flags |= pygame.FULLSCREEN +screen = pygame.display.set_mode((args.width, args.height), flags) +pygame.display.set_caption(gameData['name']) + +# Initialise game +game = __init__.Game(screen, screen.size) + +# Set to False when the game should exit +run = True + +while run: + # Event loop + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False + + game.onEvent(event) + + # Draw loop + game.draw() + +# Clean up +os.chdir(originalCWD) +game.close() +pygame.quit() \ No newline at end of file diff --git a/game.toml b/game.toml new file mode 100644 index 0000000..be4d061 --- /dev/null +++ b/game.toml @@ -0,0 +1,7 @@ +# The ID used for logging +id = "captchaGame" +# The name used for setting the windows +# title, and for displaying in the launcher +name = "Verify or Fucking Die" +# The description displayed by the launcher +description = "A captcha game where you're given a limited amount of time to complete a captcha. Type one character wrong, you get shocked. Fail to complete the captcha, and you die." diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d22a515 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +#../NoPELib/ +#../PDOLib/ +pygame-ce \ No newline at end of file