mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): add Preview surface
This commit is contained in:
parent
9767d54424
commit
25e56a3482
@ -4,6 +4,7 @@ import pygame
|
|||||||
from utils import CONFIG
|
from utils import CONFIG
|
||||||
|
|
||||||
from .game import Game
|
from .game import Game
|
||||||
|
from .preview import Preview
|
||||||
from .score import Score
|
from .score import Score
|
||||||
|
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ class Main:
|
|||||||
|
|
||||||
self.game = Game()
|
self.game = Game()
|
||||||
self.score = Score()
|
self.score = Score()
|
||||||
|
self.preview = Preview()
|
||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
self.display_surface.fill(CONFIG.colors.bg)
|
self.display_surface.fill(CONFIG.colors.bg)
|
||||||
@ -28,6 +30,7 @@ class Main:
|
|||||||
|
|
||||||
self.game.run()
|
self.game.run()
|
||||||
self.score.run()
|
self.score.run()
|
||||||
|
self.preview.run()
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(CONFIG.fps)
|
self.clock.tick(CONFIG.fps)
|
||||||
|
|||||||
17
src/game/preview.py
Normal file
17
src/game/preview.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import pygame
|
||||||
|
from utils import CONFIG, Size
|
||||||
|
|
||||||
|
|
||||||
|
class Preview:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.surface = pygame.Surface(CONFIG.sidebar.preview)
|
||||||
|
self.rect = self.surface.get_rect(
|
||||||
|
topright=(
|
||||||
|
CONFIG.window.size.width - CONFIG.window.padding,
|
||||||
|
CONFIG.window.padding,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.dispaly_surface = pygame.display.get_surface()
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
self.dispaly_surface.blit(self.surface, self.rect)
|
||||||
@ -49,8 +49,9 @@ class Game:
|
|||||||
|
|
||||||
@define
|
@define
|
||||||
class SideBar:
|
class SideBar:
|
||||||
|
padding: int = PADDING
|
||||||
size: Size = Size(200, Game().size.height)
|
size: Size = Size(200, Game().size.height)
|
||||||
score: Size = Size(size.width, size.height * 0.3)
|
score: Size = Size(size.width, size.height * 0.3 - padding)
|
||||||
preview: Size = Size(size.width, size.height * 0.7)
|
preview: Size = Size(size.width, size.height * 0.7)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user