mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
refactor(game): add image property
This commit is contained in:
parent
822dd60bc1
commit
a578731b65
@ -14,17 +14,18 @@ class FigureConfig(NamedTuple):
|
|||||||
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.
|
||||||
image: The image of the figure.
|
image: The image of the figure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
shape: list[Vec2]
|
shape: list[Vec2]
|
||||||
color: str
|
color: str
|
||||||
image: pygame.Surface
|
filename: str
|
||||||
|
|
||||||
|
@property
|
||||||
def _load_image(filename: str) -> pygame.Surface:
|
def image(self) -> pygame.Surface:
|
||||||
return pygame.image.load(BASE_PATH / "assets" / "figures" / filename) # TODO: add `.convert_alpha()``
|
|
||||||
# TODO: change colors of images
|
# TODO: change colors of images
|
||||||
|
return pygame.image.load(BASE_PATH / "assets" / "figures" / self.filename).convert_alpha()
|
||||||
|
|
||||||
|
|
||||||
class Figure(Enum):
|
class Figure(Enum):
|
||||||
@ -47,7 +48,7 @@ class Figure(Enum):
|
|||||||
Vec2(0, 1),
|
Vec2(0, 1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().cyan,
|
TokyoNightNight().cyan,
|
||||||
_load_image("I.png"),
|
"I.png",
|
||||||
)
|
)
|
||||||
O = FigureConfig(
|
O = FigureConfig(
|
||||||
[
|
[
|
||||||
@ -57,7 +58,7 @@ class Figure(Enum):
|
|||||||
Vec2(1, -1),
|
Vec2(1, -1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().yellow,
|
TokyoNightNight().yellow,
|
||||||
_load_image("O.png"),
|
"O.png",
|
||||||
)
|
)
|
||||||
T = FigureConfig(
|
T = FigureConfig(
|
||||||
[
|
[
|
||||||
@ -67,7 +68,7 @@ class Figure(Enum):
|
|||||||
Vec2(0, -1),
|
Vec2(0, -1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().purple,
|
TokyoNightNight().purple,
|
||||||
_load_image("T.png"),
|
"T.png",
|
||||||
)
|
)
|
||||||
|
|
||||||
S = FigureConfig(
|
S = FigureConfig(
|
||||||
@ -78,7 +79,7 @@ class Figure(Enum):
|
|||||||
Vec2(1, -1),
|
Vec2(1, -1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().green,
|
TokyoNightNight().green,
|
||||||
_load_image("S.png"),
|
"S.png",
|
||||||
)
|
)
|
||||||
Z = FigureConfig(
|
Z = FigureConfig(
|
||||||
[
|
[
|
||||||
@ -88,7 +89,7 @@ class Figure(Enum):
|
|||||||
Vec2(-1, -1),
|
Vec2(-1, -1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().red,
|
TokyoNightNight().red,
|
||||||
_load_image("Z.png"),
|
"Z.png",
|
||||||
)
|
)
|
||||||
J = FigureConfig(
|
J = FigureConfig(
|
||||||
[
|
[
|
||||||
@ -98,7 +99,7 @@ class Figure(Enum):
|
|||||||
Vec2(-1, 1),
|
Vec2(-1, 1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().blue,
|
TokyoNightNight().blue,
|
||||||
_load_image("J.png"),
|
"J.png",
|
||||||
)
|
)
|
||||||
L = FigureConfig(
|
L = FigureConfig(
|
||||||
[
|
[
|
||||||
@ -108,7 +109,7 @@ class Figure(Enum):
|
|||||||
Vec2(1, 1),
|
Vec2(1, 1),
|
||||||
],
|
],
|
||||||
TokyoNightNight().orange,
|
TokyoNightNight().orange,
|
||||||
_load_image("L.png"),
|
"L.png",
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user