about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--brutalmaze/characters.py22
-rw-r--r--brutalmaze/maze.py43
-rw-r--r--brutalmaze/weapons.py6
-rwxr-xr-xsetup.py6
4 files changed, 37 insertions, 40 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py
index 6a830cc..9990cb3 100644
--- a/brutalmaze/characters.py
+++ b/brutalmaze/characters.py
@@ -128,9 +128,9 @@ class Enemy:
         self.spin_speed = self.maze.fps / ENEMY_HP
         self.spin_queue = self.wound = 0.0
 
-    def pos(self):
+    def get_pos(self):
         """Return coordinate of the center of the enemy."""
-        x, y = self.maze.pos(self.x, self.y)
+        x, y = self.maze.get_pos(self.x, self.y)
         step = self.maze.distance * HERO_SPEED / self.maze.fps
         return x + self.offsetx*step, y + self.offsety*step
 
@@ -154,20 +154,20 @@ class Enemy:
         dx = (self.x-MIDDLE)*distance + self.maze.centerx - self.maze.x
         dy = (self.y-MIDDLE)*distance + self.maze.centery - self.maze.y
         mind = cosin(abs(atan(dy / dx)) if dx else 0) * distance
-        def length(x, y): return abs(dy*x - dx*y) / (dy**2 + dx**2)**0.5
+        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
-                x, y = self.maze.pos(i, j)
-                if length(x - self.maze.x, y - self.maze.y) <= mind:
+                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
         return True
 
     def fire(self):
         """Return True if the enemy has just fired, False otherwise."""
