summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-27 15:47:05 +0200
committerViljami Ilola <+@hix.fi>2024-03-27 15:47:05 +0200
commita0cbc5902996b52290afb486b3e2554e1abc123c (patch)
tree55f600717de02e961771932ad0e39080351f20cf /src
parent61a1248e340d1c87a6c4e7dec77f1089984b87b6 (diff)
colored texts
Diffstat (limited to 'src')
-rw-r--r--src/sliceitoff/display/__init__.py1
-rw-r--r--src/sliceitoff/display/colors.py21
-rw-r--r--src/sliceitoff/status/status.py10
-rw-r--r--src/sliceitoff/text/text.py11
4 files changed, 36 insertions, 7 deletions
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))