comparison pytouhou/game/sprite.py @ 38:cb5b27011044

Small refactoring and proper anm0's instruction 5 handling
author Thibaut Girka <thib@sitedethib.com>
date Sun, 14 Aug 2011 18:08:45 +0200
parents a10e3f44a883
children 93c8dc2de923
comparison
equal deleted inserted replaced
37:a10e3f44a883 38:cb5b27011044
81 frame = self.frame 81 frame = self.frame
82 if not self.keep_still: 82 if not self.keep_still:
83 script = self.anm.scripts[self.script_index] 83 script = self.anm.scripts[self.script_index]
84 try: 84 try:
85 while frame <= self.frame: 85 while frame <= self.frame:
86 frame, instr_type, data = script[self.instruction_pointer] 86 frame, instr_type, args = script[self.instruction_pointer]
87 if frame == self.frame: 87 if frame == self.frame:
88 changed = True 88 changed = True
89 if instr_type == 0: 89 if instr_type == 0:
90 self.playing = False 90 self.playing = False
91 return False 91 return False
92 if instr_type == 1: 92 if instr_type == 1:
93 self.texcoords = self.anm.sprites[unpack('<I', data)[0]] 93 self.texcoords = self.anm.sprites[args[0]]
94 elif instr_type == 2: 94 elif instr_type == 2:
95 self.rescale = unpack('<ff', data) 95 self.rescale = args
96 elif instr_type == 3: 96 elif instr_type == 3:
97 self.alpha = unpack('<I', data)[0] % 256 #TODO 97 self.alpha = args[0] % 256 #TODO
98 elif instr_type == 5: 98 elif instr_type == 5:
99 self.frame, = unpack('<I', data) 99 self.instruction_pointer, = args
100 self.instruction_pointer = 0 100 self.frame = script[self.instruction_pointer][0]
101 continue
101 elif instr_type == 7: 102 elif instr_type == 7:
102 self.mirrored = True 103 self.mirrored = True
103 elif instr_type == 9: 104 elif instr_type == 9:
104 self.rotations_3d = unpack('<fff', data) 105 self.rotations_3d = args
105 elif instr_type == 10: 106 elif instr_type == 10:
106 self.rotations_speed_3d = unpack('<fff', data) 107 self.rotations_speed_3d = args
107 elif instr_type == 23: 108 elif instr_type == 23:
108 self.corner_relative_placement = True #TODO 109 self.corner_relative_placement = True #TODO
109 elif instr_type == 15: 110 elif instr_type == 15:
110 self.keep_still = True 111 self.keep_still = True
111 break 112 break
112 else: 113 else:
113 print('unhandled opcode: %d, %r' % (instr_type, data)) #TODO 114 print('unhandled opcode: %d, %r' % (instr_type, args)) #TODO
114 if frame <= self.frame: 115 if frame <= self.frame:
115 self.instruction_pointer += 1 116 self.instruction_pointer += 1
116 except IndexError: 117 except IndexError:
117 self.playing = False 118 self.playing = False
118 pass 119 pass