-        x, y = self.pos()
-        if (self.maze.length(x, y) > FIRANGE*self.maze.distance
+        x, y = self.get_pos()
+        if (self.maze.get_distance(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 randrange((self.maze.hero.slashing+self.maze.isfast()+1) * 3)):
@@ -204,7 +204,7 @@ class Enemy:
     def slash(self):
         """Return the enemy's close-range damage."""
         if self.spin_queue:
-            d = self.maze.slashd - self.maze.length(*self.pos())
+            d = self.maze.slashd - self.maze.get_distance(*self.get_pos())
             wound = d / self.maze.hero.R / self.spin_speed
             if wound >= 0:
                 self.maze.hit(wound, self.color)
@@ -214,15 +214,15 @@ class Enemy:
     def draw(self):
         """Draw the enemy."""
         radious = self.maze.distance/SQRT2 - self.awake*2
-        square = regpoly(4, radious, self.angle, *self.pos())
+        square = regpoly(4, radious, self.angle, *self.get_pos())
         color = TANGO[self.color][int(self.wound)] if self.awake else FG_COLOR
         fill_aapolygon(self.maze.surface, square, color)
 
     def update(self):
         """Update the enemy."""
         if self.awake:
-            self.spin_speed, old_speed = self.maze.fps / ENEMY_HP, self.spin_speed
-            self.spin_queue *= self.spin_speed / old_speed
+            self.spin_speed, tmp = self.maze.fps / ENEMY_HP, self.spin_speed
+            self.spin_queue *= self.spin_speed / tmp
             if not self.spin_queue and not self.fire() and not self.move():
                 self.spin_queue = randsign() * self.spin_speed
             if abs(self.spin_queue) > 0.5:
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index 13db616..41945ca 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -32,7 +32,7 @@ from .utils import round2, sign, regpoly, fill_aapolygon
 from .weapons import Bullet
 
 
-def cell(bit, upper=True):
+def new_cell(bit, upper=True):
     """Return a half of a cell of the maze based on the given bit."""
     if bit: return deque([WALL]*ROAD_WIDTH + [EMPTY]*ROAD_WIDTH)
     if upper: return deque([WALL] * (ROAD_WIDTH<<1))
@@ -45,8 +45,8 @@ def new_column():
     upper, lower = deque(), deque()
     for _ in range(MAZE_SIZE):
         b = getrandbits(1)
-        upper.extend(cell(b))
-        lower.extend(cell(b, False))
+        upper.extend(new_cell(b))
+        lower.extend(new_cell(b, False))
     for _ in range(ROAD_WIDTH): column.append(upper.__copy__())
     for _ in range(ROAD_WIDTH): column.append(lower.__copy__())
     return column
@@ -100,25 +100,24 @@ class Maze:
 
     def add_enemy(self):
         """Add enough enemies."""
-        walls = []
+        walls, plum = [], None
         for i in self.rangex:
             for j in self.rangey:
                 if self.map[i][j] == WALL: walls.append((i, j))
+        for enemy in self.enemies:
+            if enemy.color == 'Plum' and enemy.awake: plum = enemy
         while walls and len(self.enemies) < log(self.score, INIT_SCORE):
             x, y = choice(walls)
             if all(self.map[x + a][y + b] == WALL for a, b in ADJACENT_GRIDS):
                 continue
             enemy = new_enemy(self, x, y)
             self.enemies.append(enemy)
-            if enemy.color == 'Plum':
-                for e in self.enemies:
-                    if e.color == 'Plum' and e.awake: x, y = e.x, e.y
-            try:
+            if plum is None or enemy.color != 'Plum':
                 walls.remove((x, y))
-            except ValueError:
-                enemy.x, enemy.y = x, y
+            else:
+                enemy.x, enemy.y, enemy.wound = plum.x, plum.y, plum.wound
 
-    def pos(self, 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)
@@ -129,7 +128,7 @@ class Maze:
         for i in self.rangex:
             for j in self.rangey:
                 if self.map[i][j] != WALL: continue
-                x, y = self.pos(i, j)
+                x, y = self.get_pos(i, j)
                 square = regpoly(4, self.distance / SQRT2, pi / 4, x, y)
                 fill_aapolygon(self.surface, square, FG_COLOR)
 
@@ -180,9 +179,9 @@ class Maze:
                     for k in range(ROAD_WIDTH):
                         self.map[c + k][LAST_ROW + j] = grid
 
-    def length(self, x, y):
-        """Return the length of the line segment joining the center of
-        the maze and the point (x, y).
+    def get_distance(self, x, y):
+        """Return the distance from the center of the maze to the point
+        (x, y).
         """
         return ((self.x-x)**2 + (self.y-y)**2)**0.5
 
@@ -208,8 +207,8 @@ class Maze:
         if not self.hero.spin_queue: return
         unit, killist = self.distance/SQRT2 * self.hero.spin_speed, []
         for i, enemy in enumerate(self.enemies):
-            x, y = enemy.pos()
-            d = self.length(x, y)
+            x, y = enemy.get_pos()
+            d = self.get_distance(x, y)
             if d <= self.slashd:
                 enemy.hit((self.slashd-d) / unit)
                 if enemy.wound >= ENEMY_HP:
@@ -239,8 +238,8 @@ class Maze:
                     fallen.append(i)
                     continue
                 for j, enemy in enumerate(self.enemies):
-                    x, y = enemy.pos()
-                    if bullet.length(x, y) < self.distance:
+                    x, y = enemy.get_pos()
+                    if bullet.get_distance(x, y) < self.distance:
                         enemy.hit(wound)
                         if enemy.wound >= ENEMY_HP:
                             self.score += enemy.wound
@@ -248,7 +247,7 @@ class Maze:
                             self.enemies.pop(j)
                         fallen.append(i)
                         break
-            elif bullet.length(self.x, self.y) < self.distance:
+            elif bullet.get_distance(self.x, self.y) < self.distance:
                 if not self.hero.spin_queue: self.hit(wound, bullet.color)
                 fallen.append(i)
         for i in reversed(fallen): self.bullets.pop(i)
@@ -261,12 +260,12 @@ class Maze:
         herox, heroy, dx, dy = self.x - vx, self.y - vy, sign(vx), sign(vy)
         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)
+                x, y = self.get_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)
+            x, y = self.get_pos(enemy.x, enemy.y)
             if (max(abs(herox - x), abs(heroy - y)) * 2 < self.distance
                 and enemy.awake):
                 return 0.0
diff --git a/brutalmaze/weapons.py b/brutalmaze/weapons.py
index 1112c2b..8f1ee72 100644
--- a/brutalmaze/weapons.py
+++ b/brutalmaze/weapons.py
@@ -59,8 +59,6 @@ class Bullet:
         self.x += x
         self.y += y
 
-    def length(self, x, y):
-        """Return the length of the line segment joining the center of
-        the bullet and the point (x, y).
-        """
+    def get_distance(self, x, y):
+        """Return the from the center of the bullet to the point (x, y)."""
         return ((self.x-x)**2 + (self.y-y)**2)**0.5
diff --git a/setup.py b/setup.py
index aa2abbf..67f43eb 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.1.3',
+    version='0.2.0',
     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',
@@ -15,7 +15,7 @@ setup(
     author_email='vn.mcsinyx@gmail.com',
     license='GPLv3+',
     classifiers=[
-        'Development Status :: 2 - Pre-Alpha',
+        'Development Status :: 3 - Alpha',
         'Environment :: MacOS X',
         'Environment :: Win32 (MS Windows)',
         'Environment :: X11 Applications',
@@ -25,7 +25,7 @@ setup(
         'Operating System :: OS Independent',
         'Programming Language :: Python',
         'Topic :: Games/Entertainment :: Arcade'],
-    keywords='pygame action-game',
+    keywords='pygame action-game arcade-game maze',
     packages=['brutalmaze'],
     install_requires=['pygame>=1.9'],
     package_data={'brutalmaze': ['icon.png']},