|
|
@@ -8,7 +8,7 @@ import pygame
|
|
|
import jogai
|
|
|
import jogai._globals as _globals
|
|
|
import jogai.settings as settings
|
|
|
-from jogai import character, group, logger, scene, utils
|
|
|
+from jogai import character, group, logger, scene, texts, utils
|
|
|
from jogai.translations import gettext as _
|
|
|
from jogai.utils import _get_events, _get_keys
|
|
|
|
|
|
@@ -165,6 +165,22 @@ def add_group(new_group: 'group.SquareGroup'):
|
|
|
_globals.vg_groups.append(new_group)
|
|
|
|
|
|
|
|
|
+def add_text(new_text: 'texts.Text'):
|
|
|
+ """
|
|
|
+ Add a new text to the videogame.
|
|
|
+
|
|
|
+ Parameters:
|
|
|
+ new_text: the text to be added
|
|
|
+
|
|
|
+ Examples:
|
|
|
+ >>> text = texts.Text('Test')
|
|
|
+ >>> add_text(text) # doctest: +SKIP
|
|
|
+ """
|
|
|
+ if not isinstance(new_text, texts.Text):
|
|
|
+ raise TypeError(_('Only Group instances can be added.'))
|
|
|
+ _globals.vg_texts.append(new_text)
|
|
|
+
|
|
|
+
|
|
|
def init():
|
|
|
"""
|
|
|
Start the pygame engine if it is not started.
|
|
|
@@ -239,7 +255,11 @@ def get_color(x: int, y: int) -> Tuple[int, int, int]:
|
|
|
return tuple(_globals._window.get_at((x, y))[:-1])
|
|
|
|
|
|
|
|
|
-def paint(sprite: Type['scene.Scene'] | Type['character.Character']):
|
|
|
+def paint(
|
|
|
+ sprite: Type['scene.Scene']
|
|
|
+ | Type['character.Character']
|
|
|
+ | Type['texts.Text'],
|
|
|
+):
|
|
|
"""
|
|
|
Paint both a scene and a character.
|
|
|
|
|
|
@@ -249,7 +269,7 @@ def paint(sprite: Type['scene.Scene'] | Type['character.Character']):
|
|
|
# TODO: check sprite type
|
|
|
if hasattr(sprite, 'background'):
|
|
|
_globals._window.fill(sprite.background)
|
|
|
- if sprite.image and sprite.rect:
|
|
|
+ if hasattr(sprite, 'image') and hasattr(sprite, 'rect'):
|
|
|
_globals._window.blit(sprite.image, sprite.rect)
|
|
|
|
|
|
|
|
|
@@ -352,11 +372,14 @@ def update():
|
|
|
paint(vg_character)
|
|
|
vg_character.update()
|
|
|
if _globals.vg_groups:
|
|
|
- for g in _globals.vg_groups:
|
|
|
- for e in g.sprites():
|
|
|
- e._update_rect_position()
|
|
|
- paint(e)
|
|
|
- e.update()
|
|
|
+ for group_item in _globals.vg_groups:
|
|
|
+ for sprite_item in group_item.sprites():
|
|
|
+ sprite_item._update_rect_position()
|
|
|
+ paint(sprite_item)
|
|
|
+ sprite_item.update()
|
|
|
+ if _globals.vg_texts:
|
|
|
+ for text_item in _globals.vg_texts:
|
|
|
+ paint(text_item)
|
|
|
if _globals.marks:
|
|
|
_globals.marks.draw()
|
|
|
pygame.display.flip()
|