commit 33843b4f12a12ff074942dc7ce13bf1f74d5f261
parent 32e1f5d39adee9d23a576e9d1c7a20eeee72d07a
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sat, 30 Jan 2021 01:48:00 -0600
added delay and camera move scene effects
Diffstat:
3 files changed, 101 insertions(+), 8 deletions(-)
diff --git a/data/json/scenes/testdia.json b/data/json/scenes/testdia.json
@@ -7,6 +7,38 @@
"bg_sprite" : null,
"script" : [
{
+ "speaker" : "",
+ "name_font" : "A",
+ "name_pos" : [20, 480],
+ "line_font" : "A",
+ "voice" : null,
+ "portrait" : null,
+ "line" : "",
+ "characters" : [ ],
+ "effects" : [
+ {
+ "call" : "ef_scene_delay",
+ "data" : 60
+ }
+ ]
+ },
+ {
+ "speaker" : "",
+ "name_font" : "A",
+ "name_pos" : [20, 480],
+ "line_font" : "A",
+ "voice" : null,
+ "portrait" : null,
+ "line" : "",
+ "characters" : [ ],
+ "effects" : [
+ {
+ "call" : "ef_scene_scroll_camera",
+ "data" : [0, 3, 20]
+ }
+ ]
+ },
+ {
"speaker" : "Jisella",
"name_font" : "A",
"name_pos" : [20, 480],
diff --git a/src/constants.py b/src/constants.py
@@ -92,7 +92,7 @@ STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Base_Mode Battle_Mode Sti
CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Base_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Turn_Watch_Guard Battle_Dialog Battle_Intro Still_Scene_Normal')
FACE_DIR = enum.Enum('FACE_DIR', 'U D L R')
GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_dummy ef_game_quit ef_game_switch_mode ef_game_switch_control')
-SCENE_EFFECTS = enum.Enum('SCENE_EFFECTS', 'ef_scene_dummy ef_scene_fade')
+SCENE_EFFECTS = enum.Enum('SCENE_EFFECTS', 'ef_scene_dummy ef_scene_delay ef_scene_fade ef_scene_scroll_camera ef_scene_snap_camera ef_scene_spawn_piece')
TEAMS = enum.Enum('TEAMS', 'Player Ally Neutral Enemy Other')
ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness resist riposte ignoredef parry block sweep miss onetwo stun')
diff --git a/src/scene.py b/src/scene.py
@@ -44,7 +44,9 @@ class SceneManager(manager.Manager):
"""
SceneManager-only effects for trigger_effects.
"""
- if effect["call"] == SCENE_EFFECTS.ef_scene_fade.name:
+ if effect["call"] == SCENE_EFFECTS.ef_scene_delay.name:
+ self.current_scene.setup_delay(effect["data"])
+ elif effect["call"] == SCENE_EFFECTS.ef_scene_fade.name:
posmap = { "SW" : SCREEN_WIDTH, "SH" : SCREEN_HEIGHT, "-SW" : - SCREEN_WIDTH, "-SH" : - SCREEN_HEIGHT }
ind = 0
for d in effect["data"]:
@@ -58,7 +60,12 @@ class SceneManager(manager.Manager):
xmov = effect["data"][3]
ymov = effect["data"][4]
timer = effect["data"][5]
- self.current_scene.setup_fade_effect(fade_surface, fade_surface_rect, xmov, ymov, timer)
+ self.current_scene.setup_fade(fade_surface, fade_surface_rect, xmov, ymov, timer)
+ elif effect["call"] == SCENE_EFFECTS.ef_scene_scroll_camera.name:
+ xoff = effect["data"][0]
+ yoff = effect["data"][1]
+ timer = effect["data"][2]
+ self.current_scene.setup_scroll_camera(xoff, yoff, timer)
def expose(self):
"""
@@ -134,12 +141,17 @@ class StillScene(object):
self.current_portrait_rect = None
self.voice_delay = 0
self.script_index = -1
+ self.delaying = False
+ self.delay_timer = 0
self.fading = False
self.fade_surface = None
self.fade_surface_rect = None
self.fade_x_pos_change = 0
self.fade_y_pos_change = 0
self.fade_timer = 0
+ self.scrolling_camera = False
+ self.scroll_camera_increment = None
+ self.scroll_camera_timer = 0
# Load the scene
self.load_scene(scenefile)
@@ -301,7 +313,14 @@ class StillScene(object):
if self.continue_ready and self.script_index < len(self.script) - 1:
self.cycle_script_segment()
- def setup_fade_effect(self, fade_surface, fade_surface_rect, xmov, ymov, timer):
+ def setup_delay(self, timer):
+ """
+ Setup a scene delay for the given amount of time.
+ """
+ self.delaying = True
+ self.delay_timer = timer
+
+ def setup_fade(self, fade_surface, fade_surface_rect, xmov, ymov, timer):
"""
Setup a fade effect to play.
"""
@@ -312,7 +331,26 @@ class StillScene(object):
self.fade_y_pos_change = ymov
self.fade_timer = timer
- def play_fade_effect(self):
+ def setup_scroll_camera(self, xmov, ymov, timer):
+ """
+ Setup a camera scrolling over time.
+ """
+ self.scrolling_camera = True
+ self.scroll_camera_increment = (xmov, ymov)
+ self.scroll_camera_timer = timer
+
+ def play_delay(self):
+ """
+ Play through a delay effect.
+ """
+ if self.delay_timer > 0:
+ self.delay_timer -= 1
+ else:
+ self.delaying = False
+ self.continue_ready = True
+ self.continue_script()
+
+ def play_fade(self):
"""
Play a previously setup fade effect.
"""
@@ -324,6 +362,21 @@ class StillScene(object):
self.continue_ready = True
self.continue_script()
+ def play_scroll_camera(self):
+ """
+ Play the camera scroll motion.
+ """
+ # TODO: It seems more sensible to make the TurnManager do this in this case, but
+ # that would need to be implemented via bus. Should camera be accessible via
+ # bus itself??? Either way, its not good to talk up to managers like this...
+ if self.scroll_camera_timer > 0:
+ self.manager.camera.move_offset(self.scroll_camera_increment)
+ self.scroll_camera_timer -= 1
+ else:
+ self.scrolling_camera = False
+ self.continue_ready = True
+ self.continue_script()
+
def update(self, surface = None):
"""
Update the StillScene and draw visible elements.
@@ -338,12 +391,20 @@ class StillScene(object):
for e in c:
e.update(surface)
+ # Handle delaying
+ if self.delaying:
+ self.play_delay()
+
# Handle fading
- if self.fading:
- self.play_fade_effect()
+ elif self.fading:
+ self.play_fade()
surface.blit(self.fade_surface, self.fade_surface_rect)
- # If not fading, do regular stuff
+ # Handle scrolling camera
+ elif self.scrolling_camera:
+ self.play_scroll_camera()
+
+ # Otherwise, do regular stuff
else:
self.text_box.update(surface)
self.name_box.update(surface)