Make enemies truely unitasking
This commit is contained in:
parent
96a82a67a0
commit
f177f5aef0
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))]
|
||||
|
|
|
@ -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()
|
||||
|
|
4
setup.py
4
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',
|
||||
|
|
Loading…
Reference in New Issue