Mercurial > touhou
annotate pytouhou/game/text.py @ 609:23b9418e4b2f
Remove generic usage of GL_DRAW_FRAMEBUFFER which was introduced in GL 3.0 with framebuffer_blit.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 21 Dec 2014 18:10:23 +0100 |
parents | e15672733c93 |
children | f2c3848dabff |
rev | line source |
---|---|
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
491
diff
changeset
|
15 from pytouhou.vm import ANMRunner |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
18 class Glyph(Element): |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 def __init__(self, sprite, pos): |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
20 Element.__init__(self, pos) |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
21 self.sprite = sprite |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
24 class Widget(Element): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
25 def __init__(self, pos, back_anm=None, back_script=22): |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
26 Element.__init__(self, pos) |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
27 self.changed = True |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
28 self.frame = 0 |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
30 # Set up the backround sprite |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
31 self.back_anm = back_anm |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
32 if back_anm: |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
33 self.sprite = Sprite() |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
34 self.anmrunner = ANMRunner(back_anm, back_script, self.sprite) |
322
4e8192aadcaa
Give a better interface for text handling.
Thibaut Girka <thib@sitedethib.com>
parents:
304
diff
changeset
|
35 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
36 def normal_update(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
37 if self.changed: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
38 if self.anmrunner is not None and not self.anmrunner.run_frame(): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
39 self.anmrunner = None |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
40 self.changed = False |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
41 self.frame += 1 |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
43 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
44 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
45 class GlyphCollection(Widget): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
46 def __init__(self, pos, anm, back_anm=None, ref_script=0, |
381
f1649d6c6397
Don’t hardcode background script for Widget.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
347
diff
changeset
|
47 xspacing=14, back_script=22): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
48 Widget.__init__(self, pos, back_anm, back_script) |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
49 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
50 self.ref_sprite = Sprite() |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
51 self.anm = anm |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
52 self.glyphes = [] |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
53 self.xspacing = xspacing |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
54 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
55 # Set up ref sprite |
433
1222341ea22c
Always run the first frame of an ANMRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
56 ANMRunner(anm, ref_script, self.ref_sprite) |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
57 self.ref_sprite.corner_relative_placement = True #TODO: perhaps not right |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
58 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
59 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
60 def set_length(self, length): |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
61 current_length = len(self.glyphes) |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
62 if length > current_length: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
63 self.glyphes.extend([Glyph(self.ref_sprite.copy(), |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
64 (self.x + self.xspacing * i, self.y)) |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
65 for i in range(current_length, length)]) |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
66 self.objects = [self] + self.glyphes |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
67 elif length < current_length: |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
68 self.glyphes[:] = self.glyphes[:length] |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
69 self.objects = [self] + self.glyphes |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
70 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
71 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
72 def set_sprites(self, sprite_indexes): |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
73 self.set_length(len(sprite_indexes)) |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
74 for glyph, idx in zip(self.glyphes, sprite_indexes): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
75 glyph.sprite.anm = self.anm |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
76 glyph.sprite.texcoords = self.anm.sprites[idx] |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
77 glyph.sprite.changed = True |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
78 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
79 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
80 def set_color(self, text=None, color=None): |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
81 if text is not None: |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
82 colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
83 'blue': (192, 192, 255), 'darkblue': (160, 128, 255), |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
84 'purple': (224, 128, 255), 'red': (255, 64, 0)} |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
85 color = colors[text] |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
86 else: |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
87 assert color is not None |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
88 self.ref_sprite.color = color |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
89 for glyph in self.glyphes: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
90 glyph.sprite.color = color |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
91 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
92 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
93 def set_alpha(self, alpha): |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
94 self.ref_sprite.alpha = alpha |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
95 for glyph in self.glyphes: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
96 glyph.sprite.alpha = alpha |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
97 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
98 |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
99 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
100 class Text(GlyphCollection): |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
101 def __init__(self, pos, ascii_anm, back_anm=None, text=b'', |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
102 xspacing=14, shift=21, back_script=22, align='left'): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
103 GlyphCollection.__init__(self, pos, ascii_anm, back_anm, |
381
f1649d6c6397
Don’t hardcode background script for Widget.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
347
diff
changeset
|
104 xspacing=xspacing, back_script=back_script) |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
105 self.text = b'' |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
106 self.shift = shift |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
107 |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
108 if align == 'center': |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
109 self.x -= xspacing * len(text) // 2 |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
110 elif align == 'right': |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
111 self.x -= xspacing * len(text) |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
112 else: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
113 assert align == 'left' |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
114 |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
115 self.set_text(text) |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
116 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
117 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
118 def set_text(self, text): |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
119 if text == self.text: |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
120 return |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
121 |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
122 if isinstance(text, str): |
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
123 text = text.encode() |
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
124 |
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
547
diff
changeset
|
125 self.set_sprites([c - self.shift for c in text]) |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
126 self.text = text |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
127 self.changed = True |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
128 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
129 |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
130 def timeout_update(self): |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
131 GlyphCollection.normal_update(self) |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
132 if self.frame == self.timeout: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
133 self.removed = True |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
134 |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
135 |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
136 def move_timeout_update(self): |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
137 if self.frame % 2: |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
138 for glyph in self.glyphes: |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
139 glyph.y -= 1 |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
140 self.timeout_update() |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
141 |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
142 |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
143 def fadeout_timeout_update(self): |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
144 if self.frame >= self.start: |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
145 if self.frame == self.start: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
146 self.fade(self.duration, 255) |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
147 elif self.frame == self.timeout - self.duration: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
148 self.fade(self.duration, 0) |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
149 self.fade_interpolator.update(self.frame) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
150 self.alpha = int(self.fade_interpolator.values[0]) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
151 for glyph in self.glyphes: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
152 glyph.sprite.alpha = self.alpha |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
153 glyph.sprite.changed = True |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
154 self.timeout_update() |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
155 |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
156 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
157 def fade(self, duration, alpha, formula=None): |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
158 self.fade_interpolator = Interpolator((self.alpha,), self.frame, |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
159 (alpha,), self.frame + duration, |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
160 formula) |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
161 |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
162 |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
163 def set_timeout(self, timeout, effect=None, duration=0, start=0): |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
164 self.timeout = timeout + start |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
165 if effect == 'move': |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
166 self.update = self.move_timeout_update |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
167 elif effect == 'fadeout': |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
168 self.alpha = 0 |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
169 for glyph in self.glyphes: |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
170 glyph.sprite.alpha = 0 |
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
171 self.update = self.fadeout_timeout_update |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
172 self.duration = duration |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
173 self.start = start |
404
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
174 else: |
6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
387
diff
changeset
|
175 self.update = self.timeout_update |
327
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
176 |
13201d90bb22
Display the text when collecting an item.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
323
diff
changeset
|
177 |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
178 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
179 class Counter(GlyphCollection): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
180 def __init__(self, pos, anm, back_anm=None, script=0, |
381
f1649d6c6397
Don’t hardcode background script for Widget.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
347
diff
changeset
|
181 xspacing=16, value=0, back_script=22): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
182 GlyphCollection.__init__(self, pos, anm, |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
183 back_anm=back_anm, ref_script=script, |
381
f1649d6c6397
Don’t hardcode background script for Widget.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
347
diff
changeset
|
184 xspacing=xspacing, back_script=back_script) |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
185 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
186 self.value = value |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
187 self.set_value(value) |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
188 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
189 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
190 def set_value(self, value): |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
191 if value < 0: |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
192 value = 0 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
193 if value == self.value: |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
194 return |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
195 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
196 self.set_length(value) |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
197 self.value = value |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
198 self.changed = True |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
199 |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
322
diff
changeset
|
200 |
346
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
201 |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
202 class Gauge(Element): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
203 def __init__(self, pos, anm, max_length=280, maximum=1, value=0): |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
439
diff
changeset
|
204 Element.__init__(self, pos) |
346
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
205 self.sprite = Sprite() |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
404
diff
changeset
|
206 self.anmrunner = ANMRunner(anm, 21, self.sprite) |
346
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
207 self.sprite.corner_relative_placement = True #TODO: perhaps not right |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
208 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
209 self.max_length = max_length |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
210 self.maximum = maximum |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
211 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
212 self.set_value(value) |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
213 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
214 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
215 def set_value(self, value): |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
216 self.value = value |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
217 self.sprite.width_override = self.max_length * value / self.maximum |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
218 self.sprite.changed = True #TODO |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
219 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
220 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
221 def update(self): |
347
b150ed7188a2
Show the size of the spellcard life.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
346
diff
changeset
|
222 #XXX |
b150ed7188a2
Show the size of the spellcard life.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
346
diff
changeset
|
223 if self.value == 0: |
b150ed7188a2
Show the size of the spellcard life.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
346
diff
changeset
|
224 self.sprite.visible = False |
b150ed7188a2
Show the size of the spellcard life.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
346
diff
changeset
|
225 else: |
b150ed7188a2
Show the size of the spellcard life.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
346
diff
changeset
|
226 self.sprite.visible = True |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
227 if self.anmrunner is not None and not self.anmrunner.run_frame(): |
346
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
228 self.anmrunner = None |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
229 |
862011266f2c
Add a gauge and use it for the enemy life bar.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
345
diff
changeset
|
230 |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
231 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
232 class NativeText(Element): |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
233 def __init__(self, pos, text, gradient=None, alpha=255, shadow=False, align='left'): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
234 self.removed = False |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
235 self.x, self.y = pos |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
236 self.text = text |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
237 self.alpha = alpha |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
238 self.shadow = shadow |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
239 self.align = align |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
240 self.frame = 0 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
241 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
242 self.gradient = gradient or [(255, 255, 255), (255, 255, 255), |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
243 (128, 128, 255), (128, 128, 255)] |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
244 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
245 self.update = self.normal_update |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
246 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
247 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
248 def normal_update(self): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
249 self.frame += 1 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
250 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
251 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
252 def timeout_update(self): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
253 self.normal_update() |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
254 if self.frame == self.timeout: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
255 self.removed = True |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
256 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
257 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
258 def move_timeout_update(self): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
259 if self.frame % 2: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
260 self.y -= 1 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
261 self.timeout_update() |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
262 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
263 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
264 def move_ex_timeout_update(self): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
265 if self.frame >= self.start: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
266 if self.frame == self.start: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
267 self.move_in(self.duration, self.to[0], self.to[1]) |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
268 elif self.frame == self.timeout - self.duration: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
269 self.move_in(self.duration, self.end[0], self.end[1]) |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
270 if self.offset_interpolator: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
271 self.offset_interpolator.update(self.frame) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
272 self.x, self.y = self.offset_interpolator.values |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
273 self.timeout_update() |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
274 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
275 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
276 def fadeout_timeout_update(self): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
277 if self.frame >= self.start: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
278 if self.frame == self.start: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
279 self.fade(self.duration, 255) |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
280 elif self.frame == self.timeout - self.duration: |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
281 self.fade(self.duration, 0) |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
282 self.fade_interpolator.update(self.frame) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
283 self.alpha = int(self.fade_interpolator.values[0]) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
284 self.timeout_update() |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
285 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
286 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
287 def fade(self, duration, alpha, formula=None): |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
288 self.fade_interpolator = Interpolator((self.alpha,), self.frame, |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
289 (alpha,), self.frame + duration, |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
290 formula) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
291 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
292 |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
293 def move_in(self, duration, x, y, formula=None): |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
294 self.offset_interpolator = Interpolator((self.x, self.y), self.frame, |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
295 (x, y), self.frame + duration, |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
296 formula) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
297 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
298 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
299 def set_timeout(self, timeout, effect=None, duration=0, start=0, to=None, end=None): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
300 self.timeout = timeout + start |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
301 if effect == 'move': |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
302 self.update = self.move_timeout_update |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
303 elif effect == 'move_ex': |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
304 self.update = self.move_ex_timeout_update |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
305 self.duration = duration |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
306 self.start = start |
473
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
307 self.to[:] = [to[0], to[1]] |
1c891c71cf22
Cythonize pytouhou.game.text.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
308 self.end[:] = [end[0], end[1]] |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
309 elif effect == 'fadeout': |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
310 self.alpha = 0 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
311 self.update = self.fadeout_timeout_update |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
312 self.duration = duration |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
313 self.start = start |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
314 else: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
315 self.update = self.timeout_update |