Fix zombie enemies and heart rate

This commit is contained in:
Nguyễn Gia Phong 2019-07-24 12:45:25 +07:00
parent 4f18daa234
commit 622df8c361
5 changed files with 10 additions and 13 deletions

View file

@ -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):

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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',