Merge branch 'preview'
|
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 371 B After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 371 B After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 321 B After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 321 B After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 320 B After Width: | Height: | Size: 4.3 KiB |
@ -30,7 +30,7 @@ class Preview(BaseScreen, SceenElement):
|
|||||||
Args:
|
Args:
|
||||||
next_figures: Next figure.
|
next_figures: Next figure.
|
||||||
"""
|
"""
|
||||||
self.next_figure = next_figure
|
self.next_figure: Figure = next_figure
|
||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
"""Draw the preview on the preview surface."""
|
"""Draw the preview on the preview surface."""
|
||||||
@ -51,9 +51,10 @@ class Preview(BaseScreen, SceenElement):
|
|||||||
|
|
||||||
def _draw_figure(self) -> None:
|
def _draw_figure(self) -> None:
|
||||||
"""Draw a single upcoming figure on the preview surface."""
|
"""Draw a single upcoming figure on the preview surface."""
|
||||||
figure_surface = self.next_figure.value.image
|
figure_surface: pygame.Surface = self.next_figure.value.image()
|
||||||
x = self.surface.get_width() / 2
|
x = self.surface.get_width() / 2
|
||||||
y = self.surface.get_height() / 2
|
y = self.surface.get_height() / 2
|
||||||
|
figure_surface.fill(self.next_figure.value.color, special_flags=pygame.BLEND_RGB_MULT)
|
||||||
rect = figure_surface.get_rect(center=(x, y))
|
rect = figure_surface.get_rect(center=(x, y))
|
||||||
self.surface.blit(figure_surface, rect)
|
self.surface.blit(figure_surface, rect)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from .config import CONFIG
|
from .config import CONFIG
|
||||||
from .enum import Direction, GameMode, Rotation
|
from .enum import Direction, GameMode, Rotation
|
||||||
from .figure import Figure, FigureConfig
|
from .figure import Figure
|
||||||
from .path import BASE_PATH
|
from .path import BASE_PATH
|
||||||
from .settings import read_settings, save_settings
|
from .settings import read_settings, save_settings
|
||||||
from .tuples import Size
|
from .tuples import Size
|
||||||
@ -10,7 +10,6 @@ __all__ = [
|
|||||||
"CONFIG",
|
"CONFIG",
|
||||||
"Size",
|
"Size",
|
||||||
"Figure",
|
"Figure",
|
||||||
"FigureConfig",
|
|
||||||
"Direction",
|
"Direction",
|
||||||
"Rotation",
|
"Rotation",
|
||||||
"GameMode",
|
"GameMode",
|
||||||
|
|||||||
@ -1,30 +1,32 @@
|
|||||||
import random
|
import random
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import NamedTuple
|
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
from attrs import define
|
||||||
from pygame import Vector2 as Vec2
|
from pygame import Vector2 as Vec2
|
||||||
|
|
||||||
from .config import CONFIG
|
from .config import CONFIG
|
||||||
from .path import BASE_PATH
|
from .path import BASE_PATH
|
||||||
|
|
||||||
|
|
||||||
class FigureConfig(NamedTuple):
|
@define
|
||||||
|
class FigureParams:
|
||||||
"""
|
"""
|
||||||
Attributes:
|
Attributes:
|
||||||
shape: The shape of the figure.
|
shape: The shape of the figure.
|
||||||
color: The color of the figure.
|
color: The color of the figure.
|
||||||
filename: The filename of the image of the figure.
|
filename: The filename of the image of the figure.
|
||||||
image: The image of the figure.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
shape: list[Vec2]
|
shape: list[Vec2]
|
||||||
color: str
|
color: str
|
||||||
filename: str
|
filename: str
|
||||||
|
|
||||||
@property
|
|
||||||
def image(self) -> pygame.Surface:
|
def image(self) -> pygame.Surface:
|
||||||
# TODO: change colors of images
|
"""
|
||||||
|
Returns:
|
||||||
|
The image of the figure.
|
||||||
|
"""
|
||||||
return pygame.image.load(BASE_PATH / "assets" / "figures" / self.filename).convert_alpha()
|
return pygame.image.load(BASE_PATH / "assets" / "figures" / self.filename).convert_alpha()
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ class Figure(Enum):
|
|||||||
L: The L figure.
|
L: The L figure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
I = FigureConfig(
|
I = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(0, -1),
|
Vec2(0, -1),
|
||||||
@ -50,7 +52,7 @@ class Figure(Enum):
|
|||||||
CONFIG.colors.cyan,
|
CONFIG.colors.cyan,
|
||||||
"I.png",
|
"I.png",
|
||||||
)
|
)
|
||||||
O = FigureConfig(
|
O = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(0, -1),
|
Vec2(0, -1),
|
||||||
@ -60,7 +62,7 @@ class Figure(Enum):
|
|||||||
CONFIG.colors.yellow,
|
CONFIG.colors.yellow,
|
||||||
"O.png",
|
"O.png",
|
||||||
)
|
)
|
||||||
T = FigureConfig(
|
T = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(-1, 0),
|
Vec2(-1, 0),
|
||||||
@ -71,7 +73,7 @@ class Figure(Enum):
|
|||||||
"T.png",
|
"T.png",
|
||||||
)
|
)
|
||||||
|
|
||||||
S = FigureConfig(
|
S = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(-1, 0),
|
Vec2(-1, 0),
|
||||||
@ -81,7 +83,7 @@ class Figure(Enum):
|
|||||||
CONFIG.colors.green,
|
CONFIG.colors.green,
|
||||||
"S.png",
|
"S.png",
|
||||||
)
|
)
|
||||||
Z = FigureConfig(
|
Z = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(1, 0),
|
Vec2(1, 0),
|
||||||
@ -91,7 +93,7 @@ class Figure(Enum):
|
|||||||
CONFIG.colors.red,
|
CONFIG.colors.red,
|
||||||
"Z.png",
|
"Z.png",
|
||||||
)
|
)
|
||||||
J = FigureConfig(
|
J = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(0, -1),
|
Vec2(0, -1),
|
||||||
@ -101,7 +103,7 @@ class Figure(Enum):
|
|||||||
CONFIG.colors.blue,
|
CONFIG.colors.blue,
|
||||||
"J.png",
|
"J.png",
|
||||||
)
|
)
|
||||||
L = FigureConfig(
|
L = FigureParams( # type: ignore
|
||||||
[
|
[
|
||||||
Vec2(0, 0),
|
Vec2(0, 0),
|
||||||
Vec2(0, -1),
|
Vec2(0, -1),
|
||||||
|
|||||||