Mercurial > touhou
comparison pytouhou/game/sprite.py @ 34:4d93d45ecb62
Fix animation script flow handling
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 14 Aug 2011 13:34:58 +0200 |
parents | 55973a3f1222 |
children | a10e3f44a883 |
comparison
equal
deleted
inserted
replaced
33:1f21bcc0845b | 34:4d93d45ecb62 |
---|---|
23 self.rescale = (1., 1.) | 23 self.rescale = (1., 1.) |
24 self.rotations_3d = (0., 0., 0.) | 24 self.rotations_3d = (0., 0., 0.) |
25 self.rotations_speed_3d = (0., 0., 0.) | 25 self.rotations_speed_3d = (0., 0., 0.) |
26 self.corner_relative_placement = False | 26 self.corner_relative_placement = False |
27 self.instruction_pointer = 0 | 27 self.instruction_pointer = 0 |
28 self.keep_still = False | |
29 self.playing = True | |
28 self.frame = 0 | 30 self.frame = 0 |
29 self._uvs = [] | 31 self._uvs = [] |
30 self._vertices = [] | 32 self._vertices = [] |
31 | 33 |
32 | 34 |
67 self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2]) | 69 self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2]) |
68 | 70 |
69 | 71 |
70 | 72 |
71 def update(self): | 73 def update(self): |
74 if not self.playing: | |
75 return False | |
76 | |
72 changed = False | 77 changed = False |
73 frame = self.frame | 78 frame = self.frame |
74 script = self.anm.scripts[self.script_index] | 79 if not self.keep_still: |
75 try: | 80 script = self.anm.scripts[self.script_index] |
76 while frame <= self.frame: | 81 try: |
77 frame, instr_type, data = script[self.instruction_pointer] | 82 while frame <= self.frame: |
78 if frame == self.frame: | 83 frame, instr_type, data = script[self.instruction_pointer] |
79 changed = True | 84 if frame == self.frame: |
80 if instr_type == 1: | 85 changed = True |
81 self.texcoords = self.anm.sprites[unpack('<I', data)[0]] | 86 if instr_type == 1: |
82 elif instr_type == 2: | 87 self.texcoords = self.anm.sprites[unpack('<I', data)[0]] |
83 self.rescale = unpack('<ff', data) | 88 elif instr_type == 2: |
84 elif instr_type == 5: | 89 self.rescale = unpack('<ff', data) |
85 self.frame, = unpack('<I', data) | 90 elif instr_type == 5: |
86 self.instruction_pointer = 0 | 91 self.frame, = unpack('<I', data) |
87 elif instr_type == 7: | 92 self.instruction_pointer = 0 |
88 self.mirrored = True | 93 elif instr_type == 7: |
89 elif instr_type == 9: | 94 self.mirrored = True |
90 self.rotations_3d = unpack('<fff', data) | 95 elif instr_type == 9: |
91 elif instr_type == 10: | 96 self.rotations_3d = unpack('<fff', data) |
92 self.rotations_speed_3d = unpack('<fff', data) | 97 elif instr_type == 10: |
93 elif instr_type == 23: | 98 self.rotations_speed_3d = unpack('<fff', data) |
94 self.corner_relative_placement = True #TODO | 99 elif instr_type == 23: |
95 elif instr_type == 15: | 100 self.corner_relative_placement = True #TODO |
101 elif instr_type == 15: | |
102 self.keep_still = True | |
103 break | |
104 else: | |
105 print('unhandled opcode: %d, %r' % (instr_type, data)) #TODO | |
106 if frame <= self.frame: | |
96 self.instruction_pointer += 1 | 107 self.instruction_pointer += 1 |
97 break | 108 except IndexError: |
98 else: | 109 self.playing = False |
99 print('unhandled opcode: %d, %r' % (instr_type, data)) #TODO | 110 pass |
100 if frame <= self.frame: | |
101 self.instruction_pointer += 1 | |
102 except IndexError: | |
103 pass | |
104 self.frame += 1 | 111 self.frame += 1 |
105 | 112 |
106 ax, ay, az = self.rotations_3d | 113 ax, ay, az = self.rotations_3d |
107 sax, say, saz = self.rotations_speed_3d | 114 sax, say, saz = self.rotations_speed_3d |
108 self.rotations_3d = ax + sax, ay + say, az + saz | 115 self.rotations_3d = ax + sax, ay + say, az + saz |