Merge branch 'preview'

This commit is contained in:
Kristofers Solo 2024-01-15 07:01:51 +02:00
commit a8748a69a2
10 changed files with 18 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -30,7 +30,7 @@ class Preview(BaseScreen, SceenElement):
Args:
next_figures: Next figure.
"""
self.next_figure = next_figure
self.next_figure: Figure = next_figure
def draw(self) -> None:
"""Draw the preview on the preview surface."""
@ -51,9 +51,10 @@ class Preview(BaseScreen, SceenElement):
def _draw_figure(self) -> None:
"""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
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))
self.surface.blit(figure_surface, rect)

View File

@ -1,6 +1,6 @@
from .config import CONFIG
from .enum import Direction, GameMode, Rotation
from .figure import Figure, FigureConfig
from .figure import Figure
from .path import BASE_PATH
from .settings import read_settings, save_settings
from .tuples import Size
@ -10,7 +10,6 @@ __all__ = [
"CONFIG",
"Size",
"Figure",
"FigureConfig",
"Direction",
"Rotation",
"GameMode",

View File

@ -1,30 +1,32 @@
import random
from enum import Enum
from typing import NamedTuple
import pygame
from attrs import define
from pygame import Vector2 as Vec2
from .config import CONFIG
from .path import BASE_PATH
class FigureConfig(NamedTuple):
@define
class FigureParams:
"""
Attributes:
shape: The shape of the figure.
color: The color of the figure.
filename: The filename of the image of the figure.
image: The image of the figure.
"""
shape: list[Vec2]
color: str
filename: str
@property
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()
@ -40,7 +42,7 @@ class Figure(Enum):
L: The L figure.
"""
I = FigureConfig(
I = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(0, -1),
@ -50,7 +52,7 @@ class Figure(Enum):
CONFIG.colors.cyan,
"I.png",
)
O = FigureConfig(
O = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(0, -1),
@ -60,7 +62,7 @@ class Figure(Enum):
CONFIG.colors.yellow,
"O.png",
)
T = FigureConfig(
T = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(-1, 0),
@ -71,7 +73,7 @@ class Figure(Enum):
"T.png",
)
S = FigureConfig(
S = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(-1, 0),
@ -81,7 +83,7 @@ class Figure(Enum):
CONFIG.colors.green,
"S.png",
)
Z = FigureConfig(
Z = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(1, 0),
@ -91,7 +93,7 @@ class Figure(Enum):
CONFIG.colors.red,
"Z.png",
)
J = FigureConfig(
J = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(0, -1),
@ -101,7 +103,7 @@ class Figure(Enum):
CONFIG.colors.blue,
"J.png",
)
L = FigureConfig(
L = FigureParams( # type: ignore
[
Vec2(0, 0),
Vec2(0, -1),