Mercurial > touhou
comparison pytouhou/game/text.py @ 456:cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 16 Jul 2013 21:11:40 +0200 |
parents | b9d2db93972f |
children | 1c891c71cf22 |
comparison
equal
deleted
inserted
replaced
455:6864a38b2413 | 456:cae1ae9de430 |
---|---|
133 if self.frame == self.timeout: | 133 if self.frame == self.timeout: |
134 self.removed = True | 134 self.removed = True |
135 | 135 |
136 | 136 |
137 def move_timeout_update(self): | 137 def move_timeout_update(self): |
138 GlyphCollection.update(self) | |
139 if self.frame % 2: | 138 if self.frame % 2: |
140 for glyph in self.glyphes: | 139 for glyph in self.glyphes: |
141 glyph.y -= 1 | 140 glyph.y -= 1 |
142 if self.frame == self.timeout: | 141 self.timeout_update() |
143 self.removed = True | |
144 | 142 |
145 | 143 |
146 def fadeout_timeout_update(self): | 144 def fadeout_timeout_update(self): |
147 GlyphCollection.update(self) | |
148 if self.frame >= self.start: | 145 if self.frame >= self.start: |
149 if self.frame == self.start: | 146 if self.frame == self.start: |
150 self.fade(self.duration, 255, lambda x: x) | 147 self.fade(self.duration, 255, lambda x: x) |
151 elif self.frame == self.timeout - self.duration: | 148 elif self.frame == self.timeout - self.duration: |
152 self.fade(self.duration, 0, lambda x: x) | 149 self.fade(self.duration, 0, lambda x: x) |
153 if self.fade_interpolator: | 150 self.fade_interpolator.update(self.frame) |
154 self.fade_interpolator.update(self.frame) | 151 self.alpha = int(self.fade_interpolator.values[0]) |
155 self.alpha = int(self.fade_interpolator.values[0]) | 152 for glyph in self.glyphes: |
156 for glyph in self.glyphes: | 153 glyph.sprite.alpha = self.alpha |
157 glyph.sprite.alpha = self.alpha | 154 glyph.sprite.changed = True |
158 glyph.sprite.changed = True | 155 self.timeout_update() |
159 if self.frame == self.timeout: | |
160 self.removed = True | |
161 | 156 |
162 | 157 |
163 def fade(self, duration, alpha, formula): | 158 def fade(self, duration, alpha, formula): |
164 self.fade_interpolator = Interpolator((self.alpha,), self.frame, | 159 self.fade_interpolator = Interpolator((self.alpha,), self.frame, |
165 (alpha,), self.frame + duration, | 160 (alpha,), self.frame + duration, |
166 formula) | 161 formula) |
167 | 162 |
168 | 163 |
169 def set_timeout(self, timeout, effect=None, duration=0, start=0): | 164 def set_timeout(self, timeout, effect=None, duration=0, start=0): |
165 self.timeout = timeout + start | |
170 if effect == 'move': | 166 if effect == 'move': |
171 self.update = self.move_timeout_update | 167 self.update = self.move_timeout_update |
172 self.timeout = timeout + start | |
173 elif effect == 'fadeout': | 168 elif effect == 'fadeout': |
174 self.alpha = 0 | 169 self.alpha = 0 |
175 for glyph in self.glyphes: | 170 for glyph in self.glyphes: |
176 glyph.sprite.alpha = 0 | 171 glyph.sprite.alpha = 0 |
177 self.update = self.fadeout_timeout_update | 172 self.update = self.fadeout_timeout_update |
178 self.duration = duration | 173 self.duration = duration |
179 self.start = start | 174 self.start = start |
180 self.timeout = timeout + start | |
181 else: | 175 else: |
182 self.update = self.timeout_update | 176 self.update = self.timeout_update |
183 self.timeout = timeout + start | |
184 | 177 |
185 | 178 |
186 | 179 |
187 class Counter(GlyphCollection): | 180 class Counter(GlyphCollection): |
188 def __init__(self, pos, anm, back_anm=None, script=0, | 181 def __init__(self, pos, anm, back_anm=None, script=0, |
234 self.sprite.visible = True | 227 self.sprite.visible = True |
235 if self.anmrunner and not self.anmrunner.run_frame(): | 228 if self.anmrunner and not self.anmrunner.run_frame(): |
236 self.anmrunner = None | 229 self.anmrunner = None |
237 | 230 |
238 | 231 |
232 | |
233 class NativeText(object): | |
234 def __init__(self, pos, text, gradient=None, alpha=255, shadow=False, align='left'): | |
235 self.removed = False | |
236 self.x, self.y = pos | |
237 self.text = text | |
238 self.alpha = alpha | |
239 self.shadow = shadow | |
240 self.align = align | |
241 self.frame = 0 | |
242 | |
243 self.gradient = gradient or [(255, 255, 255), (255, 255, 255), | |
244 (128, 128, 255), (128, 128, 255)] | |
245 | |
246 self.update = self.normal_update | |
247 | |
248 | |
249 def normal_update(self): | |
250 self.frame += 1 | |
251 | |
252 | |
253 def timeout_update(self): | |
254 self.normal_update() | |
255 if self.frame == self.timeout: | |
256 self.removed = True | |
257 | |
258 | |
259 def move_timeout_update(self): | |
260 if self.frame % 2: | |
261 self.y -= 1 | |
262 self.timeout_update() | |
263 | |
264 | |
265 def move_ex_timeout_update(self): | |
266 if self.frame >= self.start: | |
267 if self.frame == self.start: | |
268 self.move_in(self.duration, self.to[0], self.to[1], lambda x: x) | |
269 elif self.frame == self.timeout - self.duration: | |
270 self.move_in(self.duration, self.end[0], self.end[1], lambda x: x) | |
271 if self.offset_interpolator: | |
272 self.offset_interpolator.update(self.frame) | |
273 self.x, self.y = self.offset_interpolator.values | |
274 self.timeout_update() | |
275 | |
276 | |
277 def fadeout_timeout_update(self): | |
278 if self.frame >= self.start: | |
279 if self.frame == self.start: | |
280 self.fade(self.duration, 255, lambda x: x) | |
281 elif self.frame == self.timeout - self.duration: | |
282 self.fade(self.duration, 0, lambda x: x) | |
283 self.fade_interpolator.update(self.frame) | |
284 self.alpha = int(self.fade_interpolator.values[0]) | |
285 self.timeout_update() | |
286 | |
287 | |
288 def fade(self, duration, alpha, formula): | |
289 self.fade_interpolator = Interpolator((self.alpha,), self.frame, | |
290 (alpha,), self.frame + duration, | |
291 formula) | |
292 | |
293 | |
294 def move_in(self, duration, x, y, formula): | |
295 self.offset_interpolator = Interpolator((self.x, self.y), self.frame, | |
296 (x, y), self.frame + duration, | |
297 formula) | |
298 | |
299 | |
300 def set_timeout(self, timeout, effect=None, duration=0, start=0, to=None, end=None): | |
301 self.timeout = timeout + start | |
302 if effect == 'move': | |
303 self.update = self.move_timeout_update | |
304 elif effect == 'move_ex': | |
305 self.update = self.move_ex_timeout_update | |
306 self.duration = duration | |
307 self.start = start | |
308 self.to = to | |
309 self.end = end | |
310 elif effect == 'fadeout': | |
311 self.alpha = 0 | |
312 self.update = self.fadeout_timeout_update | |
313 self.duration = duration | |
314 self.start = start | |
315 else: | |
316 self.update = self.timeout_update |