- commit
- 5bced85117ca5452ba8fe91a9d8f84e5890ed863
- parent
- 1c3c168ad5fc1dec797f14aa1a4b695ba08e2fd1
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2014-10-11 09:52
fix pygame delch() although we use a monospaced font, seemingly not all chars have the same width. In the example this reulted in trails behind the moving char.
Diffstat
| M | dirtywords/pygame_core.py | 15 | ++++++++++++--- |
1 files changed, 12 insertions, 3 deletions
diff --git a/dirtywords/pygame_core.py b/dirtywords/pygame_core.py
@@ -15,7 +15,8 @@ class Screen(base.Screen): 15 15 self.clock = pygame.time.Clock() 16 16 17 17 self.font = pygame.font.SysFont('monospace', 12)18 -1 self.fontwidth, self.fontheight = self.font.size(' ')-1 18 reference_char = 'M' # some arbitrary char to measure the fontsize -1 19 self.fontwidth, self.fontheight = self.font.size(reference_char) 19 20 20 21 self.pygame_screen = pygame.display.set_mode( 21 22 (self.fontwidth * width, self.fontheight * height)) @@ -61,14 +62,22 @@ class Screen(base.Screen): 61 62 self.font.set_bold(ch.strong) 62 63 self.font.set_italic(ch.emph) 63 64 self.font.set_underline(ch.underline)64 -1 return self.font.render(ch, False, ch.fg_color, ch.bg_color)-1 65 -1 66 s = self.font.render(ch, False, ch.fg_color, ch.bg_color) -1 67 -1 68 # make sure the returned surface has the right dimensions -1 69 surface = pygame.Surface((self.fontwidth, self.fontheight)) -1 70 surface.fill(ch.bg_color) -1 71 surface.blit(s, (0, 0)) -1 72 return surface 65 73 66 74 def putstr(self, y, x, s): 67 75 super(Screen, self).putstr(y, x, s) 68 76 for i, ch in enumerate(s): 69 77 self.pygame_screen.blit( 70 78 self._render_ch(ch),71 -1 ((x + i) * self.fontwidth, y * self.fontheight))-1 79 ((x + i) * self.fontwidth, y * self.fontheight), -1 80 area=(0, 0, self.fontwidth, self.fontheight)) 72 81 73 82 def refresh(self): 74 83 self.clock.tick()