Created
June 7, 2022 02:38
-
-
Save Trivoz/f97fda85c7e2221f37afe65fb408755e to your computer and use it in GitHub Desktop.
pygame template file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
File: main.py | |
Author: Joshua Rose | |
Version: 0.1.0 | |
Description: ... | |
""" | |
import os | |
import logging | |
import pathlib | |
import pygame | |
from pygame.locals import * | |
__resources__: str = os.path.join(pygame.__path__[0], "index.html") | |
logging.basicConfig( | |
level=logging.INFO, | |
format='%(asctime)s %(levelname)s %(message)s', | |
datefmt='%H:%M:%S' | |
) | |
logger: logging.Logger = logging.getLogger(__name__) | |
""" | |
Description: toggles between various context GUI's, each one being dependent on the others. For | |
example, if one is true, then the rest must be false. There will be a function to ensure this. | |
Datatype: dictionary | |
Contents: boolean | |
""" | |
game_states: dict # TODO Assign variable | |
""" | |
Description: this boolean exit flag defines breaks in the game loop and stops runtime | |
Datatype: boolean | |
""" | |
game_done: bool # TODO Assign variable | |
""" | |
Description: sets cap of maximum frames(1)/1000ms when vsync is False | |
Datatype: integer | |
""" | |
window_fps: int # TODO Assign variable | |
""" | |
Description: creates the game colors that will be used allowing for pygame.Colors to be removed. | |
This creates less load on the system in runtime. | |
Datatype: dictionary | |
Contents: tuple | |
""" | |
game_colors: dict # TODO Assign variable | |
""" | |
Description: sets the window caption of the game that will be displayed @ the top-left of window control bar | |
Datatype: string | |
""" | |
window_caption: str # TODO Assign variable | |
""" | |
Description: set temporary values to be declared in a global scope for mouse_position at runtime | |
Datatype: list | |
""" | |
mouse_position: list # TODO Assign variable | |
""" | |
Description: allow the mouse to be visible on the window - which does not include detecting mouse_position | |
Datatype: bool | |
""" | |
mouse_visible: bool # TODO Assign variable | |
""" | |
Description: sets the physical window display through using the SDL window module in pygame | |
Datatype: pygame.display | |
""" | |
window: pygame.display # TODO Assign variable | |
# TODO: Enter DataType in window_size docstring after breakpoint | |
""" | |
Description: defines the width, height of the game window uses the pygame.Surface module to get the game window size | |
Datatype: list | |
""" | |
window_dimensions: list # TODO Assign variable | |
""" | |
Description: instantiate the clock function through pygame.time which regulates display update frequency | |
Datatype: pygame.time | |
""" | |
window_clock: pygame.time # TODO Assign variable | |
""" | |
Description: maps certain keys with alternative key layouts | |
Datatype: dictionary | |
""" | |
window_layouts: dict = { | |
'CMK': { | |
"w": K_w, | |
"a": K_a, | |
"s": K_r, | |
"d": K_s | |
}, | |
'DVR': {}, | |
"WRK": {} | |
} | |
class Entity(object): | |
""" | |
:description: The `Entity` class is for the purpose of inheritance, allowing sprites to have default values | |
:class Entity: object | |
""" | |
def __init__(self, x: int, y: int): | |
""" | |
:param x: int | |
:param y: int | |
""" | |
self.x = x | |
self.y = y | |
def async_timeout(ms: int) -> int: | |
""" | |
:param ms: int | |
:return: int | |
Description: return certain timeout as an integer value to be declared in a local scope at runtime | |
Datatype: pygame.Time | |
""" | |
return pygame.time.get_ticks() + ms # Expected int, got str | |
def font_exist(font: str) -> bool: | |
""" | |
:param font: str | |
:return: boolean | |
""" | |
return font in pygame.font.get_fonts() | |
def font_path(font: str, bold=False, italic=False) -> pathlib.Path: | |
""" | |
:param font: str | |
:param bold: bool | |
:param italic: bool | |
:return: pathlib.Path | |
""" | |
try: | |
return pathlib.Path(pygame.font.match_font(font, bold, italic)) | |
except pygame.error.with_traceback as _: | |
logging.warning("Cannot load %s " % font) | |
def load_font(font: str, size: int) -> pygame.font: | |
""" | |
:param font: str | |
:param size: int | |
:return: | |
""" | |
if os.path.exists(os.path.join('./fonts', font)): | |
return pygame.font.Font(os.path.join('./fonts', font), size) | |
return pygame.font.get_default_font() | |
def toggle_mouse_visible() -> None: | |
""" | |
:return: None | |
""" | |
global mouse_visible | |
if mouse_visible: | |
mouse_visible = False | |
pygame.mouse.set_visible(mouse_visible) | |
return | |
mouse_visible = True | |
pygame.mouse.set_visible(mouse_visible) | |
def load_background() -> pygame.display: ... | |
def convert_display() -> None: | |
""" | |
:return: pygame.display | |
""" | |
# TODO: Run convert_display at runtime | |
global window | |
window = window.convert() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment