From 0b4565f5042ad3f11d1a1299f15ac903c814dbcd Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Thu, 18 May 2023 18:31:56 -0700 Subject: [PATCH] Add Mage --- enemies.py | 24 ++++++++++++++++++++++++ globals.py | 3 ++- mapgen.py | 44 ++++++++++++++++++-------------------------- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/enemies.py b/enemies.py index e5d44d9..2b4abea 100644 --- a/enemies.py +++ b/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 \ No newline at end of file diff --git a/globals.py b/globals.py index 0ca5eb0..412293b 100644 --- a/globals.py +++ b/globals.py @@ -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 diff --git a/mapgen.py b/mapgen.py index b109d4d..b345c8d 100644 --- a/mapgen.py +++ b/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