This commit is contained in:
PAlexanderFranklin 2023-05-18 18:31:56 -07:00
parent 1955395811
commit 0b4565f504
3 changed files with 44 additions and 27 deletions

View File

@ -132,5 +132,29 @@ class Smart(Enemy):
closestPlayer = findClosestPlayer(self.x, self.y) closestPlayer = findClosestPlayer(self.x, self.y)
self.trackedPlayer = closestPlayer self.trackedPlayer = closestPlayer
self.AITime = random.randint(10, 15) 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: except Exception as error:
pass pass

View File

@ -1,6 +1,6 @@
import pygame import pygame
bg_color = pygame.Color('cornsilk4') bg_color = pygame.Color('lightsalmon')
bar_color = pygame.Color('white') bar_color = pygame.Color('white')
red = pygame.Color('brown4') red = pygame.Color('brown4')
blue = pygame.Color('cadetblue3') blue = pygame.Color('cadetblue3')
@ -8,6 +8,7 @@ green = pygame.Color('green3')
grey = pygame.Color("gray26") grey = pygame.Color("gray26")
black = pygame.Color("black") black = pygame.Color("black")
white = pygame.Color("white") white = pygame.Color("white")
purple = pygame.Color("purple")
tile = 34 tile = 34
tileCountx = 50 tileCountx = 50

View File

@ -6,6 +6,20 @@ from player import *
from blocks import * from blocks import *
from enemies 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(): def generateMap():
gameMap.clear() gameMap.clear()
for i in range(tileCountx): for i in range(tileCountx):
@ -21,32 +35,10 @@ def generateMap():
gameMap[spot[0]][spot[1]] = Block(uuid.uuid4(), spot[0], spot[1]) gameMap[spot[0]][spot[1]] = Block(uuid.uuid4(), spot[0], spot[1])
except Exception as error: except Exception as error:
continue continue
for i in range(50): spawnEnemy(Enemy, 20)
for j in range(50): spawnEnemy(Smart, 3)
try: spawnEnemy(Mage, 3)
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
for id, player in players.items(): for id, player in players.items():
maxTries = 5 maxTries = 5