From a0cbc5902996b52290afb486b3e2554e1abc123c Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Wed, 27 Mar 2024 15:47:05 +0200 Subject: colored texts --- src/sliceitoff/display/__init__.py | 1 + src/sliceitoff/display/colors.py | 21 +++++++++++++++++++++ src/sliceitoff/status/status.py | 10 +++++----- src/sliceitoff/text/text.py | 11 +++++++++-- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/sliceitoff/display/colors.py diff --git a/src/sliceitoff/display/__init__.py b/src/sliceitoff/display/__init__.py index 1decd21..42c1b12 100644 --- a/src/sliceitoff/display/__init__.py +++ b/src/sliceitoff/display/__init__.py @@ -1,3 +1,4 @@ from .scaling import Scaling from .display import Display from .static import INTERNAL_WIDTH, INTERNAL_HEIGHT +from .colors import EGA_COLORS diff --git a/src/sliceitoff/display/colors.py b/src/sliceitoff/display/colors.py new file mode 100644 index 0000000..18ccfc9 --- /dev/null +++ b/src/sliceitoff/display/colors.py @@ -0,0 +1,21 @@ +""" text.colors - colors are defined here """ + +EGA_COLORS=[ + (0x00,0x00,0x00,0xFF), + (0x00,0x00,0xAA,0xFF), + (0x00,0xAA,0x00,0xFF), + (0x00,0xAA,0xAA,0xFF), + (0xAA,0x00,0x00,0xFF), + (0xAA,0x00,0xAA,0xFF), + (0xAA,0x55,0x00,0xFF), + (0xAA,0xAA,0xAA,0xFF), + (0x55,0x55,0x55,0xFF), + (0x55,0x55,0xFF,0xFF), + (0x55,0xFF,0x55,0xFF), + (0x55,0xFF,0xFF,0xFF), + (0xFF,0x55,0x55,0xFF), + (0xFF,0x55,0xFF,0xFF), + (0xFF,0xFF,0x55,0xFF), + (0xFF,0xFF,0xFF,0xFF) +] + diff --git a/src/sliceitoff/status/status.py b/src/sliceitoff/status/status.py index ea93b88..ad3034c 100644 --- a/src/sliceitoff/status/status.py +++ b/src/sliceitoff/status/status.py @@ -12,11 +12,11 @@ class Status(pygame.sprite.Group): """ Rebuilds statusline if needed """ super().update(**kwargs) score_str = ( - f"\x12{Stats.level:<2d}" - f"\x03{Stats.lives:<2d}" - f"\x0e{Stats.bonus // 1000:<3d}" - f"\xfe{99 if Stats.percent == 100 else int(Stats.percent):<3d}" - f"\x0f{Stats.enemies-Stats.field_count:<3d}" + f"\xee\x12\xef{Stats.level:<2d}" + f"\xec\x03\xef{Stats.lives:<2d}" + f"\xed\x0e\xef{Stats.bonus // 1000:<3d}" + f"\xe9\xfe\xef{99 if Stats.percent == 100 else int(Stats.percent):<3d}" + f"\xea\x0f\xef{Stats.enemies-Stats.field_count:<3d}" f"{Stats.score:08d}") if self.old_srt != score_str: self.empty() diff --git a/src/sliceitoff/text/text.py b/src/sliceitoff/text/text.py index 424bbc2..8c13004 100644 --- a/src/sliceitoff/text/text.py +++ b/src/sliceitoff/text/text.py @@ -2,7 +2,7 @@ import pygame from random import randrange from images import Fonts -from display import Scaling +from display import Scaling, EGA_COLORS scaled_fonts = {} @@ -38,6 +38,7 @@ class TextPage(pygame.sprite.Group): super().__init__() if grid == None: grid = size + color = 0xf col, row = 0, 0 x, y = pos w, h = grid @@ -49,14 +50,20 @@ class TextPage(pygame.sprite.Group): if ch_txt == '\t': col = (col + 4) % 4 continue - font_key = (font, w) ch = ord(ch_txt) + if ch in range(0xe0,0xf0): + color = ch - 0xe0 + continue + font_key = (font, w, color) if font_key not in scaled_fonts: scaled_fonts[font_key]=[None for _ in range(256)] if scaled_fonts[font_key][ch] == None: scaled_fonts[font_key][ch] = pygame.transform.scale_by( Fonts.fonts[font].get(ch), size[0]/8 * Scaling.factor) + scaled_fonts[font_key][ch].fill( + EGA_COLORS[color], + special_flags = pygame.BLEND_RGBA_MULT) image = scaled_fonts[font_key][ch] image_pos = Scaling.scale_to_display( (x+col*w, y+row*h) ) self.add(LetterSprite(image, image_pos)) -- cgit v1.2.3