feat: create config file and config manager

This commit is contained in:
Giovani Rodriguez
2021-06-02 22:51:25 -04:00
parent 0f3d842935
commit 58afbf4446
5 changed files with 63 additions and 22 deletions

41
main.py
View File

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