From f177f5aef0fac0fed90279b5c64a591f14d777eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Thu, 9 Nov 2017 15:22:39 +0700 Subject: [PATCH] Make enemies truely unitasking --- README.rst | 4 ++-- brutalmaze/__init__.py | 4 ++-- brutalmaze/characters.py | 5 +++-- brutalmaze/maze.py | 23 ++++++++++++++++------- setup.py | 4 ++-- 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',