diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..17e15f2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // 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: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..f0ad2d1 --- /dev/null +++ b/config.yaml @@ -0,0 +1,10 @@ +# window properties +window: + width: 800 + height: 600 + icon: "img/tetris_icon.png" + title: "Tetris" + background-color: "#6495ED" # cornflower blue + +engine: + fps: 60 \ No newline at end of file diff --git a/entity/tetromino.py b/entity/Piece.py similarity index 73% rename from entity/tetromino.py rename to entity/Piece.py index d818fe9..87084de 100644 --- a/entity/tetromino.py +++ b/entity/Piece.py @@ -4,7 +4,10 @@ import pygame For information on the Tetris piece Tetromino go here: https://tetris.fandom.com/wiki/Tetromino ''' -class tetromino: - +class Piece: + def __init__(self): + pass + + def draw(screen): pass \ No newline at end of file diff --git a/main.py b/main.py index d2f2dd6..b98b111 100644 --- a/main.py +++ b/main.py @@ -1,26 +1,21 @@ import pygame -from entity.tetromino import tetromino -# window properties -WIN_WIDTH = 800 -WIN_HEIGHT = 600 -WIN_ICON = "img/tetris_icon.png" -WIN_TITLE = "Tetris" -WIN_BG_COLOR = (100, 149, 237) # cornflower blue, RGB +from entity.Piece import Piece +from util.ConfigurationManager import ConfigurationManager + +# load configs into game +ConfigurationManager.load() # potential color palette https://coolors.co/6495ed-ee6352-59cd90-fac05e-f79d84 -FIRE_OPAL = (238, 99, 82) - -# engine properties -FPS = 60 - -# other -TILE_SIZE = 20 +FIRE_OPAL = (238, 99, 82) # TODO define colors in config +TILE_SIZE = 20 # TODO define tile size in config def draw(screen): # draw window bg - screen.fill(WIN_BG_COLOR) + bg_color = pygame.Color(ConfigurationManager.configuration["window"]["background-color"]) + screen.fill(bg_color) + # TODO move piece logic into class # draw j tetromino? j_points = [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (3, 2), (2, 2), (2, 1), (1, 1), (0, 1)] @@ -42,16 +37,22 @@ def draw(screen): def main(): pygame.init() - screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT)) - clock = pygame.time.Clock() - loaded_icon = pygame.image.load(WIN_ICON) + win_width = ConfigurationManager.configuration["window"]["width"] + win_height = ConfigurationManager.configuration["window"]["height"] + win_icon = ConfigurationManager.configuration["window"]["icon"] + win_title = ConfigurationManager.configuration["window"]["title"] + fps = ConfigurationManager.configuration["engine"]["fps"] - pygame.display.set_caption(WIN_TITLE) + screen = pygame.display.set_mode((win_width, win_height)) + clock = pygame.time.Clock() + loaded_icon = pygame.image.load(win_icon) + + pygame.display.set_caption(win_title) pygame.display.set_icon(loaded_icon) is_running = True while is_running: - clock.tick(FPS) + clock.tick(fps) for event in pygame.event.get(): diff --git a/util/ConfigurationManager.py b/util/ConfigurationManager.py new file mode 100644 index 0000000..ef41aff --- /dev/null +++ b/util/ConfigurationManager.py @@ -0,0 +1,12 @@ +import yaml + +CONFIG_FILE_LOCATION = "config.yaml" + +class ConfigurationManager: + + configuration = [] + + @classmethod + def load(cls): + with open(CONFIG_FILE_LOCATION, "r") as yaml_file: + cls.configuration = yaml.safe_load(yaml_file) \ No newline at end of file