Mercurial > touhou
changeset 403:9589a01e6edf
Move MSG faces management to pytouhou.game.game, they have nothing to do in the MSG VM.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 17 Feb 2013 15:20:30 +0100 |
parents | 88e2a2485b2b |
children | 6c0cb3eee33e |
files | pytouhou/game/game.py pytouhou/vm/msgrunner.py |
diffstat | 2 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -22,6 +22,7 @@ from pytouhou.game.enemy import Enemy from pytouhou.game.item import Item from pytouhou.game.effect import Effect, Particle from pytouhou.game.text import Text +from pytouhou.game.face import Face @@ -53,6 +54,7 @@ class Game(object): self.players_lasers = [None, None] self.items = [] self.labels = [] + self.faces = [None, None] self.interface = interface self.continues = continues @@ -92,7 +94,7 @@ class Game(object): def msg_sprites(self): - return [] + return [face for face in self.faces if face] if self.msg_runner and not self.msg_runner.ended else [] def lasers_sprites(self): @@ -214,6 +216,12 @@ class Game(object): return label + def new_face(self, side, effect): + face = Face(self.msg_anm_wrapper, effect, side) + self.faces[side] = face + return face + + def run_iter(self, keystate): # 1. VMs. for runner in self.ecl_runners: @@ -249,6 +257,7 @@ class Game(object): self.interface.update() # Pri 12 for label in self.labels: #TODO: what priority is it? label.update() + self.update_faces() # Pri XXX # 5. Clean up self.cleanup() @@ -298,6 +307,12 @@ class Game(object): effect.update() + def update_faces(self): + for face in self.faces: + if face: + face.update() + + def update_bullets(self): if self.time_stop: return None
--- a/pytouhou/vm/msgrunner.py +++ b/pytouhou/vm/msgrunner.py @@ -16,7 +16,6 @@ from pytouhou.utils.helpers import get_logger from pytouhou.vm.common import MetaRegistry, instruction -from pytouhou.game.face import Face logger = get_logger(__name__) @@ -28,7 +27,7 @@ class NextStage(Exception): class MSGRunner(object): __metaclass__ = MetaRegistry __slots__ = ('_msg', '_game', 'frame', 'sleep_time', 'allow_skip', - 'skipping', 'frozen', 'faces', 'ended', 'instruction_pointer', + 'skipping', 'frozen', 'ended', 'instruction_pointer', 'handlers') def __init__(self, msg, script, game): @@ -40,18 +39,11 @@ class MSGRunner(object): self.allow_skip = True self.skipping = False self.frozen = False - - self.faces = [None, None] - game.msg_sprites = self.objects self.ended = False self.instruction_pointer = 0 - def objects(self): - return [face for face in self.faces if face] if not self.ended else [] - - def run_iteration(self): while True: if self.ended: @@ -82,10 +74,6 @@ class MSGRunner(object): else: self.frame += 1 - for face in self.faces: - if face: - face.update() - return True @@ -108,12 +96,12 @@ class MSGRunner(object): @instruction(1) def enter(self, side, effect): - self.faces[side] = Face(self._game.msg_anm_wrapper, effect, side) + self._game.new_face(side, effect) @instruction(2) def change_face(self, side, index): - face = self.faces[side] + face = self._game.faces[side] if face: face.load(index) @@ -126,7 +114,7 @@ class MSGRunner(object): @instruction(5) def animate(self, side, effect): - face = self.faces[side] + face = self._game.faces[side] if face: face.animate(effect)