comparison pytouhou/vm/anmrunner.py @ 122:174324a4da51

Add support for launch animations! (Warning: slow :()
author Thibaut Girka <thib@sitedethib.com>
date Sat, 10 Sep 2011 01:26:30 +0200
parents 4300a832f033
children 284ac8f97a96
comparison
equal deleted inserted replaced
121:1bc0ad774ed4 122:174324a4da51
39 39
40 self.sprite_index_offset = sprite_index_offset 40 self.sprite_index_offset = sprite_index_offset
41 41
42 42
43 def run_frame(self): 43 def run_frame(self):
44 if self._sprite._removed: 44 if not self._running:
45 return False 45 return False
46 46
47 sprite = self._sprite
48
47 while self._running: 49 while self._running:
48 try: 50 frame, opcode, args = self.script[self.instruction_pointer]
49 frame, instr_type, args = self.script[self.instruction_pointer]
50 except IndexError:
51 return False
52 51
53 if frame > self.frame: 52 if frame > self.frame:
54 break 53 break
55 else: 54 else:
56 self.instruction_pointer += 1 55 self.instruction_pointer += 1
57 56
58 if frame == self.frame: 57 if frame == self.frame:
59 try: 58 try:
60 callback = self._handlers[instr_type] 59 callback = self._handlers[opcode]
61 except KeyError: 60 except KeyError:
62 logger.warn('unhandled opcode %d (args: %r)', instr_type, args) 61 logger.warn('unhandled opcode %d (args: %r)', instr_type, args)
63 else: 62 else:
64 callback(self, *args) 63 callback(self, *args)
65 self._sprite._changed = True 64 sprite._changed = True
66 self.frame += 1 65 self.frame += 1
67 66
68 # Update sprite 67 # Update sprite
69 sprite = self._sprite
70 sprite.frame += 1 68 sprite.frame += 1
71 69
72 if sprite.rotations_speed_3d != (0., 0., 0.): 70 if sprite.rotations_speed_3d != (0., 0., 0.):
73 ax, ay, az = sprite.rotations_3d 71 ax, ay, az = sprite.rotations_3d
74 sax, say, saz = sprite.rotations_speed_3d 72 sax, say, saz = sprite.rotations_speed_3d
100 98
101 99
102 @instruction(0) 100 @instruction(0)
103 def remove(self): 101 def remove(self):
104 self._sprite._removed = True 102 self._sprite._removed = True
105 self._running = True 103 self._running = False
106 104
107 105
108 @instruction(1) 106 @instruction(1)
109 def load_sprite(self, sprite_index): 107 def load_sprite(self, sprite_index):
110 self._sprite.anm, self._sprite.texcoords = self._anm_wrapper.get_sprite(sprite_index + self.sprite_index_offset) 108 self._sprite.anm, self._sprite.texcoords = self._anm_wrapper.get_sprite(sprite_index + self.sprite_index_offset)