tighogg

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

commit
9015fbf53be5624cab9b7e451da4514d06cc7e2f
parent
3936189462dcdd322ad2fe3171ecbf7ef7cb5bb6
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2021-05-10 06:47
die on contact

Diffstat

M tighogg.py 43 ++++++++++++++++++++++++++++++++-----------

1 files changed, 32 insertions, 11 deletions


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

@@ -110,7 +110,7 @@ class Player:
  110   110         if self.floor == self.y:
  111   111             self.dy = -JUMP_VELOCITY
  112   112 
  113    -1     def _render(self):
   -1   113     def _get_sprite(self):
  114   114         if self.dy > 0:
  115   115             yield r' __O  /'
  116   116             yield r'   /\/ '
@@ -148,12 +148,8 @@ class Player:
  148   148             yield r'   |\  '
  149   149             yield r'  / |  '
  150   150 
  151    -1     def render(self, camera, cols, rows):
  152    -1         sys.stdout.write(
  153    -1             boon.get_cap('setaf', self.color)
  154    -1             + boon.get_cap('bold')
  155    -1         )
  156    -1         for i, line in enumerate(self._render()):
   -1   151     def get_chars(self):
   -1   152         for i, line in enumerate(self._get_sprite()):
  157   153             if self.direction == LEFT:
  158   154                 line = (
  159   155                     line[::-1]
@@ -161,12 +157,33 @@ class Player:
  161   157                     .replace('\\', '/')
  162   158                     .replace('1', '\\')
  163   159                 )
  164    -1             x = round(self.x - camera) - 3
  165    -1             y = round(self.y - 3 + i)
  166   160             for j, c in enumerate(line):
  167   161                 if c != ' ':
  168    -1                     boon.move(y + rows // 2, x + j)
  169    -1                     sys.stdout.write(c)
   -1   162                     yield j - 3, i - 3, c
   -1   163 
   -1   164     def touches(self, other):
   -1   165         if not self.alive or not other.alive:
   -1   166             return False
   -1   167         a = set(
   -1   168             (round(self.x + dx), round(self.y + dy))
   -1   169             for dx, dy, c in self.get_chars()
   -1   170         )
   -1   171         b = set(
   -1   172             (round(other.x + dx), round(other.y + dy))
   -1   173             for dx, dy, c in other.get_chars()
   -1   174         )
   -1   175         return a.intersection(b)
   -1   176 
   -1   177     def render(self, camera, cols, rows):
   -1   178         sys.stdout.write(
   -1   179             boon.get_cap('setaf', self.color)
   -1   180             + boon.get_cap('bold')
   -1   181         )
   -1   182         for dx, dy, c in self.get_chars():
   -1   183             x = round(self.x + dx - camera)
   -1   184             y = round(self.y + dy) + rows // 2
   -1   185             boon.move(y, x)
   -1   186             sys.stdout.write(c)
  170   187         sys.stdout.write(boon.get_cap('sgr0'))
  171   188 
  172   189 
@@ -284,6 +301,10 @@ class Game:
  284   301                     if player.y > 2 * BLOCK_HEIGHT:
  285   302                         player.die()
  286   303 
   -1   304                 # die on contact
   -1   305                 if self.leader.touches(self.straggler):
   -1   306                     self.leader.die()
   -1   307 
  287   308                 # respawn on edge of screen
  288   309                 for player in self.players:
  289   310                     if not player.alive and player.cooldown <= 0: