|
@@ -5,6 +5,7 @@ import pygame
|
|
|
from jogai import _globals, settings
|
|
from jogai import _globals, settings
|
|
|
from jogai.translations import gettext as _
|
|
from jogai.translations import gettext as _
|
|
|
|
|
|
|
|
|
|
+
|
|
|
class Text:
|
|
class Text:
|
|
|
def __init__(
|
|
def __init__(
|
|
|
self,
|
|
self,
|
|
@@ -17,6 +18,8 @@ class Text:
|
|
|
italic: bool = False,
|
|
italic: bool = False,
|
|
|
shadow: tuple = (),
|
|
shadow: tuple = (),
|
|
|
):
|
|
):
|
|
|
|
|
+ if not pygame.font.get_init():
|
|
|
|
|
+ pygame.font.init()
|
|
|
self.color = color
|
|
self.color = color
|
|
|
self.font = pygame.font.Font(join(settings.FONTS_DIR, font), size)
|
|
self.font = pygame.font.Font(join(settings.FONTS_DIR, font), size)
|
|
|
self.font.set_bold(bold)
|
|
self.font.set_bold(bold)
|
|
@@ -47,7 +50,6 @@ class Text:
|
|
|
self.rect = self.image.get_rect()
|
|
self.rect = self.image.get_rect()
|
|
|
self.rect.x, self.rect.y = position
|
|
self.rect.x, self.rect.y = position
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def set_message(self, message: str, key: str = ''):
|
|
def set_message(self, message: str, key: str = ''):
|
|
|
"""
|
|
"""
|
|
|
Set a new message for the text.
|
|
Set a new message for the text.
|
|
@@ -83,7 +85,7 @@ class Scoreboard(Text):
|
|
|
raise TypeError(_('The prefix text must be a string.'))
|
|
raise TypeError(_('The prefix text must be a string.'))
|
|
|
super().__init__(**kwargs)
|
|
super().__init__(**kwargs)
|
|
|
self._prefix = prefix
|
|
self._prefix = prefix
|
|
|
- self.set(score)
|
|
|
|
|
|
|
+ self.set_score(score)
|
|
|
if 'position' in kwargs:
|
|
if 'position' in kwargs:
|
|
|
self.render(position=kwargs['position'])
|
|
self.render(position=kwargs['position'])
|
|
|
else:
|
|
else:
|
|
@@ -106,7 +108,7 @@ class Scoreboard(Text):
|
|
|
def message(self):
|
|
def message(self):
|
|
|
return self._message
|
|
return self._message
|
|
|
|
|
|
|
|
- def set(self, score: int):
|
|
|
|
|
|
|
+ def set_score(self, score: int):
|
|
|
"""
|
|
"""
|
|
|
Set the character score.
|
|
Set the character score.
|
|
|
|
|
|
|
@@ -120,10 +122,10 @@ class Scoreboard(Text):
|
|
|
if not isinstance(score, int):
|
|
if not isinstance(score, int):
|
|
|
raise TypeError(_('Score must be an integer.'))
|
|
raise TypeError(_('Score must be an integer.'))
|
|
|
self._score = score
|
|
self._score = score
|
|
|
- self._message = f'{self._prefix}{self.score}'
|
|
|
|
|
|
|
+ self._message = f'{self._prefix}{self._score}'
|
|
|
self.render()
|
|
self.render()
|
|
|
|
|
|
|
|
- def add(self, score: int):
|
|
|
|
|
|
|
+ def add_score(self, score: int):
|
|
|
"""
|
|
"""
|
|
|
Increment the character score.
|
|
Increment the character score.
|
|
|
|
|
|
|
@@ -132,11 +134,11 @@ class Scoreboard(Text):
|
|
|
|
|
|
|
|
Examples:
|
|
Examples:
|
|
|
>>> scoreboard = Scoreboard('My character: ')
|
|
>>> scoreboard = Scoreboard('My character: ')
|
|
|
- >>> scoreboard.add(5)
|
|
|
|
|
|
|
+ >>> scoreboard.add_score(5)
|
|
|
"""
|
|
"""
|
|
|
if not isinstance(score, int):
|
|
if not isinstance(score, int):
|
|
|
raise TypeError(_('Score must be an integer.'))
|
|
raise TypeError(_('Score must be an integer.'))
|
|
|
- self.score += score
|
|
|
|
|
|
|
+ self._score += score
|
|
|
|
|
|
|
|
|
|
|
|
|
class LevelBar(pygame.Surface):
|
|
class LevelBar(pygame.Surface):
|
|
@@ -207,13 +209,15 @@ class LevelBar(pygame.Surface):
|
|
|
increase: amount to increase
|
|
increase: amount to increase
|
|
|
|
|
|
|
|
Examples:
|
|
Examples:
|
|
|
- >>> lifes = LevelBar(5)
|
|
|
|
|
|
|
+ >>> lifes = LevelBar(5, 2)
|
|
|
>>> lifes.increase(1)
|
|
>>> lifes.increase(1)
|
|
|
"""
|
|
"""
|
|
|
if not isinstance(increase, int):
|
|
if not isinstance(increase, int):
|
|
|
raise TypeError(_('The increase level must be an integer.'))
|
|
raise TypeError(_('The increase level must be an integer.'))
|
|
|
if self._level + increase > self._parts:
|
|
if self._level + increase > self._parts:
|
|
|
- raise ValueError(_('The increase cannot exceed the maximum level.'))
|
|
|
|
|
|
|
+ raise ValueError(
|
|
|
|
|
+ _('The increase cannot exceed the maximum level.')
|
|
|
|
|
+ )
|
|
|
self.set(self._level + increase)
|
|
self.set(self._level + increase)
|
|
|
|
|
|
|
|
def set(self, level):
|
|
def set(self, level):
|
|
@@ -266,7 +270,7 @@ class LevelBar(pygame.Surface):
|
|
|
_globals._window,
|
|
_globals._window,
|
|
|
self.border_color,
|
|
self.border_color,
|
|
|
(position[0] + division * part, position[1]),
|
|
(position[0] + division * part, position[1]),
|
|
|
- (position[0] + division * (part+1), position[1]),
|
|
|
|
|
|
|
+ (position[0] + division * (part + 1), position[1]),
|
|
|
self._thick,
|
|
self._thick,
|
|
|
)
|
|
)
|
|
|
# inside
|
|
# inside
|
|
@@ -276,10 +280,11 @@ class LevelBar(pygame.Surface):
|
|
|
self.fill_color,
|
|
self.fill_color,
|
|
|
(
|
|
(
|
|
|
position[0] + division * part + self._thick / 2,
|
|
position[0] + division * part + self._thick / 2,
|
|
|
- position[1] + int(self._height / 2)),
|
|
|
|
|
|
|
+ position[1] + int(self._height / 2),
|
|
|
|
|
+ ),
|
|
|
(
|
|
(
|
|
|
position[0] + division * (part + 1) - self._thick / 2,
|
|
position[0] + division * (part + 1) - self._thick / 2,
|
|
|
- position[1] + int(self._height / 2)
|
|
|
|
|
|
|
+ position[1] + int(self._height / 2),
|
|
|
),
|
|
),
|
|
|
self._height,
|
|
self._height,
|
|
|
)
|
|
)
|
|
@@ -288,7 +293,10 @@ class LevelBar(pygame.Surface):
|
|
|
_globals._window,
|
|
_globals._window,
|
|
|
self.border_color,
|
|
self.border_color,
|
|
|
(position[0] + division * part, position[1] + self._height),
|
|
(position[0] + division * part, position[1] + self._height),
|
|
|
- (position[0] + division * (part + 1), position[1] + self._height),
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ position[0] + division * (part + 1),
|
|
|
|
|
+ position[1] + self._height,
|
|
|
|
|
+ ),
|
|
|
self._thick,
|
|
self._thick,
|
|
|
)
|
|
)
|
|
|
self.rect = self.get_rect()
|
|
self.rect = self.get_rect()
|