diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-30 12:07:49 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-30 12:07:49 +0200 |
commit | 607c00bc57fb68572754404cb5da0e7f7a5618e5 (patch) | |
tree | 195f10e6506a1c30500662230c807dc2756431af /src/sliceitoff/text/text.py | |
parent | 51c495d9691d19b65b377d377599ce1d52def874 (diff) |
refactor enemies to add bounchers
Diffstat (limited to 'src/sliceitoff/text/text.py')
-rw-r--r-- | src/sliceitoff/text/text.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/sliceitoff/text/text.py b/src/sliceitoff/text/text.py index 83367e0..69a30bc 100644 --- a/src/sliceitoff/text/text.py +++ b/src/sliceitoff/text/text.py @@ -8,28 +8,35 @@ from .fonts import Fonts scaled_fonts = {} -class LetterSprite(pygame.sprite.Sprite): - """ Single letter at given properties hopefully from cache +def get_letter_surface(font_key, ch): + """ Get letter surface at given properties hopefully from cache args: font_key: (font name, width to scale, color) ch: 0-255 character on cp473 color: 0-15 as in CGA palette """ + font, w, color = font_key + if font not in Fonts.fonts: + return None + if font_key not in scaled_fonts: + scaled_fonts[font_key]=[None for _ in range(256)] + if scaled_fonts[font_key][ch] is None: + scaled_fonts[font_key][ch] = pygame.transform.scale_by( + Fonts.fonts[font].get(ch), + w/8 * Scaling.factor) + scaled_fonts[font_key][ch].fill( + CGA_COLORS[color], + special_flags = pygame.BLEND_RGBA_MULT) + return scaled_fonts[font_key][ch] + + +class LetterSprite(pygame.sprite.Sprite): + """ Make sprite out of letter surface at given position """ def __init__(self, font_key, ch, pos): super().__init__() self.dead = True - if font_key not in scaled_fonts: - scaled_fonts[font_key]=[None for _ in range(256)] - if scaled_fonts[font_key][ch] is None: - font, w, color = font_key - scaled_fonts[font_key][ch] = pygame.transform.scale_by( - Fonts.fonts[font].get(ch), - w/8 * Scaling.factor) - scaled_fonts[font_key][ch].fill( - CGA_COLORS[color], - special_flags = pygame.BLEND_RGBA_MULT) - self.image = scaled_fonts[font_key][ch] + self.image = get_letter_surface(font_key, ch) self.rect = self.image.get_rect().move(pos) self.direction = ( Scaling.factor * (1_000 - randrange(2_000)), |