about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2018-05-31 22:06:28 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2018-05-31 22:07:07 +0700
commit654a1a2c5e8a30a11002e859f84b46fc20ab4356 (patch)
treef1ca68dac0f6f9efe6e3e74ed27a8fa92ec69e21
parentcbaec90dd12bc5d9bea63c315ce835c8207e6fa0 (diff)
downloadbrutalmaze-654a1a2c5e8a30a11002e859f84b46fc20ab4356.tar.gz
Fix bug that walls out of display can still be turned into enemies
-rw-r--r--brutalmaze/game.py5
-rw-r--r--brutalmaze/maze.py24
-rwxr-xr-xsetup.py2
3 files changed, 18 insertions, 13 deletions
diff --git a/brutalmaze/game.py b/brutalmaze/game.py
index 7240439..6962df6 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.7.3'
+__version__ = '0.7.4'
 
 import re
 from argparse import ArgumentParser, FileType, RawTextHelpFormatter
@@ -321,8 +321,7 @@ class Game:
                 maze.stepx = maze.stepy = 0
             elif autove:
                 maze.destx, maze.desty = maze.get_grid(x, y)
-                maze.set_step(lambda x: maze.rangex[0] <= x <= maze.rangex[-1],
-                              lambda y: maze.rangey[0] <= y <= maze.rangey[-1])
+                maze.set_step(maze.is_displayed)
                 if maze.stepx == maze.stepy == 0:
                     maze.destx = maze.desty = MIDDLE
 
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index d733716..b1614c3 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -169,6 +169,13 @@ class Maze:
         pygame.display.set_caption(
             'Brutal Maze - Score: {}'.format(self.get_score()))
 
+    def is_displayed(self, x, y):
+        """Return True if the grid (x, y) is in the displayable part
+        of the map, False otherwise.
+        """
+        return (self.rangex[0] <= x <= self.rangex[-1]
+                and self.rangey[0] <= y <= self.rangey[-1])
+
     def rotate(self):
         """Rotate the maze if needed."""
         x = int((self.centerx-self.x) * 2 / self.distance)
@@ -195,8 +202,7 @@ class Maze:
         killist = []
         for i, enemy in enumerate(self.enemies):
             enemy.place(x, y)
-            if not (self.rangex[0] <= enemy.x <= self.rangex[-1]
-                    and self.rangey[0] <= enemy.y <= self.rangey[-1]):
+            if not self.is_displayed(enemy.x, enemy.y):
                 self.score += enemy.wound
                 enemy.die()
                 killist.append(i)
@@ -279,15 +285,15 @@ class Maze:
         for i, bullet in enumerate(self.bullets):
             wound = bullet.fall_time / BULLET_LIFETIME
             bullet.update(self.fps, self.distance)
-            if wound < 0:
+            gridx, gridy = self.get_grid(bullet.x, bullet.y)
+            if wound < 0 or not self.is_displayed(gridx, gridy):
                 fallen.append(i)
             elif bullet.color == 'Aluminium':
-                x, y = self.get_grid(bullet.x, bullet.y)
-                if self.map[x][y] == WALL and self.next_move <= 0:
+                if self.map[gridx][gridy] == WALL and self.next_move <= 0:
                     self.glitch = wound * 1000
-                    enemy = new_enemy(self, x, y)
+                    enemy = new_enemy(self, gridx, gridy)
                     enemy.awake = True
-                    self.map[x][y] = ENEMY
+                    self.map[gridx][gridy] = ENEMY
                     play(self.sfx_spawn,
                          1 - enemy.get_distance()/self.get_distance(0, 0)/2,
                          enemy.get_angle() + pi)
@@ -376,7 +382,7 @@ class Maze:
         self.rangey = list(range(MIDDLE - h, MIDDLE + h + 1))
         self.slashd = self.hero.R + self.distance/SQRT2
 
-    def set_step(self, xcheck=(lambda _: True), ycheck=(lambda _: True)):
+    def set_step(self, check=(lambda x, y: True)):
         """Return direction on the shortest path to the destination."""
         if self.stepx or self.stepy and self.vx == self.vy == 0.0:
             x, y = MIDDLE - self.stepx, MIDDLE - self.stepy
@@ -409,7 +415,7 @@ class Maze:
                 self.stepx, self.stepy = dx, dy
                 return
             for i, j in around(x, y):
-                if self.map[i][j] == EMPTY and xcheck(i) and ycheck(j):
+                if self.map[i][j] == EMPTY and check(i, j):
                     queue[distance + 1].append((i, j))
                     count += 1
         self.stepx, self.stepy = 0, 0
diff --git a/setup.py b/setup.py
index 6355eea..bee16d6 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.7.3',
+    version='0.7.4',
     description='A minimalist TPS game with fast-paced action',
     long_description=long_description,
     url='https://github.com/McSinyx/brutalmaze',