Mercurial > touhou
changeset 34:4d93d45ecb62
Fix animation script flow handling
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 14 Aug 2011 13:34:58 +0200 |
parents | 1f21bcc0845b |
children | 9027692abd79 |
files | pytouhou/game/enemymanager.py pytouhou/game/sprite.py |
diffstat | 2 files changed, 39 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/enemymanager.py +++ b/pytouhou/game/enemymanager.py @@ -150,6 +150,9 @@ class Enemy(object): visible = self.is_visible(384, 448) if changed and visible: self.sprite.update_uvs_vertices() + elif not self.sprite.playing: + visible = False + self.sprite = None else: visible = False
--- a/pytouhou/game/sprite.py +++ b/pytouhou/game/sprite.py @@ -25,6 +25,8 @@ class Sprite(object): self.rotations_speed_3d = (0., 0., 0.) self.corner_relative_placement = False self.instruction_pointer = 0 + self.keep_still = False + self.playing = True self.frame = 0 self._uvs = [] self._vertices = [] @@ -69,38 +71,43 @@ class Sprite(object): def update(self): + if not self.playing: + return False + changed = False frame = self.frame - script = self.anm.scripts[self.script_index] - try: - while frame <= self.frame: - frame, instr_type, data = script[self.instruction_pointer] - if frame == self.frame: - changed = True - if instr_type == 1: - self.texcoords = self.anm.sprites[unpack('<I', data)[0]] - elif instr_type == 2: - self.rescale = unpack('<ff', data) - elif instr_type == 5: - self.frame, = unpack('<I', data) - self.instruction_pointer = 0 - elif instr_type == 7: - self.mirrored = True - elif instr_type == 9: - self.rotations_3d = unpack('<fff', data) - elif instr_type == 10: - self.rotations_speed_3d = unpack('<fff', data) - elif instr_type == 23: - self.corner_relative_placement = True #TODO - elif instr_type == 15: + if not self.keep_still: + script = self.anm.scripts[self.script_index] + try: + while frame <= self.frame: + frame, instr_type, data = script[self.instruction_pointer] + if frame == self.frame: + changed = True + if instr_type == 1: + self.texcoords = self.anm.sprites[unpack('<I', data)[0]] + elif instr_type == 2: + self.rescale = unpack('<ff', data) + elif instr_type == 5: + self.frame, = unpack('<I', data) + self.instruction_pointer = 0 + elif instr_type == 7: + self.mirrored = True + elif instr_type == 9: + self.rotations_3d = unpack('<fff', data) + elif instr_type == 10: + self.rotations_speed_3d = unpack('<fff', data) + elif instr_type == 23: + self.corner_relative_placement = True #TODO + elif instr_type == 15: + self.keep_still = True + break + else: + print('unhandled opcode: %d, %r' % (instr_type, data)) #TODO + if frame <= self.frame: self.instruction_pointer += 1 - break - else: - print('unhandled opcode: %d, %r' % (instr_type, data)) #TODO - if frame <= self.frame: - self.instruction_pointer += 1 - except IndexError: - pass + except IndexError: + self.playing = False + pass self.frame += 1 ax, ay, az = self.rotations_3d