summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2017-11-19 12:10:45 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2017-11-19 12:10:45 +0700
commit6a9b702c7737ea73bbb209f920e6e5d7d1d71aea (patch)
tree35715d30fe03acf63718929a1e5940d2e85f779b
parent764fe3421f1113037ca439028ecbe5374610849c (diff)
downloadbrutalmaze-6a9b702c7737ea73bbb209f920e6e5d7d1d71aea.tar.gz
Add Butter the better, Agent Orange and lightning from the Sky 0.1.2
-rw-r--r--brutalmaze/characters.py36
-rw-r--r--brutalmaze/constants.py4
-rw-r--r--brutalmaze/maze.py27
-rwxr-xr-xsetup.py2
4 files changed, 39 insertions, 30 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py
index ac681c5..372600b 100644
--- a/brutalmaze/characters.py
+++ b/brutalmaze/characters.py
@@ -40,6 +40,7 @@ class Hero:
         angle (float): angle of the direction the hero pointing (in radians)
         color (tuple of pygame.Color): colors of the hero on different HPs
         R (int): circumradius of the regular triangle representing the hero
+        next_heal (int): the tick that the hero gains back healing ability
         next_strike (int): the tick that the hero can do the next attack
         slashing (bool): flag indicates if the hero is doing close-range attack
         firing (bool): flag indicates if the hero is doing long-range attack
@@ -55,7 +56,7 @@ class Hero:
         self.angle, self.color = pi / 4, TANGO['Aluminium']
         self.R = (w * h / sin(pi*2/3) / 624) ** 0.5
 
-        self.next_strike = 0
+        self.next_heal = self.next_strike = 0
         self.slashing = self.firing = self.dead = False
         self.spin_speed = fps / HERO_HP
         self.spin_queue = self.wound = 0.0
@@ -65,8 +66,9 @@ class Hero:
         old_speed, time = self.spin_speed, pygame.time.get_ticks()
         self.spin_speed = fps / (HERO_HP-self.wound**0.5)
         self.spin_queue *= self.spin_speed / old_speed
-        if not self.dead: self.wound -= HEAL_SPEED / self.spin_speed / HERO_HP
-        if self.wound < 0: self.wound = 0.0
+        if not self.dead and time > self.next_heal:
+            self.wound -= HEAL_SPEED / self.spin_speed / HERO_HP
+            if self.wound < 0: self.wound = 0.0
 
         if self.slashing and time >= self.next_strike:
             self.next_strike = time + ATTACK_SPEED
@@ -200,12 +202,14 @@ class Enemy:
         return False
 
     def slash(self):
-        """Handle the enemy's close-range attack."""
-        if not self.spin_queue: return
-        x, y = self.pos()
-        d = self.maze.slashd - self.maze.length(x, y)
-        if d >= 0:
-            self.maze.hit(d / self.maze.hero.R / self.spin_speed, self.color)
+        """Return the enemy's close-range damage."""
+        if self.spin_queue:
+            d = self.maze.slashd - self.maze.length(*self.pos())
+            wound = d / self.maze.hero.R / self.spin_speed
+            if wound >= 0:
+                self.maze.hit(wound, self.color)
+                return wound
+        return 0.0
 
     def draw(self):
         """Draw the enemy."""
@@ -236,8 +240,8 @@ class Enemy:
         """Handle the enemy's death."""
         if self.awake:
             self.maze.map[self.x][self.y] = EMPTY
-            if self.maze.enemy_weights[self.color] > INIT_WEIGHT:
-                self.maze.enemy_weights[self.color] -= 1
+            if self.maze.enemy_weights[self.color] > MINW + 1.5:
+                self.maze.enemy_weights[self.color] -= 1.5
         else:
             self.maze.map[self.x][self.y] = WALL
 
@@ -312,14 +316,8 @@ class ScarletRed(Enemy):
 
     def slash(self):
         """Handle the Scarlet Red's close-range attack."""
-        if not self.spin_queue: return
-        x, y = self.pos()
-        d = self.maze.slashd - self.maze.length(x, y)
-        wound = d / self.maze.hero.R / self.spin_speed
-        if wound >= 0:
-            self.maze.hit(wound, self.color)
-            self.wound -= wound
-            if self.wound < 0: self.wound = 0.0
+        self.wound -= Enemy.slash(self)
+        if self.wound < 0: self.wound = 0.0
 
 
 def new_enemy(maze, x, y):
