Mercurial > touhou
comparison pytouhou/games/eosd.py @ 345:2c4589370cc6
Display a boss remaining lives and timeout.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 05 Jul 2012 00:11:19 +0200 |
parents | 61caded6b4f5 |
children | 862011266f2c |
comparison
equal
deleted
inserted
replaced
344:eab591728abf | 345:2c4589370cc6 |
---|---|
89 (0, 2, 4, 8, 10, 11, 12)) | 89 (0, 2, 4, 8, 10, 11, 12)) |
90 | 90 |
91 characters = resource_loader.get_eosd_characters() | 91 characters = resource_loader.get_eosd_characters() |
92 players = [EoSDPlayer(state, self, resource_loader, characters[state.character]) for state in player_states] | 92 players = [EoSDPlayer(state, self, resource_loader, characters[state.character]) for state in player_states] |
93 | 93 |
94 interface = EoSDInterface(player_states, resource_loader) | 94 interface = EoSDInterface(self, resource_loader) |
95 | 95 |
96 Game.__init__(self, resource_loader, players, stage, rank, difficulty, | 96 Game.__init__(self, resource_loader, players, stage, rank, difficulty, |
97 bullet_types, laser_types, item_types, nb_bullets_max, | 97 bullet_types, laser_types, item_types, nb_bullets_max, |
98 width, height, prng, interface, continues) | 98 width, height, prng, interface, continues) |
99 | 99 |
100 | 100 |
101 | 101 |
102 class EoSDInterface(object): | 102 class EoSDInterface(object): |
103 def __init__(self, states, resource_loader): | 103 def __init__(self, game, resource_loader): |
104 self.states = states | 104 self.game = game |
105 front = resource_loader.get_anm_wrapper(('front.anm',)) | 105 front = resource_loader.get_anm_wrapper(('front.anm',)) |
106 ascii_wrapper = resource_loader.get_anm_wrapper(('ascii.anm',)) | 106 ascii_wrapper = resource_loader.get_anm_wrapper(('ascii.anm',)) |
107 | 107 |
108 self.width = 640 | 108 self.width = 640 |
109 self.height = 480 | 109 self.height = 480 |
127 'power': Text((500, 186), ascii_wrapper, front, text='0'), | 127 'power': Text((500, 186), ascii_wrapper, front, text='0'), |
128 'graze': Text((500, 206), ascii_wrapper, front, text='0'), | 128 'graze': Text((500, 206), ascii_wrapper, front, text='0'), |
129 'points': Text((500, 226), ascii_wrapper, front, text='0'), | 129 'points': Text((500, 226), ascii_wrapper, front, text='0'), |
130 'framerate': Text((512, 464), ascii_wrapper, front), | 130 'framerate': Text((512, 464), ascii_wrapper, front), |
131 'debug?': Text((0, 464), ascii_wrapper, front), | 131 'debug?': Text((0, 464), ascii_wrapper, front), |
132 | |
133 # Only when there is a boss. | |
134 'boss_lives': Text((80, 16), ascii_wrapper), | |
135 'timeout': Text((384, 16), ascii_wrapper), | |
132 } | 136 } |
137 self.labels['boss_lives'].set_color('yellow') | |
138 | |
139 self.boss_items = [ | |
140 Effect((0, 0), 19, front), # Enemy | |
141 # Gauge | |
142 ] | |
143 for item in self.boss_items: | |
144 item.sprite.allow_dest_offset = True #XXX | |
145 | |
146 self.front = front #XXX | |
133 | 147 |
134 | 148 |
135 def update(self): | 149 def update(self): |
136 for elem in self.items: | 150 for elem in self.items: |
137 elem.update() | 151 elem.update() |
138 | 152 |
139 player_state = self.states[0] | 153 player_state = self.game.players[0].state |
140 | 154 |
141 self.highscore = max(self.highscore, player_state.effective_score) | 155 self.highscore = max(self.highscore, player_state.effective_score) |
142 self.labels['highscore'].set_text('%09d' % self.highscore) | 156 self.labels['highscore'].set_text('%09d' % self.highscore) |
143 self.labels['score'].set_text('%09d' % player_state.effective_score) | 157 self.labels['score'].set_text('%09d' % player_state.effective_score) |
144 self.labels['power'].set_text('%d' % player_state.power) | 158 self.labels['power'].set_text('%d' % player_state.power) |
145 self.labels['graze'].set_text('%d' % player_state.graze) | 159 self.labels['graze'].set_text('%d' % player_state.graze) |
146 self.labels['points'].set_text('%d' % player_state.points) | 160 self.labels['points'].set_text('%d' % player_state.points) |
147 self.labels['player'].set_value(player_state.lives) | 161 self.labels['player'].set_value(player_state.lives) |
148 self.labels['bombs'].set_value(player_state.bombs) | 162 self.labels['bombs'].set_value(player_state.bombs) |
163 | |
164 if self.game.boss: | |
165 boss = self.game.boss._enemy | |
166 for item in self.boss_items: | |
167 item.update() | |
168 | |
169 self.labels['boss_lives'].set_text('%d' % boss.remaining_lives) | |
170 self.labels['boss_lives'].changed = True | |
171 | |
172 timeout = (boss.timeout - boss.frame) // 60 | |
173 timeout_label = self.labels['timeout'] | |
174 if timeout >= 20: | |
175 timeout_label.set_color('blue') | |
176 elif timeout >= 10: | |
177 timeout_label.set_color('darkblue') | |
178 elif timeout >= 5: | |
179 timeout_label.set_color('purple') | |
180 else: | |
181 timeout_label.set_color('red') | |
182 timeout_label.set_text('%02d' % (timeout if timeout >= 0 else 0)) | |
183 timeout_label.changed = True | |
149 | 184 |
150 | 185 |
151 | 186 |
152 class EoSDPlayer(Player): | 187 class EoSDPlayer(Player): |
153 def __init__(self, state, game, resource_loader, character): | 188 def __init__(self, state, game, resource_loader, character): |