Mercurial > touhou
comparison pytouhou/game/text.py @ 387:e1f5dcd4b83e
Display something at the start of a stage.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 20 Oct 2012 20:48:40 +0200 |
parents | 690b5faaa0e6 |
children | 6c0cb3eee33e |
comparison
equal
deleted
inserted
replaced
386:dc6ed7b1c6de | 387:e1f5dcd4b83e |
---|---|
14 | 14 |
15 from copy import copy | 15 from copy import copy |
16 | 16 |
17 from pytouhou.game.sprite import Sprite | 17 from pytouhou.game.sprite import Sprite |
18 from pytouhou.vm.anmrunner import ANMRunner | 18 from pytouhou.vm.anmrunner import ANMRunner |
19 from pytouhou.utils.interpolator import Interpolator | |
19 | 20 |
20 | 21 |
21 class Glyph(object): | 22 class Glyph(object): |
22 def __init__(self, sprite, pos): | 23 def __init__(self, sprite, pos): |
23 self.sprite = sprite | 24 self.sprite = sprite |
30 def __init__(self, pos, back_wrapper=None, back_script=22): | 31 def __init__(self, pos, back_wrapper=None, back_script=22): |
31 self.sprite = None | 32 self.sprite = None |
32 self.removed = False | 33 self.removed = False |
33 self.changed = True | 34 self.changed = True |
34 self.anmrunner = None | 35 self.anmrunner = None |
36 self.frame = 0 | |
35 | 37 |
36 # Set up the backround sprite | 38 # Set up the backround sprite |
37 self.back_wrapper = back_wrapper | 39 self.back_wrapper = back_wrapper |
38 if back_wrapper: | 40 if back_wrapper: |
39 self.sprite = Sprite() | 41 self.sprite = Sprite() |
41 self.anmrunner.run_frame() | 43 self.anmrunner.run_frame() |
42 | 44 |
43 self.x, self.y = pos | 45 self.x, self.y = pos |
44 | 46 |
45 def update(self): | 47 def update(self): |
48 self.frame += 1 | |
46 if self.changed: | 49 if self.changed: |
47 if self.anmrunner and not self.anmrunner.run_frame(): | 50 if self.anmrunner and not self.anmrunner.run_frame(): |
48 self.anmrunner = None | 51 self.anmrunner = None |
49 self.changed = False | 52 self.changed = False |
50 | 53 |
116 self.ref_sprite.color = colors[color] | 119 self.ref_sprite.color = colors[color] |
117 for glyph in self.glyphes: | 120 for glyph in self.glyphes: |
118 glyph.sprite.color = colors[color] | 121 glyph.sprite.color = colors[color] |
119 | 122 |
120 | 123 |
121 def timeout_update(self): | 124 def move_timeout_update(self): |
122 GlyphCollection.update(self) | 125 GlyphCollection.update(self) |
123 if self.timeout % 2: | 126 if self.frame % 2: |
124 for glyph in self.glyphes: | 127 for glyph in self.glyphes: |
125 glyph.y -= 1 | 128 glyph.y -= 1 |
126 self.timeout -= 1 | 129 if self.frame == self.timeout: |
127 if self.timeout == 0: | |
128 self.removed = True | 130 self.removed = True |
129 | 131 |
130 | 132 |
131 def set_timeout(self, timeout): | 133 def fadeout_timeout_update(self): |
132 self.timeout = timeout | 134 GlyphCollection.update(self) |
133 self.update = self.timeout_update | 135 if self.frame >= self.start: |
136 if self.frame == self.start: | |
137 self.fade(self.effect, 255, lambda x: x) | |
138 elif self.frame == self.timeout - self.effect: | |
139 self.fade(self.effect, 0, lambda x: x) | |
140 if self.fade_interpolator: | |
141 self.fade_interpolator.update(self.frame) | |
142 self.alpha = int(self.fade_interpolator.values[0]) | |
143 for glyph in self.glyphes: | |
144 glyph.sprite.alpha = self.alpha | |
145 glyph.sprite.changed = True | |
146 if self.frame == self.timeout: | |
147 self.removed = True | |
148 | |
149 | |
150 def fade(self, duration, alpha, formula): | |
151 self.fade_interpolator = Interpolator((self.alpha,), self.frame, | |
152 (alpha,), self.frame + duration, | |
153 formula) | |
154 | |
155 | |
156 def set_timeout(self, timeout, effect=None, start=0): | |
157 if effect == None: #XXX | |
158 self.update = self.move_timeout_update | |
159 self.timeout = timeout + start | |
160 else: | |
161 self.alpha = 0 | |
162 for glyph in self.glyphes: | |
163 glyph.sprite.alpha = 0 | |
164 self.update = self.fadeout_timeout_update | |
165 self.effect = effect | |
166 self.start = start | |
167 self.timeout = timeout + start | |
134 | 168 |
135 | 169 |
136 | 170 |
137 class Counter(GlyphCollection): | 171 class Counter(GlyphCollection): |
138 def __init__(self, pos, anm_wrapper, back_wrapper=None, script=0, | 172 def __init__(self, pos, anm_wrapper, back_wrapper=None, script=0, |