diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-01-24 21:01:51 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-01-24 21:01:51 +0700 |
commit | 59501c6c44f26b66d4bb314b9f2eb21d7984eeb7 (patch) | |
tree | 6f784665faa4197e6c027b02a57af77f4dab4848 | |
parent | b25b3c3e6bafebcbb531dec367232148764fb334 (diff) | |
download | brutalmaze-59501c6c44f26b66d4bb314b9f2eb21d7984eeb7.tar.gz |
Give hero special vision when struck by lightning 0.3.3
-rw-r--r-- | brutalmaze/characters.py | 22 | ||||
-rw-r--r-- | brutalmaze/maze.py | 3 | ||||
-rwxr-xr-x | setup.py | 2 |
3 files changed, 15 insertions, 12 deletions
diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py index c9dd28b..6cb78df 100644 --- a/brutalmaze/characters.py +++ b/brutalmaze/characters.py @@ -25,6 +25,8 @@ from random import choice, randrange, shuffle from sys import modules import pygame +from pygame.mixer import Sound +from pygame.time import get_ticks from .constants import * from .misc import sign, cosin, randsign, regpoly, fill_aapolygon, choices, play @@ -63,14 +65,14 @@ class Hero: self.spin_speed = fps / HERO_HP self.spin_queue = self.wound = 0.0 - self.sfx_heart = pygame.mixer.Sound(SFX_HEART) + self.sfx_heart = Sound(SFX_HEART) def update(self, fps): """Update the hero.""" if self.dead: self.spin_queue = 0.0 return - old_speed, time = self.spin_speed, pygame.time.get_ticks() + old_speed, time = self.spin_speed, get_ticks() self.spin_speed = fps / (HERO_HP-self.wound**0.5) self.spin_queue *= self.spin_speed / old_speed if time > self.next_heal: @@ -131,7 +133,7 @@ class Enemy: self.spin_speed = self.maze.fps / ENEMY_HP self.spin_queue = self.wound = 0.0 - self.sfx_slash = pygame.mixer.Sound(SFX_SLASH_HERO) + self.sfx_slash = Sound(SFX_SLASH_HERO) def get_pos(self): """Return coordinate of the center of the enemy.""" @@ -174,11 +176,11 @@ class Enemy: if self.maze.hero.dead: return False 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 get_ticks() < self.next_strike 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)): return False - self.next_strike = pygame.time.get_ticks() + ATTACK_SPEED + self.next_strike = get_ticks() + ATTACK_SPEED self.maze.bullets.append(Bullet( self.maze.surface, x, y, atan2(self.maze.y - y, self.maze.x - x), self.color)) @@ -192,7 +194,7 @@ class Enemy: if self.offsety: self.offsety -= sign(self.offsety) return True - if self.next_strike > pygame.time.get_ticks(): return False + if get_ticks() < self.next_strike: return False self.move_speed = self.maze.fps / speed directions = [(sign(MIDDLE - self.x), 0), (0, sign(MIDDLE - self.y))] @@ -241,7 +243,7 @@ class Enemy: self.spin_queue -= sign(self.spin_queue) else: self.angle, self.spin_queue = pi / 4, 0.0 - self.draw() + if self.awake or get_ticks() >= self.maze.next_move: self.draw() def hit(self, wound): """Handle the enemy when it's attacked.""" @@ -270,17 +272,17 @@ class Chameleon(Enemy): def wake(self): """Wake the Chameleon up if it can see the hero.""" if Enemy.wake(self) is True: - self.visible = pygame.time.get_ticks() + 1000//ENEMY_SPEED + self.visible = get_ticks() + 1000//ENEMY_SPEED def draw(self): """Draw the Chameleon.""" if (not self.awake or self.spin_queue - or pygame.time.get_ticks() <= self.visible): + or get_ticks() < max(self.visible, self.maze.next_move)): Enemy.draw(self) def hit(self, wound): """Handle the Chameleon when it's attacked.""" - self.visible = pygame.time.get_ticks() + 1000//ENEMY_SPEED + self.visible = get_ticks() + 1000//ENEMY_SPEED Enemy.hit(self, wound) diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py index 0ca75ae..3b0ee6d 100644 --- a/brutalmaze/maze.py +++ b/brutalmaze/maze.py @@ -136,6 +136,7 @@ class Maze: def draw(self): """Draw the maze.""" self.surface.fill(BG_COLOR) + if get_ticks() < self.next_move: return for i in self.rangex: for j in self.rangey: if self.map[i][j] != WALL: continue @@ -249,7 +250,7 @@ class Maze: elif bullet.color == 'Aluminium': x = MIDDLE + round2((bullet.x-self.x) / self.distance) y = MIDDLE + round2((bullet.y-self.y) / self.distance) - if self.map[x][y] == WALL: + if self.map[x][y] == WALL and time >= self.next_move: fallen.append(i) continue for j, enemy in enumerate(self.enemies): diff --git a/setup.py b/setup.py index 4bf6935..8a2e802 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.rst') as f: setup( name='brutalmaze', - version='0.3.2', + version='0.3.3', 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', |