about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2017-11-09 15:22:39 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2017-11-09 15:22:39 +0700
commitf177f5aef0fac0fed90279b5c64a591f14d777eb (patch)
treea39c025f9f3654b40509867f65dc21d6c355e3f4
parent96a82a67a0173c6c448897c05ddcb4d139329b0f (diff)
downloadbrutalmaze-f177f5aef0fac0fed90279b5c64a591f14d777eb.tar.gz
Make enemies truely unitasking 0.0.4
-rw-r--r--README.rst4
-rw-r--r--brutalmaze/__init__.py4
-rw-r--r--brutalmaze/characters.py5
-rw-r--r--brutalmaze/maze.py23
-rwxr-xr-xsetup.py4
5 files changed, 25 insertions, 15 deletions
diff --git a/README.rst b/README.rst
index 705f722..8e1f484 100644
--- a/README.rst
+++ b/README.rst
@@ -1,8 +1,8 @@
 Brutal Maze
 ===========
 
-Brutal Maze is a research hash and slash game with fast-paced action and a
-minimalist art style.
+Brutal Maze is a hash and slash game with fast-paced action and a minimalist
+art style.
 
 .. image:: https://raw.githubusercontent.com/McSinyx/brutalmaze/master/screenshot.png
 
diff --git a/brutalmaze/__init__.py b/brutalmaze/__init__.py
index 5111000..75b07c7 100644
--- a/brutalmaze/__init__.py
+++ b/brutalmaze/__init__.py
@@ -1,5 +1,5 @@
-"""Brutal Maze is a research hash and slash game with fast-paced action
-and a minimalist art style.
+"""Brutal Maze is a hash and slash game with fast-paced action and a
+minimalist art style.
 """
 
 from .main import main
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py
index 2e33379..f7c8521 100644
--- a/brutalmaze/characters.py
+++ b/brutalmaze/characters.py
@@ -21,7 +21,7 @@ __doc__ = 'brutalmaze module for hero and enemy classes'
 
 from collections import deque
 from math import atan, atan2, sin, pi
-from random import choice, shuffle, uniform
+from random import choice, randrange, shuffle
 
 import pygame
 
@@ -161,7 +161,7 @@ class Enemy:
         if (self.maze.length(x, y) > FIRANGE*self.maze.distance
             or self.next_strike > pygame.time.get_ticks()
             or (self.x, self.y) in AROUND_HERO or self.offsetx or self.offsety
-            or uniform(-2, 2) < (INIT_SCORE/self.maze.score) ** 2):
+            or randrange((self.maze.hero.slashing+self.maze.isfast()+1) * 3)):
             return False
         self.next_strike = pygame.time.get_ticks() + ATTACK_SPEED
         self.maze.bullets.append(Bullet(
@@ -180,6 +180,7 @@ class Enemy:
         if self.offsety:
             self.offsety -= sign(self.offsety)
             return True
+        if self.next_strike > pygame.time.get_ticks(): return False
 
         self.move_speed = self.maze.fps / ENEMY_SPEED
         directions = [(sign(MIDDLE - self.x), 0), (0, sign(MIDDLE - self.y))]
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index 4012e2c..df83ff0 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -239,12 +239,17 @@ class Maze:
         """
         d = self.distance/2 + self.hero.R
         herox, heroy, dx, dy = self.x - vx, self.y - vy, sign(vx), sign(vy)
-        for x in range(MIDDLE - dx - 1, MIDDLE - dx + 2):
-            for y in range(MIDDLE - dy - 1, MIDDLE - dy + 2):
-                gridx, gridy = self.pos(x, y)
-                if (max(abs(herox - gridx), abs(heroy - gridy)) < d
-                    and self.map[x][y] == WALL):
+        for gridx in range(MIDDLE - dx - 1, MIDDLE - dx + 2):
+            for gridy in range(MIDDLE - dy - 1, MIDDLE - dy + 2):
+                x, y = self.pos(gridx, gridy)
+                if (max(abs(herox - x), abs(heroy - y)) < d
+                    and self.map[gridx][gridy] == WALL):
                     return 0.0
+        for enemy in self.enemies:
+            x, y = self.pos(enemy.x, enemy.y)
+            if (max(abs(herox - x), abs(heroy - y)) * 2 < self.distance
+                and enemy.awake):
+                return 0.0
         return vx or vy
 
     def update(self, fps):
@@ -277,7 +282,7 @@ class Maze:
         accel = velocity * HERO_SPEED / fps
         if not x:
             self.vx -= sign(self.vx) * accel
-            if abs(self.vx) < accel: self.vx = 0.0
+            if abs(self.vx) < accel * 2: self.vx = 0.0
         elif x * self.vx < 0:
             self.vx += x * 2 * accel
         else:
@@ -285,7 +290,7 @@ class Maze:
             if abs(self.vx) > velocity: self.vx = x * velocity
         if not y:
             self.vy -= sign(self.vy) * accel
-            if abs(self.vy) < accel: self.vy = 0.0
+            if abs(self.vy) < accel * 2: self.vy = 0.0
         elif y * self.vy < 0:
             self.vy += y * 2 * accel
         else:
@@ -309,6 +314,10 @@ class Maze:
         self.rangey = range(MIDDLE - h, MIDDLE + h + 1)
         self.slashd = self.hero.R + self.distance/SQRT2
 
+    def isfast(self):
+        """Return if the hero is moving faster than HERO_SPEED."""
+        return (self.vx**2+self.vy**2)**0.5*self.fps > HERO_SPEED*self.distance
+
     def lose(self):
         """Handle loses."""
         self.hero.die()
diff --git a/setup.py b/setup.py
index 20b9129..a72ea9c 100755
--- a/setup.py
+++ b/setup.py
@@ -7,8 +7,8 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.0.3',
-    description='A research hash and slash game with fast-paced action and a minimalist art style',
+    version='0.0.4',
+    description='A hash and slash game with fast-paced action and a minimalist art style',
     long_description=long_description,
     url='https://github.com/McSinyx/brutalmaze',
     author='Nguyễn Gia Phong',