Inital commit
Straight up fucked everything up so the history is gone. My bad.
This commit is contained in:
19
README.md
Normal file
19
README.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# BaseGame
|
||||||
|
|
||||||
|
A template that all games should be 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.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This template contains the following files:
|
||||||
|
|
||||||
|
`__init__.py`: Your actual game code.
|
||||||
|
|
||||||
|
`__main__.py`: The standalone launcher. This should not be changed as this file is not ran when using an external launcher.
|
||||||
|
|
||||||
|
`game.toml`: Stores information about your game
|
||||||
|
|
||||||
|
For more information about how to use each of these files, check the documentation within each file.
|
||||||
40
__init__.py
Normal file
40
__init__.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import logging
|
||||||
|
import pygame
|
||||||
|
import gameUtils
|
||||||
|
import NoPELib
|
||||||
|
|
||||||
|
class Game(gameUtils.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 update(self):
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
58
__main__.py
Normal file
58
__main__.py
Normal file
@ -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()
|
||||||
8
game.toml
Normal file
8
game.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# The ID used for logging
|
||||||
|
# TODO: Filter things like '\', '{}', '\n' etc.-
|
||||||
|
id = "changeMe"
|
||||||
|
# The name used for setting the windows
|
||||||
|
# title, and for displaying in the launcher
|
||||||
|
name = "Change me"
|
||||||
|
# The description displayed by the launcher
|
||||||
|
description = "Write something about this game.\nNew lines are supported."
|
||||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
../GameUtils/
|
||||||
|
../NoPELib/
|
||||||
|
../PDOLib/
|
||||||
|
pygame-ce
|
||||||
Reference in New Issue
Block a user