about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2018-05-21 23:21:20 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2018-05-22 09:54:08 +0700
commit9a896890fab2c831bacbda52bab8c78a182dd141 (patch)
tree3316f2799cbdece37db02aeedf2483d3ba43066b
parent9dff378b57fbe16aa9edde9e3bc4eab959081e83 (diff)
downloadbrutalmaze-9a896890fab2c831bacbda52bab8c78a182dd141.tar.gz
Turn wall grids into enemies when they are shot
-rw-r--r--brutalmaze/characters.py13
-rw-r--r--brutalmaze/game.py10
-rw-r--r--brutalmaze/maze.py51
-rwxr-xr-xsetup.py2
m---------wiki0
5 files changed, 46 insertions, 30 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py
index ab517c1..1414645 100644
--- a/brutalmaze/characters.py
+++ b/brutalmaze/characters.py
@@ -148,7 +148,6 @@ class Enemy:
     def __init__(self, maze, x, y, color):
         self.maze = maze
         self.x, self.y = x, y
-        self.maze.map[x][y] = ENEMY
         self.angle, self.color = pi / 4, color
 
         self.awake = False
@@ -176,7 +175,7 @@ class Enemy:
         """Move the enemy by (x, y) (in grids)."""
         self.x += x
         self.y += y
-        self.maze.map[self.x][self.y] = ENEMY
+        if self.awake: self.maze.map[self.x][self.y] = ENEMY
 
     def wake(self):
         """Wake the enemy up if it can see the hero.
@@ -195,11 +194,13 @@ class Enemy:
         def get_distance(x, y): return abs(dy*x - dx*y) / (dy**2 + dx**2)**0.5
         for i in range(startx, stopx + 1):
             for j in range(starty, stopy + 1):
-                if self.maze.map[i][j] != WALL: continue
+                if self.maze.map[i][j] != WALL or i == stopx and j == stopy:
+                    continue
                 x, y = self.maze.get_pos(i, j)
                 if get_distance(x - self.maze.x, y - self.maze.y) <= mind:
                     return False
         self.awake = True
+        self.maze.map[self.x][self.y] = ENEMY
         play(self.maze.sfx_spawn,
              1 - self.get_distance()/self.maze.get_distance(0, 0)/2,
              self.get_angle() + pi)
@@ -265,13 +266,13 @@ class Enemy:
 
     def get_color(self):
         """Return current color of the enemy."""
-        return TANGO[self.color][int(self.wound)] if self.awake else FG_COLOR
+        return TANGO[self.color][int(self.wound)]
 
 
     def draw(self):
         """Draw the enemy."""
-        if self.maze.next_move > 0 and not self.awake: return
-        radius = self.maze.distance/SQRT2 - self.awake*2
+        if not self.awake: return
+        radius = self.maze.distance / SQRT2
         square = regpoly(4, radius, self.angle, *self.get_pos())
         fill_aapolygon(self.maze.surface, square, self.get_color())
 
diff --git a/brutalmaze/game.py b/brutalmaze/game.py
index 8c30686..de70881 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.0'
+__version__ = '0.7.1'
 
 import re
 from argparse import ArgumentParser, FileType, RawTextHelpFormatter
@@ -158,11 +158,8 @@ class Game:
         ne = nb = 0
 
         for enemy in maze.enemies:
-            if not enemy.awake and walls:
-                walls[enemy.y-maze.rangey[0]][enemy.x-maze.rangex[0]] = WALL
-                continue
             # Check Chameleons
-            elif getattr(enemy, 'visible', 1) <= 0 and maze.next_move <= 0:
+            if getattr(enemy, 'visible', 1) <= 0 and maze.next_move <= 0:
                 continue
             lines.append('{0} {2} {3} {1:.0f}'.format(
                 COLORS[enemy.get_color()], deg(enemy.angle),
@@ -321,8 +318,7 @@ class Game:
                 maze.destx = maze.desty = MIDDLE
                 maze.stepx = maze.stepy = 0
             elif autove:
-                maze.destx = MIDDLE + round2((x-maze.centerx) / maze.distance)
-                maze.desty = MIDDLE + round2((y-maze.centery) / maze.distance)
+                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])
                 if maze.stepx == maze.stepy == 0:
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index e98e421..43bc4b0 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -27,10 +27,10 @@ import pygame
 
 from .characters import Hero, new_enemy
 from .constants import (
-    EMPTY, WALL, HERO, ROAD_WIDTH, MAZE_SIZE, MIDDLE, INIT_SCORE, ENEMIES,
-    MINW, MAXW, SQRT2, SFX_SPAWN, SFX_SLASH_ENEMY, SFX_LOSE, ADJACENTS,
-    BG_COLOR, FG_COLOR, CELL_WIDTH, LAST_ROW, HERO_HP, ENEMY_HP, ATTACK_SPEED,
-    HERO_SPEED, BULLET_LIFETIME)
+    EMPTY, WALL, HERO, ENEMY, ROAD_WIDTH, MAZE_SIZE, MIDDLE, INIT_SCORE,
+    ENEMIES, MINW, MAXW, SQRT2, SFX_SPAWN, SFX_SLASH_ENEMY, SFX_LOSE,
+    ADJACENTS, TANGO, BG_COLOR, FG_COLOR, CELL_WIDTH, LAST_ROW,
+    HERO_HP, ENEMY_HP, ATTACK_SPEED, HERO_SPEED, BULLET_LIFETIME)
 from .misc import round2, sign, around, regpoly, fill_aapolygon, play
 from .weapons import Bullet
 
@@ -77,6 +77,7 @@ class Maze:
         destx, desty (int): the grid the hero is moving to
         stepx, stepy (int): direction the maze is moving
         next_move (float): time until the hero gets mobilized (in ms)
+        glitch (float): time that the maze remain flashing colors (in ms)
         next_slashfx (float): time until next slash effect of the hero (in ms)
         slashd (float): minimum distance for slashes to be effective
         sfx_slash (pygame.mixer.Sound): sound effect of slashed enemy
@@ -109,7 +110,7 @@ class Maze:
         self.map[MIDDLE][MIDDLE] = HERO
         self.destx = self.desty = MIDDLE
         self.stepx = self.stepy = 0
-        self.next_move = self.next_slashfx = 0.0
+        self.next_move = self.glitch = self.next_slashfx = 0.0
         self.slashd = self.hero.R + self.distance/SQRT2
 
         self.sfx_spawn = SFX_SPAWN
@@ -129,20 +130,26 @@ class Maze:
                 continue
             enemy = new_enemy(self, x, y)
             self.enemies.append(enemy)
-            if plum is None or not plum.clone(enemy):
-                walls.remove((x, y))
-            else:
-                self.map[x][y] = WALL
+            if plum is None or not plum.clone(enemy): walls.remove((x, y))
 
     def get_pos(self, x, y):
         """Return coordinate of the center of the grid (x, y)."""
         return (self.centerx + (x - MIDDLE)*self.distance,
                 self.centery + (y - MIDDLE)*self.distance)
 
+    def get_grid(self, x, y):
+        """Return the grid containing the point (x, y)."""
+        return (MIDDLE + round2((x-self.centerx) / self.distance),
+                MIDDLE + round2((y-self.centery) / self.distance))
+
     def get_score(self):
         """Return the current score."""
         return int(self.score - INIT_SCORE)
 
+    def get_color(self):
+        """Return color of a grid."""
+        return choice(TANGO.values())[0] if self.glitch > 0 else FG_COLOR
+
     def draw(self):
         """Draw the maze."""
         self.surface.fill(BG_COLOR)
@@ -152,7 +159,7 @@ class Maze:
                     if self.map[i][j] != WALL: continue
                     x, y = self.get_pos(i, j)
                     square = regpoly(4, self.distance / SQRT2, pi / 4, x, y)
-                    fill_aapolygon(self.surface, square, FG_COLOR)
+                    fill_aapolygon(self.surface, square, self.get_color())
 
         for enemy in self.enemies: enemy.draw()
         if not self.hero.dead: self.hero.draw()
@@ -167,7 +174,9 @@ class Maze:
         x = int((self.centerx-self.x) * 2 / self.distance)
         y = int((self.centery-self.y) * 2 / self.distance)
         if x == y == 0: return
-        for enemy in self.enemies: self.map[enemy.x][enemy.y] = EMPTY
+        for enemy in self.enemies:
+            if self.map[enemy.x][enemy.y] == ENEMY:
+                self.map[enemy.x][enemy.y] = EMPTY
 
         self.map[MIDDLE][MIDDLE] = EMPTY
         self.centerx -= x * self.distance
@@ -273,9 +282,17 @@ class Maze:
             if wound < 0:
                 fallen.append(i)
             elif bullet.color == 'Aluminium':
-                x = MIDDLE + round2((bullet.x-self.x) / self.distance)
-                y = MIDDLE + round2((bullet.y-self.y) / self.distance)
+                x, y = self.get_grid(bullet.x, bullet.y)
                 if self.map[x][y] == WALL and self.next_move <= 0:
+                    self.glitch = wound * 1000
+                    enemy = new_enemy(self, x, y)
+                    enemy.awake = True
+                    self.map[x][y] = ENEMY
+                    play(self.sfx_spawn,
+                         1 - enemy.get_distance()/self.get_distance(0, 0)/2,
+                         enemy.get_angle() + pi)
+                    enemy.hit(wound)
+                    self.enemies.append(enemy)
                     fallen.append(i)
                     continue
                 for j, enemy in enumerate(self.enemies):
@@ -327,11 +344,12 @@ class Maze:
         self.vy = self.is_valid_move(vy=self.vy)
         self.centery += self.vy
 
-        self.next_move -= 1000.0 / self.fps
-        self.next_slashfx -= 1000.0 / self.fps
+        self.next_move -= 1000.0 / fps
+        self.glitch -= 1000.0 / fps
+        self.next_slashfx -= 1000.0 / fps
 
         self.rotate()
-        if self.vx or self.vy:
+        if self.vx or self.vy or self.hero.firing or self.hero.slashing:
             for enemy in self.enemies: enemy.wake()
             for bullet in self.bullets: bullet.place(self.vx, self.vy)
 
@@ -415,6 +433,7 @@ class Maze:
         self.score = INIT_SCORE
         self.map = deque()
         for _ in range(MAZE_SIZE): self.map.extend(new_column())
+        self.map[MIDDLE][MIDDLE] = HERO
         self.destx = self.desty = MIDDLE
         self.stepx = self.stepy = 0
         self.vx = self.vy = 0.0
diff --git a/setup.py b/setup.py
index 5588f06..fe0128c 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.7.0',
+    version='0.7.1',
     description='A minimalist TPS game with fast-paced action',
     long_description=long_description,
     url='https://github.com/McSinyx/brutalmaze',
diff --git a/wiki b/wiki
-Subproject b4169d8f16a5f99b11f41e4823ca67065788cba
+Subproject 73e7729aea1d4760d5091d8af06469a6111e3b8