about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-07-24 12:45:25 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-07-24 13:20:31 +0700
commit622df8c361b2da20693962fb4f119edffa69228f (patch)
tree42272342de983e1c435881aeae8b07c586a7e5e2
parent4f18daa2342fb4a0d97b1e241d19674d3ab9df60 (diff)
downloadbrutalmaze-622df8c361b2da20693962fb4f119edffa69228f.tar.gz
Fix zombie enemies and heart rate 0.8.26
-rw-r--r--brutalmaze/characters.py4
-rw-r--r--brutalmaze/constants.py2
-rw-r--r--brutalmaze/game.py2
-rw-r--r--brutalmaze/maze.py13
-rwxr-xr-xsetup.py2
5 files changed, 10 insertions, 13 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py
index 6edfb71..1febf00 100644
--- a/brutalmaze/characters.py
+++ b/brutalmaze/characters.py
@@ -161,6 +161,7 @@ class Enemy:
         x, y (int): coordinates of the center of the enemy (in grids)
         angle (float): angle of the direction the enemy pointing (in radians)
         color (str): enemy's color name
+        alive (bool): flag indicating if the enemy is alive
         awake (bool): flag indicating if the enemy is active
         next_strike (float): time until the enemy's next action (in ms)
         move_speed (float): speed of movement (in frames per grid)
@@ -175,7 +176,7 @@ class Enemy:
         self.x, self.y = x, y
         self.angle, self.color = pi / 4, color
 
-        self.awake = False
+        self.alive, self.awake = True, False
         self.next_strike = 0.0
         self.move_speed = self.maze.fps / ENEMY_SPEED
         self.offsetx = self.offsety = 0
@@ -354,6 +355,7 @@ class Enemy:
                 self.maze.enemy_weights[self.color] -= 1.5
         else:
             self.maze.map[self.x][self.y] = WALL
+        self.alive = False
 
 
 class Chameleon(Enemy):
diff --git a/brutalmaze/constants.py b/brutalmaze/constants.py
index 24ad23a..23fa040 100644
--- a/brutalmaze/constants.py
+++ b/brutalmaze/constants.py
@@ -80,7 +80,7 @@ COLORS = {c: COLOR_CODE[i] for i, c in enumerate(
 MINW, MAXW = 24, 36
 ENEMY_HP = 3
 HERO_HP = 5
-MIN_BEAT = 526
+MIN_BEAT = 420
 BG_COLOR = TANGO['Aluminium'][-1]
 FG_COLOR = TANGO['Aluminium'][0]
 
diff --git a/brutalmaze/game.py b/brutalmaze/game.py
index cd34199..181346f 100644
--- a/brutalmaze/game.py
+++ b/brutalmaze/game.py
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Brutal Maze.  If not, see <https://www.gnu.org/licenses/>.
 
-__version__ = '0.8.25'
+__version__ = '0.8.26'
 
 import re
 from argparse import ArgumentParser, FileType, RawTextHelpFormatter
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index ef4f13f..119eab1 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -132,6 +132,7 @@ class Maze:
 
     def add_enemy(self):
         """Add enough enemies."""
+        self.enemies = [e for e in self.enemies if e.alive]
         walls = [(i, j) for i in self.rangex for j in self.rangey
                  if self.map[i][j] == WALL]
         plums = [e for e in self.enemies if e.color == 'Plum' and e.awake]
@@ -223,14 +224,11 @@ class Maze:
         self.stepx = self.stepy = 0
 
         # Respawn the enemies that fall off the display
-        killist = []
         for i, enemy in enumerate(self.enemies):
             enemy.place(x, y)
             if not self.isdisplayed(enemy.x, enemy.y):
                 self.score += enemy.wound
                 enemy.die()
-                killist.append(i)
-        for i in reversed(killist): self.enemies.pop(i)
         self.add_enemy()
 
         # LockOn target is not yet updated.
@@ -281,8 +279,7 @@ class Maze:
         """Handle close-range attacks."""
         for enemy in self.enemies: enemy.slash()
         if not self.hero.spin_queue: return
-        killist = []
-        for i, enemy in enumerate(self.enemies):
+        for enemy in filter(lambda e: e.awake, self.enemies):
             d = self.slashd - enemy.distance
             if d > 0:
                 wound = d * SQRT2 / self.distance
@@ -293,8 +290,6 @@ class Maze:
                 if enemy.wound >= ENEMY_HP:
                     self.score += enemy.wound
                     enemy.die()
-                    killist.append(i)
-        for i in reversed(killist): self.enemies.pop(i)
         self.add_enemy()
 
     def track_bullets(self):
@@ -323,13 +318,13 @@ class Maze:
                     enemy.hit(wound)
                     self.enemies.append(enemy)
                     continue
-                for j, enemy in enumerate(active_enemies):
+                for enemy in active_enemies:
                     if bullet.get_distance(*enemy.pos) < self.distance:
                         enemy.hit(wound)
                         if enemy.wound >= ENEMY_HP:
                             self.score += enemy.wound
                             enemy.die()
-                            self.enemies.pop(j)
+                            self.add_enemy()
                         play(bullet.sfx_hit, wound, bullet.angle)
                         fallen.append(i)
                         break
diff --git a/setup.py b/setup.py
index 15bf0da..b06df68 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.8.25',
+    version='0.8.26',
     description="Minimalist thrilling shoot 'em up game",
     long_description=long_description,
     url='https://github.com/McSinyx/brutalmaze',