Mercurial > touhou
changeset 327:13201d90bb22
Display the text when collecting an item.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 21 Jun 2012 15:01:25 +0200 |
parents | efcdf2ce747c |
children | 56523a16db1d |
files | pytouhou/game/game.py pytouhou/game/item.py pytouhou/game/text.py pytouhou/ui/gamerenderer.pyx |
diffstat | 4 files changed, 59 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -21,6 +21,7 @@ from pytouhou.game.enemy import Enemy from pytouhou.game.item import Item from pytouhou.game.effect import Effect from pytouhou.game.effect import Particle +from pytouhou.game.text import Text @@ -46,6 +47,7 @@ class Game(object): self.players_bullets = [] self.players_lasers = [None, None] self.items = [] + self.labels = [] self.interface = interface self.stage = stage @@ -73,6 +75,9 @@ class Game(object): self.spellcard_effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,)) self.spellcard_effect = None + #TODO: better place? + self.ascii_wrapper = resource_loader.get_anm_wrapper(('ascii.anm',)) + # See 102h.exe@0x413220 if you think you're brave enough. self.deaths_count = self.prng.rand_uint16() % 3 self.next_bonus = self.prng.rand_uint16() % 8 @@ -154,7 +159,7 @@ class Game(object): score = 0 bonus = 2000 for bullet in self.bullets: - #TODO: display the labels. + label = self.new_label((bullet.x, bullet.y), str(bonus)) score += bonus bonus += 10 self.bullets = [] @@ -181,6 +186,13 @@ class Game(object): self.msg_runner.run_iteration() + def new_label(self, pos, text): + label = Text(pos, self.ascii_wrapper, text=text, xspacing=8, shift=48) + label.set_timeout(60) + self.labels.append(label) + return label + + def run_iter(self, keystate): # 1. VMs. self.ecl_runner.run_iter() @@ -213,6 +225,8 @@ class Game(object): for laser in self.lasers: #TODO: what priority is it? laser.update() self.interface.update() # Pri 12 + for label in self.labels: #TODO: what priority is it? + label.update() # 5. Clean up self.cleanup() @@ -381,6 +395,8 @@ class Game(object): self.modify_difficulty(-3) self.items = items + self.labels = [label for label in self.labels if not label.removed] + # Disable boss mode if it is dead/it has timeout if self.boss and self.boss._enemy.removed: self.boss = None
--- a/pytouhou/game/item.py +++ b/pytouhou/game/item.py @@ -78,6 +78,8 @@ class Item(object): player_state = player.state old_power = player_state.power score = 0 + label = None + color = 'white' if self._type == 0 or self._type == 2: # power or big power if old_power < 128: @@ -86,6 +88,12 @@ class Item(object): player_state.power += (1 if self._type == 0 else 8) if player_state.power > 128: player_state.power = 128 + for level in (8, 16, 32, 48, 64, 96): + if old_power < level and player_state.power >= level: + label = self._game.new_label((self.x, self.y), ':') # Actually a “PowerUp” character. + color = 'blue' + label.set_color(color) + labeled = True else: bonus = player_state.power_bonus + (1 if self._type == 0 else 8) if bonus > 30: @@ -98,6 +106,7 @@ class Item(object): score = (bonus - 17) * 1000 elif bonus == 30: score = 51200 + color = 'yellow' player_state.power_bonus = bonus self._game.modify_difficulty(+1) @@ -107,6 +116,7 @@ class Item(object): if player_state.y < poc: score = 100000 self._game.modify_difficulty(+30) + color = 'yellow' else: #score = #TODO: find the formula. self._game.modify_difficulty(+3) @@ -133,8 +143,11 @@ class Item(object): self._game.change_bullets_into_star_items() if score > 0: - #TODO: display the score. player_state.score += score + if not label: + label = self._game.new_label((self.x, self.y), str(score)) + if color != 'white': + label.set_color(color) self.removed = True
--- a/pytouhou/game/text.py +++ b/pytouhou/game/text.py @@ -31,6 +31,7 @@ class Widget(object): self.sprite = None self.removed = False self.changed = True + self.anmrunner = None # Set up the backround sprite self.back_wrapper = back_wrapper @@ -87,9 +88,10 @@ class GlyphCollection(Widget): class Text(GlyphCollection): - def __init__(self, pos, ascii_wrapper, back_wrapper=None, text=''): - GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper) + def __init__(self, pos, ascii_wrapper, back_wrapper=None, text='', xspacing=14, shift=21): + GlyphCollection.__init__(self, pos, ascii_wrapper, back_wrapper, xspacing=xspacing) self.text = '' + self.shift = shift self.set_text(text) @@ -98,11 +100,32 @@ class Text(GlyphCollection): if text == self.text: return - self.set_sprites([ord(c) - 21 for c in text]) + self.set_sprites([ord(c) - self.shift for c in text]) self.text = text self.changed = True + def set_color(self, color): + colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), 'blue': (192, 192, 255)} + for glyph in self.glyphes: + glyph.sprite.color = colors[color] + + + def timeout_update(self): + GlyphCollection.update(self) + if self.timeout % 2: + for glyph in self.glyphes: + glyph.y -= 1 + self.timeout -= 1 + if self.timeout == 0: + self.removed = True + + + def set_timeout(self, timeout): + self.timeout = timeout + self.update = self.timeout_update + + class Counter(GlyphCollection): def __init__(self, pos, anm_wrapper, back_wrapper=None, script=0, xspacing=16, value=0):
--- a/pytouhou/ui/gamerenderer.pyx +++ b/pytouhou/ui/gamerenderer.pyx @@ -90,7 +90,7 @@ cdef class GameRenderer(Renderer): *(player.objects() for player in game.players))) self.render_elements(chain(game.bullets, game.lasers, game.cancelled_bullets, game.items, - (item.indicator for item in game.items if item.indicator))) - #TODO: display item indicators + (item.indicator for item in game.items if item.indicator), + *(label.objects() for label in game.labels))) glEnable(GL_FOG)