From 6c6c1af32941f10b7b2dddd9cc8cf8253e57e40a Mon Sep 17 00:00:00 2001 From: Brosef Date: Fri, 20 Jun 2025 19:32:22 +0100 Subject: [PATCH] Re-based to follow thee new new base game --- __init__.py | 33 ++++++++++++++------------- __main__.py | 58 ------------------------------------------------ requirements.txt | 5 +++-- 3 files changed, 21 insertions(+), 75 deletions(-) delete mode 100644 __main__.py diff --git a/__init__.py b/__init__.py index 7cbf5cb..14278f9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,39 +1,42 @@ +from PIL import Imgae import logging import pygame -#import NoPELib -#import PDOLib +import gameUtils +import NoPELib -class Game: - def __init__(self, surface, size): +class Game(gameUtils.Game): + def __init__(self, *args, **kwargs): """ Ran when the game starts. - Args: - surface (pygame.Surface): The surface you draw to. - size (list[int, int]): The size of the surface. + You have access to the following variables: + self.surf (pygame.Surface): This is the surface you draw onto. + self.pm (NoPELib.PlayerManager): This is where your players are stored. + self.cfg (dict): Everything from the `game.toml` file. You can access it like this: self.details['title'] """ - - pygame.init() - self.surface = surface - self.size = size + + # Don't remove this. It does important things. :3 + super().__init__(*args, **kwargs) def onEvent(self, event): """ Ran when an event is fired. Args: - event (pygame.Event): The event that was fired + event (pygame.Event): The event that was fired. """ pass - def draw(self): + def update(self): """ - Ran once per frame, put your drawing code in here + Ran once per frame, put your drawing code and any + game logic that should be ran once per frame in here. """ pass def close(self): """ - Ran when the game closes + Ran when the game closes. """ pass + diff --git a/__main__.py b/__main__.py deleted file mode 100644 index b98f690..0000000 --- a/__main__.py +++ /dev/null @@ -1,58 +0,0 @@ -# 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/requirements.txt b/requirements.txt index d22a515..88e6a6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -#../NoPELib/ -#../PDOLib/ +../GameUtils/ +../NoPELib/ +../PDOLib/ pygame-ce \ No newline at end of file