Add Mage
This commit is contained in:
parent
1955395811
commit
0b4565f504
24
enemies.py
24
enemies.py
@ -132,5 +132,29 @@ class Smart(Enemy):
|
||||
closestPlayer = findClosestPlayer(self.x, self.y)
|
||||
self.trackedPlayer = closestPlayer
|
||||
self.AITime = random.randint(10, 15)
|
||||
except Exception as error:
|
||||
pass
|
||||
|
||||
class Mage(Enemy):
|
||||
def __init__(self, id, x, y):
|
||||
Enemy.__init__(self, id, x, y)
|
||||
self.deathColor = purple
|
||||
self.sprite = pygame.Surface((32,32), pygame.SRCALPHA)
|
||||
pygame.draw.circle(self.sprite, purple, (16,16), 6)
|
||||
|
||||
def runAI(self):
|
||||
self.AITime -= 1
|
||||
if self.AITime < 1:
|
||||
try:
|
||||
diff = findClosestPlayer(self.x, self.y)["difference"]
|
||||
weightsx = [1,1,1]
|
||||
weightsy = [1,1,1]
|
||||
randomWeights = randomizeMovement(weightsx, weightsy, diff, 0.15)
|
||||
weightsx = randomWeights[0]
|
||||
weightsy = randomWeights[1]
|
||||
movementx = random.choices([-1, 0, 1], weightsx)[0] * random.randint(1,4)
|
||||
movementy = random.choices([-1, 0, 1], weightsy)[0] * random.randint(1,4)
|
||||
self.move(movementx, movementy)
|
||||
self.AITime = random.randint(150, 200)
|
||||
except Exception as error:
|
||||
pass
|
@ -1,6 +1,6 @@
|
||||
import pygame
|
||||
|
||||
bg_color = pygame.Color('cornsilk4')
|
||||
bg_color = pygame.Color('lightsalmon')
|
||||
bar_color = pygame.Color('white')
|
||||
red = pygame.Color('brown4')
|
||||
blue = pygame.Color('cadetblue3')
|
||||
@ -8,6 +8,7 @@ green = pygame.Color('green3')
|
||||
grey = pygame.Color("gray26")
|
||||
black = pygame.Color("black")
|
||||
white = pygame.Color("white")
|
||||
purple = pygame.Color("purple")
|
||||
|
||||
tile = 34
|
||||
tileCountx = 50
|
||||
|
44
mapgen.py
44
mapgen.py
@ -6,6 +6,20 @@ from player import *
|
||||
from blocks import *
|
||||
from enemies import *
|
||||
|
||||
def spawnEnemy(type, amount):
|
||||
for i in range(amount):
|
||||
for j in range(50):
|
||||
try:
|
||||
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
|
||||
if gameMap[spot[0]][spot[1]]:
|
||||
raise Exception("spot taken!")
|
||||
newEnemy = type(uuid.uuid4(), spot[0], spot[1])
|
||||
gameMap[spot[0]][spot[1]] = newEnemy
|
||||
enemies[newEnemy.id] = newEnemy
|
||||
break
|
||||
except Exception as error:
|
||||
continue
|
||||
|
||||
def generateMap():
|
||||
gameMap.clear()
|
||||
for i in range(tileCountx):
|
||||
@ -21,32 +35,10 @@ def generateMap():
|
||||
gameMap[spot[0]][spot[1]] = Block(uuid.uuid4(), spot[0], spot[1])
|
||||
except Exception as error:
|
||||
continue
|
||||
|
||||
for i in range(50):
|
||||
for j in range(50):
|
||||
try:
|
||||
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
|
||||
if gameMap[spot[0]][spot[1]]:
|
||||
raise Exception("spot taken!")
|
||||
newEnemy = Enemy(uuid.uuid4(), spot[0], spot[1])
|
||||
gameMap[spot[0]][spot[1]] = newEnemy
|
||||
enemies[newEnemy.id] = newEnemy
|
||||
break
|
||||
except Exception as error:
|
||||
continue
|
||||
|
||||
for i in range(3):
|
||||
for j in range(50):
|
||||
try:
|
||||
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
|
||||
if gameMap[spot[0]][spot[1]]:
|
||||
raise Exception("spot taken!")
|
||||
newEnemy = Smart(uuid.uuid4(), spot[0], spot[1])
|
||||
gameMap[spot[0]][spot[1]] = newEnemy
|
||||
enemies[newEnemy.id] = newEnemy
|
||||
break
|
||||
except Exception as error:
|
||||
continue
|
||||
|
||||
spawnEnemy(Enemy, 20)
|
||||
spawnEnemy(Smart, 3)
|
||||
spawnEnemy(Mage, 3)
|
||||
|
||||
for id, player in players.items():
|
||||
maxTries = 5
|
||||
|
Loading…
Reference in New Issue
Block a user