comparison pytouhou/game/background.py @ 14:07a7f28c8aaa

Minor refactoring
author Thibaut Girka <thib@sitedethib.com>
date Fri, 05 Aug 2011 14:54:32 +0200
parents 58bc264aba38
children 07fba4e1da65
comparison
equal deleted inserted replaced
13:58bc264aba38 14:07a7f28c8aaa
8 8
9 from pytouhou.formats.std import Stage 9 from pytouhou.formats.std import Stage
10 from pytouhou.formats.anm0 import Animations 10 from pytouhou.formats.anm0 import Animations
11 11
12 12
13
14 class Background(object): 13 class Background(object):
15 def __init__(self, archive, stage_num): 14 def __init__(self, archive, stage_num):
16 self.stage = Stage.read(BytesIO(archive.extract('stage%d.std' % stage_num))) 15 self.stage = Stage.read(BytesIO(archive.extract('stage%d.std' % stage_num)))
17 self.anim = Animations.read(BytesIO(archive.extract('stg%dbg.anm' % stage_num))) 16 self.anim = Animations.read(BytesIO(archive.extract('stg%dbg.anm' % stage_num)))
18 texture_components = [None, None]
19 for i, component_name in ((0, self.anim.first_name), (1, self.anim.secondary_name)):
20 if component_name:
21 texture_components[i] = BytesIO(archive.extract(os.path.basename(component_name)))
22 self.texture_components = texture_components
23 self.objects = [] 17 self.objects = []
24 self.object_instances = [] 18 self.object_instances = []
25 self._uvs = b'' 19 self._uvs = b''
26 self._vertices = b'' 20 self._vertices = b''
27 self.build_objects() 21 self.build_objects()
135 self.fog_interpolator = Interpolator((0, 0, 0, 0, 0)) 129 self.fog_interpolator = Interpolator((0, 0, 0, 0, 0))
136 self.position2_interpolator = Interpolator((0, 0, 0)) 130 self.position2_interpolator = Interpolator((0, 0, 0))
137 131
138 for frame_num, message_type, args in self.stage.script: 132 for frame_num, message_type, args in self.stage.script:
139 if frame_num == frame: 133 if frame_num == frame:
140 if message_type == 1: 134 if message_type == 0:
135 self.position_interpolator.set_interpolation_start(frame_num, args)
136 elif message_type == 1:
141 self.fog_interpolator.set_interpolation_end_values(args) 137 self.fog_interpolator.set_interpolation_end_values(args)
138 elif message_type == 2:
139 self.position2_interpolator.set_interpolation_end_values(args)
142 elif message_type == 3: 140 elif message_type == 3:
143 duration, = args 141 duration, = args
144 self.position2_interpolator.set_interpolation_end_frame(frame_num + duration) 142 self.position2_interpolator.set_interpolation_end_frame(frame_num + duration)
145 elif message_type == 4: 143 elif message_type == 4:
146 duration, = args 144 duration, = args
147 self.fog_interpolator.set_interpolation_end_frame(frame_num + duration) 145 self.fog_interpolator.set_interpolation_end_frame(frame_num + duration)
148 elif message_type == 2:
149 self.position2_interpolator.set_interpolation_end_values(args)
150 if frame_num <= frame and message_type == 0:
151 self.position_interpolator.set_interpolation_start(frame_num, args)
152 if frame_num > frame and message_type == 0: 146 if frame_num > frame and message_type == 0:
153 self.position_interpolator.set_interpolation_end(frame_num, args) 147 self.position_interpolator.set_interpolation_end(frame_num, args)
154 break 148 break
155 149
156 self.position2_interpolator.update(frame) 150 self.position2_interpolator.update(frame)