mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
fix(game): flickering
This commit is contained in:
parent
25e56a3482
commit
06fa7c4cf7
@ -6,6 +6,41 @@ class Game:
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.surface = pygame.Surface(CONFIG.game.size)
|
self.surface = pygame.Surface(CONFIG.game.size)
|
||||||
self.dispaly_surface = pygame.display.get_surface()
|
self.dispaly_surface = pygame.display.get_surface()
|
||||||
|
self.rect = self.surface.get_rect(topleft=CONFIG.game.pos)
|
||||||
|
self.surface.fill(CONFIG.colors.bg_float)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.dispaly_surface.blit(self.surface, CONFIG.game.pos)
|
self.dispaly_surface.blit(self.surface, CONFIG.game.pos)
|
||||||
|
|
||||||
|
def draw(self) -> None:
|
||||||
|
self._draw_grid()
|
||||||
|
self._draw_border()
|
||||||
|
|
||||||
|
def _draw_grid(self) -> None:
|
||||||
|
for col in range(1, CONFIG.game.columns):
|
||||||
|
x = col * CONFIG.game.cell_size
|
||||||
|
pygame.draw.line(
|
||||||
|
self.surface,
|
||||||
|
CONFIG.colors.border_highlight,
|
||||||
|
(x, 0),
|
||||||
|
(x, self.surface.get_height()),
|
||||||
|
CONFIG.game.line_width,
|
||||||
|
)
|
||||||
|
for row in range(1, CONFIG.game.rows):
|
||||||
|
y = row * CONFIG.game.cell_size
|
||||||
|
pygame.draw.line(
|
||||||
|
self.surface,
|
||||||
|
CONFIG.colors.border_highlight,
|
||||||
|
(0, y),
|
||||||
|
(self.surface.get_width(), y),
|
||||||
|
CONFIG.game.line_width,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _draw_border(self) -> None:
|
||||||
|
pygame.draw.rect(
|
||||||
|
self.dispaly_surface,
|
||||||
|
CONFIG.colors.border_highlight,
|
||||||
|
self.rect,
|
||||||
|
CONFIG.game.line_width,
|
||||||
|
CONFIG.game.border_radius,
|
||||||
|
)
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class Main:
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption(CONFIG.window.title)
|
pygame.display.set_caption(CONFIG.window.title)
|
||||||
self.display_surface = pygame.display.set_mode(CONFIG.window.size)
|
self.display_surface = pygame.display.set_mode(CONFIG.window.size)
|
||||||
|
self.display_surface.fill(CONFIG.colors.bg)
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
self.game = Game()
|
self.game = Game()
|
||||||
@ -20,8 +21,8 @@ class Main:
|
|||||||
self.preview = Preview()
|
self.preview = Preview()
|
||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
self.display_surface.fill(CONFIG.colors.bg)
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
self.game.draw()
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@ -12,6 +12,7 @@ class Preview:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.dispaly_surface = pygame.display.get_surface()
|
self.dispaly_surface = pygame.display.get_surface()
|
||||||
|
self.surface.fill(CONFIG.colors.bg_sidebar)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.dispaly_surface.blit(self.surface, self.rect)
|
self.dispaly_surface.blit(self.surface, self.rect)
|
||||||
|
|||||||
@ -5,10 +5,11 @@ from utils import CONFIG, Size
|
|||||||
class Score:
|
class Score:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.surface = pygame.Surface(CONFIG.sidebar.score)
|
self.surface = pygame.Surface(CONFIG.sidebar.score)
|
||||||
|
self.dispaly_surface = pygame.display.get_surface()
|
||||||
self.rect = self.surface.get_rect(
|
self.rect = self.surface.get_rect(
|
||||||
bottomright=CONFIG.window.size.sub(CONFIG.window.padding)
|
bottomright=CONFIG.window.size.sub(CONFIG.window.padding)
|
||||||
)
|
)
|
||||||
self.dispaly_surface = pygame.display.get_surface()
|
self.surface.fill(CONFIG.colors.bg_sidebar)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.dispaly_surface.blit(self.surface, self.rect)
|
self.dispaly_surface.blit(self.surface, self.rect)
|
||||||
|
|||||||
@ -41,6 +41,8 @@ class Position(NamedTuple):
|
|||||||
class Game:
|
class Game:
|
||||||
columns: int = 10
|
columns: int = 10
|
||||||
rows: int = 20
|
rows: int = 20
|
||||||
|
line_width: int = 1
|
||||||
|
border_radius: int = 2
|
||||||
padding: int = PADDING
|
padding: int = PADDING
|
||||||
cell_size: int = 40
|
cell_size: int = 40
|
||||||
size: Size = Size(columns * cell_size, rows * cell_size)
|
size: Size = Size(columns * cell_size, rows * cell_size)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user