Compare commits

...

9 Commits

Author SHA1 Message Date
9c99027912 Updated README.md 2025-06-22 18:21:33 +01:00
5a60777a73 Added example launch.json 2025-06-22 18:15:25 +01:00
39ec99fd1f Update README.md 2025-06-21 22:29:56 +00:00
e87c977c6f Update README.md 2025-06-21 22:29:28 +00:00
c96b3b803d Updated to utilise v1.0.0 of GameUtils 2025-06-21 23:27:16 +01:00
fe5d3a3de4 Updated README.md 2025-06-20 19:30:12 +01:00
7b502f27ff Removed __main__.py 2025-06-20 19:28:32 +01:00
593488f73c Renamed __init__.py to game.py 2025-06-20 18:05:25 +01:00
43768f4fed Moved initalisation code to GameUtils 2025-06-20 14:46:58 +01:00
4 changed files with 45 additions and 75 deletions

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger",
"type": "debugpy",
"request": "launch",
"python": "../PainJamLauncher/.venv/Scripts/python.exe",
"program": "../PainJamLauncher/__main__.py",
"args": ["CHANGE ME TO YOUR GAME ID"],
"console": "integratedTerminal"
}
]
}

View File

@ -1,19 +1,28 @@
# BaseGame
A template that all games should be based on.
The boilerplate code that all games are based on.
The idea is this will make it easier to integrate with [The Pain Jam Launcher](https://git.personal.imadumbass.dog/PainJam/PainJamLauncher).
I have no idea how templates work so we just kinda balling with this one, team.
This makes it possible for the [The Pain Jam Launcher](https://git.personal.imadumbass.dog/PainJam/PainJamLauncher) to run your game properly.
## Usage
This template contains the following files:
- `game.py`: Your actual game code.
- `game.toml`: Stores information about your game.
- `requirements.txt`: Base requirements each game needs.
- `.vscode/launch.json`: An example `launch.json` for use in VSCode. Change the arguments to use your game ID.
`__init__.py`: Your actual game code.
Make sure to edit / delete:
- `README.md`: To contain information about your game, rather than this.
- `TODO.md`: To contain your own TODOs.
`__main__.py`: The standalone launcher. This should not be changed as this file is not ran when using an external launcher.
For more information about how to use each of these files, check the documentation within each file.
`game.toml`: Stores information about your game
In order to develop a game, you must base your game off this file, and require the following directory layout:
- `YourGame` (Based on [BaseGame](https://git.personal.imadumbass.dog/PainJam/BaseGame))
- [`GameUtils`](https://git.personal.imadumbass.dog/PainJam/GameUtils)
- [`NoPELib`](https://git.personal.imadumbass.dog/Brosef/NoPELib)
- [`PDOLib`](https://git.personal.imadumbass.dog/Brosef/PDOLib)
- [`PainJamLauncher`](https://git.personal.imadumbass.dog/PainJam/PainJamLauncher)
For more information about how to use each of these files, check the documentation within each file.
Once you have all of those, run `setup.py` located in the `PainJamLauncher`. This will automatically configure a virtual environment and install all dependancies.

View File

@ -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()

View File

@ -4,18 +4,18 @@ import gameUtils
import NoPELib
class Game(gameUtils.Game):
def __init__(self, surface, size):
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):
"""
@ -31,7 +31,9 @@ class Game(gameUtils.Game):
Ran once per frame, put your drawing code and any
game logic that should be ran once per frame in here.
"""
pass
# Don't remove this. It does important things. :3
super().update()
def close(self):
"""