Improve help menu
This commit is contained in:
@@ -435,14 +435,14 @@ class Game:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@lru_cache(maxsize=1)
|
@lru_cache(maxsize=1)
|
||||||
def make_help_string(am: dict[int, Action]):
|
def make_action_help_string(am: dict[int, Action]):
|
||||||
key_names = [pygame.key.name(k) for k in am.keys()]
|
key_names = [pygame.key.name(k) for k in am.keys()]
|
||||||
max_key_len = max(map(len, key_names))
|
max_key_len = max(map(len, key_names))
|
||||||
out = ""
|
out = "Keys:"
|
||||||
for act in am.values():
|
for act in am.values():
|
||||||
if out:
|
out += (
|
||||||
out += "\n"
|
f"\n{pygame.key.name(act.key).rjust(max_key_len)}: {act.desc}"
|
||||||
out += f"{pygame.key.name(act.key).rjust(max_key_len)}: {act.desc}"
|
)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -450,6 +450,20 @@ class Game:
|
|||||||
self.high_score = 0
|
self.high_score = 0
|
||||||
self._score = 0
|
self._score = 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@lru_cache(maxsize=1)
|
||||||
|
def make_score_help_string():
|
||||||
|
return (
|
||||||
|
"Points:\n"
|
||||||
|
"10 lines clear to level up.\n"
|
||||||
|
f"Soft drop: {Game.DROP_POINTS} * dist. * level\n"
|
||||||
|
f"Hard drop: {Game.HARD_DROP_POINTS} * dist. * level\n"
|
||||||
|
f" 1 line: {Game.POINTS_PER_LINE[0]} * level\n"
|
||||||
|
f" 2 lines: {Game.POINTS_PER_LINE[1]} * level\n"
|
||||||
|
f" 3 lines: {Game.POINTS_PER_LINE[2]} * level\n"
|
||||||
|
f" 4 lines: {Game.POINTS_PER_LINE[3]} * level\n"
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def game_over(self) -> bool:
|
def game_over(self) -> bool:
|
||||||
return self._game_over
|
return self._game_over
|
||||||
@@ -831,6 +845,7 @@ class Game:
|
|||||||
"Press <h> \nfor help\nor pause.\n"
|
"Press <h> \nfor help\nor pause.\n"
|
||||||
"\n"
|
"\n"
|
||||||
f"Level: {self.level:02}\n"
|
f"Level: {self.level:02}\n"
|
||||||
|
f"Lines: {self.cleared_this_level:02}\n"
|
||||||
f"Score: {self.score:05}\n"
|
f"Score: {self.score:05}\n"
|
||||||
f" HS: {self.high_score:05}"
|
f" HS: {self.high_score:05}"
|
||||||
)
|
)
|
||||||
@@ -927,7 +942,11 @@ class Game:
|
|||||||
def process_and_draw_help_overlay(self):
|
def process_and_draw_help_overlay(self):
|
||||||
self.draw_gray_overlay()
|
self.draw_gray_overlay()
|
||||||
|
|
||||||
hs = Game.make_help_string(Game.GAME_ACTION_MAP)
|
hs = (
|
||||||
|
Game.make_action_help_string(Game.GAME_ACTION_MAP)
|
||||||
|
+ "\n\n"
|
||||||
|
+ Game.make_score_help_string()
|
||||||
|
)
|
||||||
exts = Game.TINY_FONT.compute_extents(hs)
|
exts = Game.TINY_FONT.compute_extents(hs)
|
||||||
|
|
||||||
sw, sh = self.screen.get_size()
|
sw, sh = self.screen.get_size()
|
||||||
@@ -1589,6 +1608,16 @@ GLYPH_DATA = [
|
|||||||
"* ",
|
"* ",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Font.Glyph(
|
||||||
|
"*",
|
||||||
|
[
|
||||||
|
" ",
|
||||||
|
"* *",
|
||||||
|
" * ",
|
||||||
|
"* *",
|
||||||
|
" ",
|
||||||
|
],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user