|
|
@@ -42,6 +42,23 @@ def _load_scene(data: dict) -> 'scene.Scene':
|
|
|
return scene.Scene()
|
|
|
|
|
|
|
|
|
+def _load_attributes(data: dict):
|
|
|
+ """
|
|
|
+ Load attributes from data schema.
|
|
|
+
|
|
|
+ Parameters:
|
|
|
+ data: input schema
|
|
|
+ """
|
|
|
+ if _('attributes') in data:
|
|
|
+ attributes = data[_('attributes')]
|
|
|
+ if not isinstance(attributes, dict):
|
|
|
+ raise TypeError(
|
|
|
+ _('The attributes in the input schema must be a dict.')
|
|
|
+ )
|
|
|
+ if _('gravity') in attributes:
|
|
|
+ set_gravity(attributes[_('gravity')])
|
|
|
+
|
|
|
+
|
|
|
def _load_characters(data: dict) -> list:
|
|
|
"""
|
|
|
Load characters from data schema.
|
|
|
@@ -235,13 +252,28 @@ def paint_group(group: Type['group.SquareGroup']):
|
|
|
group.draw(_globals._window)
|
|
|
|
|
|
|
|
|
+def set_gravity(gravity: int):
|
|
|
+ """
|
|
|
+ Set the gravity in the videogame.
|
|
|
+
|
|
|
+ Parameters:
|
|
|
+ gravity: Gravity force to be setted.
|
|
|
+
|
|
|
+ Examples:
|
|
|
+ >>> set_gravity(5)
|
|
|
+ """
|
|
|
+ if not isinstance(gravity, int):
|
|
|
+ raise TypeError(_('The gravity must be an integer.'))
|
|
|
+ _globals._gravity = gravity
|
|
|
+
|
|
|
+
|
|
|
def set_marks(
|
|
|
- x_gap=0,
|
|
|
- y_gap=0,
|
|
|
- x_color=(255, 180, 30),
|
|
|
- y_color=(0, 0, 255),
|
|
|
- width=1,
|
|
|
- debug=False,
|
|
|
+ x_gap: int = 0,
|
|
|
+ y_gap: int = 0,
|
|
|
+ x_color: tuple = (255, 180, 30),
|
|
|
+ y_color: tuple = (0, 0, 255),
|
|
|
+ width: int = 1,
|
|
|
+ debug: bool = False,
|
|
|
):
|
|
|
_globals.marks = utils.Marks(x_gap, y_gap, x_color, y_color, width, debug)
|
|
|
|
|
|
@@ -264,6 +296,7 @@ def prepare(data_filename: str = ''):
|
|
|
|
|
|
_globals.vg_scene = _load_scene(vg_data)
|
|
|
_globals.vg_characters = _load_characters(vg_data)
|
|
|
+ _globals.vg_attributes = _load_attributes(vg_data)
|
|
|
|
|
|
if _globals.vg_characters:
|
|
|
_globals.character_focus = _globals.vg_characters[0]
|
|
|
@@ -303,6 +336,7 @@ def update():
|
|
|
for e in g.sprites():
|
|
|
e._update_rect_position()
|
|
|
paint(e)
|
|
|
+ e.update()
|
|
|
if _globals.marks:
|
|
|
_globals.marks.draw()
|
|
|
pygame.display.flip()
|