feat: revamp colors
This commit is contained in:
14
Tetris.py
14
Tetris.py
@@ -34,15 +34,15 @@ class Tetris:
|
|||||||
self.screen = pygame.display.set_mode((win_width, win_height))
|
self.screen = pygame.display.set_mode((win_width, win_height))
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.main_music = mixer.Channel(0)
|
self.main_music = mixer.Channel(0)
|
||||||
self.well = Well((280, 80), ConfigurationManager.configuration["color"]["border"]) # TODO calculate position later and redo color config for well
|
self.well = Well((280, 80), ConfigurationManager.configuration["color"]["well-1"], ConfigurationManager.configuration["color"]["well-border-1"]) # TODO calculate position later and redo color config for well
|
||||||
self.stack = Stack(ConfigurationManager.configuration["color"]["base-4"], ConfigurationManager.configuration["color"]["border"])
|
self.stack = Stack(ConfigurationManager.configuration["color"]["stack-1"], ConfigurationManager.configuration["color"]["stack-border-1"])
|
||||||
|
|
||||||
loaded_icon = pygame.image.load(win_icon)
|
loaded_icon = pygame.image.load(win_icon)
|
||||||
pygame.display.set_caption(win_title)
|
pygame.display.set_caption(win_title)
|
||||||
pygame.display.set_icon(loaded_icon)
|
pygame.display.set_icon(loaded_icon)
|
||||||
|
|
||||||
main_music_file = ConfigurationManager.configuration["sound"]["main-music"]
|
main_music_file = ConfigurationManager.configuration["sound"]["main-music"]
|
||||||
self.main_music.set_volume(0.7)
|
self.main_music.set_volume(0.7) # TODO add volume to the config
|
||||||
self.main_music.play(mixer.Sound(main_music_file), -1)
|
self.main_music.play(mixer.Sound(main_music_file), -1)
|
||||||
|
|
||||||
# gets called from the games main loop
|
# gets called from the games main loop
|
||||||
@@ -81,12 +81,6 @@ class Tetris:
|
|||||||
self.current_piece.revert()
|
self.current_piece.revert()
|
||||||
if self.stack and self.current_piece.collide(self.stack):
|
if self.stack and self.current_piece.collide(self.stack):
|
||||||
self.current_piece.revert()
|
self.current_piece.revert()
|
||||||
if event.key == pygame.K_UP:
|
|
||||||
self.current_piece.move((0, -self.tile_size))
|
|
||||||
if self.well and self.current_piece.collide(self.well):
|
|
||||||
self.current_piece.revert()
|
|
||||||
if self.stack and self.current_piece.collide(self.stack):
|
|
||||||
self.current_piece.revert()
|
|
||||||
if event.key == pygame.K_DOWN:
|
if event.key == pygame.K_DOWN:
|
||||||
self.current_piece.move((0, self.tile_size))
|
self.current_piece.move((0, self.tile_size))
|
||||||
if self.well and self.current_piece.collide(self.well):
|
if self.well and self.current_piece.collide(self.well):
|
||||||
@@ -104,7 +98,7 @@ class Tetris:
|
|||||||
# TODO write not initialized exception
|
# TODO write not initialized exception
|
||||||
|
|
||||||
# draw window bg
|
# draw window bg
|
||||||
bg_color = pygame.Color(ConfigurationManager.configuration["window"]["bg-color"])
|
bg_color = pygame.Color(ConfigurationManager.configuration["color"]["window-bg"])
|
||||||
self.screen.fill(bg_color)
|
self.screen.fill(bg_color)
|
||||||
|
|
||||||
# draw all game objects
|
# draw all game objects
|
||||||
|
|||||||
17
config.yaml
17
config.yaml
@@ -3,7 +3,6 @@ window:
|
|||||||
height: 600
|
height: 600
|
||||||
icon: "tetris_icon.png"
|
icon: "tetris_icon.png"
|
||||||
title: "Tetris"
|
title: "Tetris"
|
||||||
bg-color: "#6495ED" # cornflower-blue
|
|
||||||
|
|
||||||
sound:
|
sound:
|
||||||
main-music: "main_music.ogg"
|
main-music: "main_music.ogg"
|
||||||
@@ -14,10 +13,14 @@ engine:
|
|||||||
fps: 60
|
fps: 60
|
||||||
tile-size: 20
|
tile-size: 20
|
||||||
|
|
||||||
# https://coolors.co/6495ed-ee6352-59cd90-fac05e-dfd9e2
|
|
||||||
color:
|
color:
|
||||||
base-1: "#EE6352"
|
window-bg: "#000000"
|
||||||
base-2: "#59CD90"
|
piece-1: "#1F37EC"
|
||||||
base-3: "#FAC05E"
|
piece-2: "#3DBBFC"
|
||||||
base-4: "#4C5B5C"
|
piece-3: "#FFFFFF"
|
||||||
border: "#DFD9E2"
|
piece-inner-border-1: "#1F37EC"
|
||||||
|
piece-border-1: "#000000"
|
||||||
|
well-1: "#9BFCF0"
|
||||||
|
well-border-1: "#000000"
|
||||||
|
stack-1: "#747474"
|
||||||
|
stack-border-1: "#000000"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
from pygame import mixer
|
from pygame import mixer
|
||||||
|
import pygame
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from entity.Entity import Entity
|
from entity.Entity import Entity
|
||||||
@@ -11,10 +12,11 @@ from util.ConfigurationManager import ConfigurationManager
|
|||||||
'''
|
'''
|
||||||
class Piece(Entity):
|
class Piece(Entity):
|
||||||
|
|
||||||
GRAVITY = 300 # A move down every 600 ms
|
GRAVITY = 300 # A move down every 300 ms
|
||||||
|
|
||||||
def __init__(self, shape: Tuple, position: Tuple, color: str, border_color: str):
|
def __init__(self, shape: Tuple, position: Tuple, color: str, inner_border_color: str, border_color: str):
|
||||||
super().__init__(self.__get_points(shape, position), color, border_color)
|
super().__init__(self.__get_points(shape, position), color, border_color)
|
||||||
|
self.inner_border_color = inner_border_color
|
||||||
self.center = self.__get_center(shape, position)
|
self.center = self.__get_center(shape, position)
|
||||||
self.piece_set_sound = mixer.Channel(2)
|
self.piece_set_sound = mixer.Channel(2)
|
||||||
|
|
||||||
@@ -34,6 +36,19 @@ class Piece(Entity):
|
|||||||
if stack and self.collide(stack):
|
if stack and self.collide(stack):
|
||||||
self.revert()
|
self.revert()
|
||||||
|
|
||||||
|
def draw(self, surface: pygame.Surface) -> None:
|
||||||
|
super().draw(surface)
|
||||||
|
|
||||||
|
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||||
|
for square in self.points:
|
||||||
|
if self.inner_border_color:
|
||||||
|
vertex_one = (square[0][0] + (tile_size // 10), square[0][1] + (tile_size // 10))
|
||||||
|
vertex_two = (square[1][0] - (tile_size // 10), square[1][1] + (tile_size // 10))
|
||||||
|
vertex_three = (square[2][0] - (tile_size // 10), square[2][1] - (tile_size // 10))
|
||||||
|
vertex_four = (square[3][0] + (tile_size // 10), square[3][1] - (tile_size // 10))
|
||||||
|
new_square = (vertex_one, vertex_two, vertex_three, vertex_four)
|
||||||
|
pygame.draw.polygon(surface, pygame.Color(self.inner_border_color), new_square, max(tile_size // 6, 1))
|
||||||
|
|
||||||
def move(self, vector: Tuple) -> None:
|
def move(self, vector: Tuple) -> None:
|
||||||
# reset elapsed time if user moves down to stall gravity
|
# reset elapsed time if user moves down to stall gravity
|
||||||
if vector[1] > 0:
|
if vector[1] > 0:
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class Well(Entity):
|
|||||||
WIDTH = 10 # standard tetris well width, should not be changed
|
WIDTH = 10 # standard tetris well width, should not be changed
|
||||||
HEIGHT = 20 # standard tetris well height, should not be changed
|
HEIGHT = 20 # standard tetris well height, should not be changed
|
||||||
|
|
||||||
def __init__(self, position: Tuple, color):
|
def __init__(self, position: Tuple, color: str, border_color: str):
|
||||||
super().__init__(self.__get_points(position), color)
|
super().__init__(self.__get_points(position), color, border_color)
|
||||||
|
|
||||||
def __get_points(self, position: Tuple) -> List:
|
def __get_points(self, position: Tuple) -> List:
|
||||||
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||||
|
|||||||
@@ -16,9 +16,8 @@ class PieceGenerator:
|
|||||||
if len(cls.__bucket) == 0:
|
if len(cls.__bucket) == 0:
|
||||||
cls.__generate_bucket()
|
cls.__generate_bucket()
|
||||||
|
|
||||||
border_color = ConfigurationManager.configuration["color"]["border"] # TODO abstract color call to config out?
|
base_color, inner_border_color, border_color = cls.__get_piece_color()
|
||||||
|
return Piece(cls.__get_piece_shape(cls.__bucket.pop()), position, base_color, inner_border_color, border_color)
|
||||||
return Piece(cls.__get_piece_shape(cls.__bucket.pop()), position, cls.__get_piece_color(), border_color)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __generate_bucket(cls) -> None:
|
def __generate_bucket(cls) -> None:
|
||||||
@@ -45,6 +44,11 @@ class PieceGenerator:
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __get_piece_color() -> str:
|
def __get_piece_color() -> Tuple:
|
||||||
random_number = random.randint(1, 3)
|
random_number = random.randint(1, 3)
|
||||||
return ConfigurationManager.configuration["color"]["base-" + str(random_number)]
|
|
||||||
|
base_color = ConfigurationManager.configuration["color"]["piece-" + str(random_number)]
|
||||||
|
inner_border_color = None if random_number != 3 else ConfigurationManager.configuration["color"]["piece-inner-border-1"]
|
||||||
|
border_color = ConfigurationManager.configuration["color"]["piece-border-1"]
|
||||||
|
|
||||||
|
return (base_color, inner_border_color, border_color)
|
||||||
|
|||||||
Reference in New Issue
Block a user