tighogg

fighting game for the terminal
git clone https://git.ce9e.org/tighogg.git

commit
952337d4891b8115daa1c48af4fe37dbdaeef435
parent
3093c24276abea84a9450a3716ea949b0a11c510
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2021-05-09 16:04
improve rendering

Diffstat

M tighogg.py 22 ++++++++++++----------

1 files changed, 12 insertions, 10 deletions


diff --git a/tighogg.py b/tighogg.py

@@ -41,12 +41,14 @@ class Map:
   41    41         return math.inf
   42    42 
   43    43     def render(self, camera, cols, rows):
   -1    44         sys.stdout.write(boon.get_cap('setaf', 7))
   44    45         for x in range(cols):
   45    46             y = self.get_floor(camera + x)
   46    47             if y is math.inf:
   47    48                 continue
   48    49             boon.move(y + rows // 2 + 1, x)
   49    50             sys.stdout.write('#')
   -1    51         sys.stdout.write(boon.get_cap('sgr0'))
   50    52 
   51    53 
   52    54 class Player:
@@ -147,6 +149,10 @@ class Player:
  147   149             yield r'  / |  '
  148   150 
  149   151     def render(self, camera, cols, rows):
   -1   152         sys.stdout.write(
   -1   153             boon.get_cap('setaf', self.color)
   -1   154             + boon.get_cap('bold')
   -1   155         )
  150   156         for i, line in enumerate(self._render()):
  151   157             if self.direction == LEFT:
  152   158                 line = (
@@ -155,17 +161,13 @@ class Player:
  155   161                     .replace('\\', '/')
  156   162                     .replace('1', '\\')
  157   163                 )
  158    -1             x = round(self.x - camera) - 3 + len(line) - len(line.lstrip())
   -1   164             x = round(self.x - camera) - 3
  159   165             y = round(self.y - 3 + i)
  160    -1             if x < 0:
  161    -1                 continue
  162    -1             boon.move(y + rows // 2, x)
  163    -1             sys.stdout.write(
  164    -1                 boon.get_cap('setaf', self.color)
  165    -1                 + boon.get_cap('bold')
  166    -1                 + line.strip()
  167    -1                 + boon.get_cap('sgr0')
  168    -1             )
   -1   166             for j, c in enumerate(line):
   -1   167                 if c != ' ':
   -1   168                     boon.move(y + rows // 2, x + j)
   -1   169                     sys.stdout.write(c)
   -1   170         sys.stdout.write(boon.get_cap('sgr0'))
  169   171 
  170   172 
  171   173 class Game: