commit 19ecaff30760990bb35c8e698cff05443c778aeb
parent 0015934d5302ace1aa7661e2d278dd3c12c3c06b
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sat, 17 Oct 2020 04:05:11 -0500
Semi-working implementation of still scenes
Diffstat:
8 files changed, 85 insertions(+), 33 deletions(-)
diff --git a/data/img/test_scene_bg_1.png b/data/img/test_scene_bg_1.png
Binary files differ.
diff --git a/data/img/test_scene_char1.png b/data/img/test_scene_char1.png
Binary files differ.
diff --git a/data/json/menus/mainmenu.json b/data/json/menus/mainmenu.json
@@ -9,10 +9,10 @@
"pos" : [100, 100],
"intlayer" : 0,
"effects" : {
- "me_switch_mode" : {
- "mode" : "Battle_Mode"
- }
- }
+ "me_switch_mode" : {
+ "mode" : "Battle_Mode"
+ }
+ }
},
"LoadGame" : {
"sheet" : "mainmenu_buttons_1",
@@ -20,8 +20,10 @@
"pos" : [100, 200],
"intlayer" : 0,
"effects" : {
- "me_quit" : {}
- }
+ "me_switch_mode" : {
+ "mode" : "Still_Scene_Mode"
+ }
+ }
},
"Options" : {
"sheet" : "mainmenu_buttons_1",
@@ -29,8 +31,8 @@
"pos" : [100, 300],
"intlayer" : 0,
"effects" : {
- "me_quit" : {}
- }
+ "me_quit" : {}
+ }
}
},
"entities" : { },
diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json
@@ -3,9 +3,11 @@
"fonts" : {
"A" : ["ArchivoNarrow-Regular.otf", 16]
},
+ "bg_sheet" : "test_scene_bg_1",
+ "bg_sprite" : [0, 0],
"characters" : {
"Jisella1" : {
- "sheet" : "JisellaChar1.png",
+ "sheet" : "test_scene_char1",
"sprite" : [0, 0]
}
},
diff --git a/data/json/sheets.json b/data/json/sheets.json
@@ -24,6 +24,16 @@
"dimensions" : [32, 13],
"total_sprites" : 9
},
+ "test_scene_bg_1" : {
+ "filename" : "test_scene_bg_1.png",
+ "dimensions" : [1024, 768],
+ "total_sprites" : 1
+ },
+ "test_scene_char1" : {
+ "filename" : "test_scene_char1.png",
+ "dimensions" : [72, 200],
+ "total_sprites" : 1
+ },
"jisella_1" : {
"filename" : "jisella_1.png",
"dimensions" : [64, 64],
diff --git a/src/game.py b/src/game.py
@@ -83,7 +83,7 @@ class Game(object):
elif new_mode == STATE_MODES.Still_Scene_Mode:
self.control_mode = CTRL_MODES.Still_Scene_Normal
# TODO: Generic-ify
- self.scene_manager.load_scene("testscene.json")
+ self.scene_manager.load_still_scene_from_file("testscene.json")
def shift_frames(self):
"""
@@ -113,6 +113,8 @@ class Game(object):
# battle mode. In-battle menus should be handled
# by EntityManager most likely
#self.menu_manager.update_current_menu(self.screen)
+ elif self.state_mode == STATE_MODES.Still_Scene_Mode:
+ self.scene_manager.update_scene(self.screen)
# Last, update the screen
pygame.display.update()
diff --git a/src/scene.py b/src/scene.py
@@ -30,7 +30,7 @@ class SceneManager(manager.Manager):
# Important values
self.current_scene = None
- def load_still_scene(self, scenefile):
+ def load_still_scene_from_file(self, scenefile):
"""
Create a still scene from file.
"""
@@ -83,8 +83,10 @@ class StillScene(object):
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 = pygame.Surface((928, 196)).convert()
+ self.text_surface.set_colorkey((255, 0, 255))
self.text_surface_pos = (48, 540)
+ self.background = None
# Swap-in values
self.displayed_characters = pygame.sprite.LayeredDirty()
@@ -93,6 +95,7 @@ class StillScene(object):
self.line_number = 0
self.current_font = None # An index of the 'fonts' value
self.current_text_voice = None
+ self.script_index = -1
# Load the scene
self.load_scene(scenefile)
@@ -102,22 +105,44 @@ class StillScene(object):
Load a scene from file.
"""
# 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)
+ self.name_box = vgo.VisibleGameObject(self.manager.game.sheet_manager.loaded_sheets["still_scene_name_box_1"])
+ self.name_box.set_position(self.name_box_pos)
+ self.text_box = vgo.VisibleGameObject(self.manager.game.sheet_manager.loaded_sheets["still_scene_text_box_1"])
+ self.text_box.set_position(self.text_box_pos)
+ self.continue_prompt = vgo.VisibleGameObject(self.manager.game.sheet_manager.loaded_sheets["continue_prompt_1"], (0, 0),
+ self.manager.game.sheet_manager.animations["continue_prompt_1"]["shimmer"], True)
+ self.continue_prompt.set_position(self.continue_prompt_pos)
# Load from scene definition JSON
scenedef = json.load(open(os.path.join(SCENE_JSON_PATH, scenefile)))
self.name = scenedef["name"]
+ self.background = vgo.VisibleGameObject(self.manager.game.sheet_manager.loaded_sheets[scenedef["bg_sheet"]], tuple(scenedef["bg_sprite"]))
self.script = scenedef["script"]
for f in scenedef["fonts"]:
- self.fonts[f] = pygame.font.Font(os.path.join(FONT_JSON_PATH, scenedef["fonts"][f][0]), scenedef["fonts"][f][1])
- for c in scendef["characters"]:
- nc = vgo.VGO(self.game.sheet_manager.loaded_sheets[scenedef["characters"][c]["sheet"]], tuple(scenedef["characters"][c]["sprite"]))
+ self.fonts[f] = pygame.font.Font(os.path.join(FONT_PATH, scenedef["fonts"][f][0]), scenedef["fonts"][f][1])
+ for c in scenedef["characters"]:
+ nc = vgo.VisibleGameObject(self.manager.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
+ self.characters[c] = nc
+
+ # Cycle in for the first time
+ self.cycle_script_segment()
+
+ def cycle_script_segment(self):
+ """
+ Cycle up to the next script segment.
+ """
+ # First, clear up and prepare
+ self.displayed_strings = [""]
+ self.line_number = 0
+ # NOTE: The displayed_characters group is not emptied here.
+ # That must be done manually in a script event.
+
+ # Next, load up the next segment
+ self.script_index += 1
+ self.current_font = self.fonts[self.script[self.script_index]["line_font"]]
+ self.current_text_string = self.script[self.script_index]["line"]
def write_text(self):
"""
@@ -145,30 +170,41 @@ class StillScene(object):
# 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))
+ d = self.current_font.render(l, True, (0, 0, 255)).convert()
+ #self.text_surface.blit(d, self.text_surface_pos)
+ self.manager.game.screen.blit(d, self.text_surface_pos)
+ # TODO: Text getting immediately erased
+ # Make d here permenant to text_surface somehow
+ # Should prob be stored in a var and blitted outside
+ # of this func
# Check if we have written the last character
- if self.current_text_char_index >= len(self.current_text_string - 1):
+ if self.current_text_char_index >= len(self.current_text_string) - 1:
self.continue_ready = True
- def switch_lines(self, script_index):
- pass
-
+ def continue_script(self):
+ """
+ Trigger the script cycle. Activated by something
+ else.
+ """
+ if self.script_index < len(self.script) - 1:
+ self.cycle_script_segment()
+
def update(self, surface = None):
"""
Update the StillScene and draw visible elements.
"""
if surface != None:
+ self.background.update(surface)
self.displayed_characters.update(surface)
- surface.update(self.text_box, self.text_box_pos)
- surface.update(self.name_box, self.name_box_pos)
+ self.text_box.update(surface)
+ self.name_box.update(surface)
if self.continue_ready:
- surface.update(self.continue_prompt, self.continue_prompt_pos)
+ self.continue_prompt.update(surface)
if self.text_surface != None:
+ #self.text_surface.fill((255, 255, 255))
self.write_text()
- surface.update(self.text_surface, self.text_surface_pos)
+ #surface.blit(self.text_surface, self.text_surface_pos)
diff --git a/src/vgo.py b/src/vgo.py
@@ -33,7 +33,7 @@ class VisibleGameObject(pygame.sprite.DirtySprite):
# Saved values
self.sheet = sheet
- self.image = sheet.sprites[sprite] # TODO: Should this be assigned??
+ self.image = sheet.sprites[sprite]
self.rect = self.image.get_rect()
self.rect.topleft = (0, 0)
self.custom_flags = None # Used to pass special info to VGOs
@@ -44,7 +44,7 @@ class VisibleGameObject(pygame.sprite.DirtySprite):
self.layer = 0
# Animation values
- self.animated = False
+ self.animated = animated
self.animation = {}
self.animation_timer = 0
self.animation_frame = 0