feat: create config file and config manager
This commit is contained in:
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
10
config.yaml
Normal file
10
config.yaml
Normal file
@@ -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
|
||||
@@ -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
|
||||
41
main.py
41
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():
|
||||
|
||||
|
||||
12
util/ConfigurationManager.py
Normal file
12
util/ConfigurationManager.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user