commit 930f784c5b3876ccb9749e42d929fe03a9f02ebf
parent fb2614839923399f1621c9ee2092077c958bcf0b
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sat, 17 Oct 2020 01:43:05 -0500
Scene work checkpoint, near implementation
Diffstat:
4 files changed, 86 insertions(+), 4 deletions(-)
diff --git a/data/json/anims.json b/data/json/anims.json
@@ -74,5 +74,18 @@
{ "sprite" : [0, 1], "timer" : 3 },
{ "sprite" : [1, 0], "timer" : 3 }
]
- }
+ },
+ "continue_prompt_1" : {
+ "shimmer" : [
+ { "sprite" : [0, 0], "timer" : 52 },
+ { "sprite" : [0, 1], "timer" : 1 },
+ { "sprite" : [0, 2], "timer" : 1 },
+ { "sprite" : [0, 3], "timer" : 1 },
+ { "sprite" : [0, 4], "timer" : 1 },
+ { "sprite" : [0, 5], "timer" : 1 },
+ { "sprite" : [0, 6], "timer" : 1 },
+ { "sprite" : [0, 7], "timer" : 1 },
+ { "sprite" : [0, 8], "timer" : 1 }
+ ]
+ }
}
diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json
@@ -13,6 +13,7 @@
{
"speaker" : "Jisella",
"name_font" : "A",
+ "name_pos" : [20, 480],
"line_font" : "A",
"voice" : 0,
"line" : "Hi there. This is a test of the Scene system.",
@@ -28,6 +29,7 @@
{
"speaker" : "",
"name_font" : "A",
+ "name_pos" : [20, 480],
"line_font" : "A",
"voice" : 0,
"line" : "",
diff --git a/src/game.py b/src/game.py
@@ -1,5 +1,5 @@
import pygame
-from . import images, board, vgo, unit, menu
+from . import images, board, vgo, unit, menu, scene
from .constants import *
###########
@@ -48,6 +48,7 @@ class Game(object):
self.board_manager = board.BoardManager(self)
self.entity_manager = vgo.EntityManager(self)
self.unit_manager = unit.UnitManager(self)
+ self.scene_manager = scene.SceneManager(self)
# Setup (This is WIP)
self.sheet_manager.load_sheets_from_json("sheets.json")
@@ -80,7 +81,9 @@ class Game(object):
self.entity_manager.load_entities_from_json("testmap1.json")
self.entity_manager.load_tile_cursor("cursor1")
elif new_mode == STATE_MODES.Still_Scene_Mode:
- pass
+ self.control_mode = CTRL_MODES.Still_Scene_Normal
+ # TODO: Generic-ify
+ self.scene_manager.load_scene("testscene.json")
def shift_frames(self):
"""
diff --git a/src/scene.py b/src/scene.py
@@ -30,6 +30,12 @@ class SceneManager(manager.Manager):
# Important values
self.current_scene = None
+ def load_still_scene(self, scenefile):
+ """
+ Create a still scene from file.
+ """
+ self.current_scene = StillScene(self, scenefile)
+
def update_scene(self, surface = None):
"""
Update and draw the current scene. Behaves differently
@@ -65,16 +71,26 @@ class StillScene(object):
self.characters = {}
self.text_speed = 10
self.text_write_timer = 0
+ self.current_text_char_index = 0
+ self.continue_ready = False
+ self.max_line = 100
# Universal elements
+ # TODO: Pos vals should not be hardcoded like this
self.name_box = None
+ self.name_box_pos = (20, 480)
self.text_box = None
+ self.text_box_pos = (0, 508)
self.continue_prompt = None
+ self.continue_prompt_pos = (964, 748)
+ self.text_surface = pygame.Surface((928, 196))
+ self.text_surface_pos = (48, 540)
# Swap-in values
self.displayed_characters = pygame.sprite.LayeredDirty()
self.current_text_string = ""
- self.displayed_string = ""
+ self.displayed_strings = [""] # list of text lines
+ self.line_number = 0
self.current_font = None # An index of the 'fonts' value
self.current_text_voice = None
@@ -88,6 +104,8 @@ class StillScene(object):
# Load univeral elements
self.name_box = vgo.VGO(self.game.sheet_manager.loaded_sheets["still_scene_name_box_1"])
self.text_box = vgo.VGO(self.game.sheet_manager.loaded_sheets["still_scene_text_box_1"])
+ self.continue_prompt = vgo.VGO(self.game.sheet_manager.loaded_sheets["continue_prompt_1"], (0, 0),
+ self.game.sheet_manager.animations["continue_prompt_1"]["shimmer"], True)
# Load from scene definition JSON
scenedef = json.load(open(os.path.join(SCENE_JSON_PATH, scenefile)))
@@ -100,6 +118,43 @@ class StillScene(object):
nc = vgo.VGO(self.game.sheet_manager.loaded_sheets[scenedef["characters"][c]["sheet"]], tuple(scenedef["characters"][c]["sprite"]))
nc.custom_flags = c # TODO: Hacky solution for now, fix later
self.characters[scenedef["characters"][c]["name"]] = nc
+
+ def write_text(self):
+ """
+ Write out the text of a script and render it to
+ a pygame Font surface.
+ """
+ # If we aren't ready to write a new char yet, don't
+ if self.text_write_timer < self.text_speed and not self.continue_ready:
+ self.text_write_timer += 1
+
+ # If the whole line is displayed, get outta here
+ elif self.continue_ready:
+ return
+
+ # Otherwise, write a new char and switch up the appropriate vals
+ else:
+ self.text_write_timer = 0
+ self.current_text_char_index += 1
+ self.displayed_strings[self.line_number] = self.current_text_string[0:self.current_text_char_index]
+
+ # Check if we need to add a new line
+ if len(self.displayed_strings[self.line_number]) >= self.max_line:
+ self.displayed_strings.append("")
+ self.line_number += 1
+
+ # Render to a surface
+ for l in self.displayed_strings:
+ d = self.fonts[self.current_font].render(self.displayed_strings[l],
+ False, (0, 0, 0))
+ self.text_surface.blit(d, (self.text_surface_pos[0], self.text_surface_pos[1] + (self.fonts[self.current_font].get_height() * self.line_number) + 2))
+
+ # Check if we have written the last character
+ if self.current_text_char_index >= len(self.current_text_string - 1):
+ self.continue_ready = True
+
+ def switch_lines(self, script_index):
+ pass
def update(self, surface = None):
"""
@@ -107,4 +162,13 @@ class StillScene(object):
"""
if surface != None:
self.displayed_characters.update(surface)
+ surface.update(self.text_box, self.text_box_pos)
+ surface.update(self.name_box, self.name_box_pos)
+
+ if self.continue_ready:
+ surface.update(self.continue_prompt, self.continue_prompt_pos)
+
+ if self.text_surface != None:
+ self.write_text()
+ surface.update(self.text_surface, self.text_surface_pos)