diff --git a/brutalmaze/constants.py b/brutalmaze/constants.py
index 9d6cacf..6cc9103 100644
--- a/brutalmaze/constants.py
+++ b/brutalmaze/constants.py
@@ -45,8 +45,6 @@ BULLET_SPEED = 15   # grid/s
 ATTACK_SPEED = 333  # ms/strike
 FIRANGE = 6     # grids
 BULLET_LIFETIME = 1000.0 * FIRANGE / (BULLET_SPEED-HERO_SPEED)  # ms
-FIRE_DAM = 1# / SQRT2    # HP
-
 EMPTY, WALL, HERO, ENEMY = range(4)
 ADJACENT_GRIDS = (1, 0), (0, 1), (-1, 0), (0, -1)
 CROSS = ADJACENT_GRIDS + ((0, 0),)
@@ -64,7 +62,7 @@ TANGO = {'Butter': ((252, 233, 79), (237, 212, 0), (196, 160, 0)),
                        (136, 138, 133), (85, 87, 83), (46, 52, 54))}
 ENEMIES = ['Butter', 'Orange', 'Chocolate', 'Chameleon',
            'SkyBlue', 'Plum', 'ScarletRed']
-INIT_WEIGHT = 11.25
+MINW, MAXW = 24, 36
 ENEMY_HP = 3
 HERO_HP = 6
 BG_COLOR = TANGO['Aluminium'][-1]
diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py
index cf22438..1bd51b1 100644
--- a/brutalmaze/maze.py
+++ b/brutalmaze/maze.py
@@ -21,7 +21,7 @@ __doc__ = 'brutalmaze module for the maze class'
 
 from collections import deque
 from math import pi, atan2, log
-from random import choice, getrandbits
+from random import choice, getrandbits, uniform
 
 import pygame
 from pygame import RESIZABLE
@@ -72,6 +72,7 @@ class Maze:
         enemy_weights (dict): probabilities of enemies to be created
         enemies (list of Enemy): alive enemies
         hero (Hero): the hero
+        next_move (int): the tick that the hero gets mobilized
         slashd (float): minimum distance for slashes to be effective
     """
     def __init__(self, size, fps):
@@ -91,11 +92,11 @@ class Maze:
         self.vx = self.vy = 0.0
         self.rotatex = self.rotatey = 0
         self.bullets, self.enemies = [], []
-        self.enemy_weights = {color: INIT_WEIGHT for color in ENEMIES}
+        self.enemy_weights = {color: MINW for color in ENEMIES}
         self.add_enemy()
         self.hero = Hero(self.surface, fps)
         self.map[MIDDLE][MIDDLE] = HERO
-        self.slashd = self.hero.R + self.distance/SQRT2
+        self.next_move, self.slashd = 0, self.hero.R + self.distance/SQRT2
 
     def add_enemy(self):
         """Add enough enemies."""
@@ -180,8 +181,19 @@ class Maze:
 
     def hit(self, wound, color):
         """Handle the hero when he loses HP."""
-        self.hero.wound += wound
-        self.enemy_weights[color] += wound
+        fx = (uniform(0, sum(self.enemy_weights.values()))
+              < self.enemy_weights[color])
+        time = pygame.time.get_ticks()
+        if color == 'Butter' and fx:
+            self.hero.wound += 1.0
+        elif color == 'Orange' and fx:
+            self.hero.next_heal = max(self.hero.next_heal, time) + wound*1000
+        elif color == 'SkyBlue' and fx:
+            self.next_move = max(self.next_move, time) + wound*1000
+        else:
+            self.hero.wound += wound
+        if self.enemy_weights[color] + wound < MAXW:
+            self.enemy_weights[color] += wound
 
     def slash(self):
         """Handle close-range attacks."""
@@ -279,9 +291,10 @@ class Maze:
 
     def move(self, x, y, fps):
         """Command the hero to move faster in the given direction."""
+        stunned = pygame.time.get_ticks() < self.next_move
         velocity = self.distance * HERO_SPEED / fps
         accel = velocity * HERO_SPEED / fps
-        if not x:
+        if stunned or not x:
             self.vx -= sign(self.vx) * accel
             if abs(self.vx) < accel * 2: self.vx = 0.0
         elif x * self.vx < 0:
@@ -289,7 +302,7 @@ class Maze:
         else:
             self.vx += x * accel
             if abs(self.vx) > velocity: self.vx = x * velocity
-        if not y:
+        if stunned or not y:
             self.vy -= sign(self.vy) * accel
             if abs(self.vy) < accel * 2: self.vy = 0.0
         elif y * self.vy < 0:
diff --git a/setup.py b/setup.py
index c3084c5..cce9e85 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open('README.rst') as f:
 
 setup(
     name='brutalmaze',
-    version='0.1.1',
+    version='0.1.2',
     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',