Add new enemy type that doesn't work
This commit is contained in:
parent
5973675c51
commit
0add18a31d
@ -86,6 +86,7 @@ def main():
|
|||||||
|
|
||||||
return image
|
return image
|
||||||
frame_0 = get_image(sprite_sheet_image, 0, 0, 32, 32, (tile-2)/32, black)
|
frame_0 = get_image(sprite_sheet_image, 0, 0, 32, 32, (tile-2)/32, black)
|
||||||
|
frame_1 = get_image(sprite_sheet_image, 0, 32, 32, 32, (tile-2)/32, black)
|
||||||
frame_4 = get_image(sprite_sheet_image, 32, 0, 32, 32, (tile-2)/32, black)
|
frame_4 = get_image(sprite_sheet_image, 32, 0, 32, 32, (tile-2)/32, black)
|
||||||
|
|
||||||
game_font = pygame.font.Font("freesansbold.ttf",32)
|
game_font = pygame.font.Font("freesansbold.ttf",32)
|
||||||
@ -113,15 +114,18 @@ def main():
|
|||||||
continue
|
continue
|
||||||
elif isinstance(spot, Block):
|
elif isinstance(spot, Block):
|
||||||
pygame.draw.rect(screen, spot.color, spot.sprite)
|
pygame.draw.rect(screen, spot.color, spot.sprite)
|
||||||
|
elif isinstance(spot, Smart):
|
||||||
|
screen.blit(frame_1, ((tile*spot.renderPos[0])+2, (tile*spot.renderPos[1])+2))
|
||||||
elif isinstance(spot, Enemy):
|
elif isinstance(spot, Enemy):
|
||||||
screen.blit(frame_4, ((tile*spot.renderPos[0])+2, (tile*spot.renderPos[1])+2))
|
screen.blit(frame_4, ((tile*spot.renderPos[0])+2, (tile*spot.renderPos[1])+2))
|
||||||
spot.renderPos = ((spot.x - spot.renderPos[0])/3 + spot.renderPos[0], (spot.y - spot.renderPos[1])/3 + spot.renderPos[1])
|
|
||||||
elif isinstance(spot, Player):
|
elif isinstance(spot, Player):
|
||||||
screen.blit(frame_0, ((tile*spot.renderPos[0])+2, (tile*spot.renderPos[1])+2))
|
screen.blit(frame_0, ((tile*spot.renderPos[0])+2, (tile*spot.renderPos[1])+2))
|
||||||
spot.renderPos = ((spot.x - spot.renderPos[0])/3 + spot.renderPos[0], (spot.y - spot.renderPos[1])/3 + spot.renderPos[1])
|
|
||||||
scoreSurface = game_font.render(f'player {spot.id} kills: {spot.kills} lives: {spot.lives}', False, black)
|
scoreSurface = game_font.render(f'player {spot.id} kills: {spot.kills} lives: {spot.lives}', False, black)
|
||||||
screen.blit(scoreSurface, (500*int(spot.id) - 400, screen_height - bottomBarHeight + 20))
|
screen.blit(scoreSurface, (500*int(spot.id) - 400, screen_height - bottomBarHeight + 20))
|
||||||
|
try:
|
||||||
|
spot.renderPos = ((spot.x - spot.renderPos[0])/3 + spot.renderPos[0], (spot.y - spot.renderPos[1])/3 + spot.renderPos[1])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
|
||||||
|
40
enemies.py
40
enemies.py
@ -24,9 +24,10 @@ class Enemy:
|
|||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.renderPos = (x,y)
|
self.renderPos = (x,y)
|
||||||
self.AITime = random.randint(350, 600)
|
# self.AITime = random.randint(350, 600)
|
||||||
|
self.AITime = random.randint(10, 50)
|
||||||
|
self.deathColor = white
|
||||||
|
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
del enemies[self.id]
|
del enemies[self.id]
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ class Enemy:
|
|||||||
if hasattr(pusher, "PLAYER") and hasattr(caller, "BLOCK"):
|
if hasattr(pusher, "PLAYER") and hasattr(caller, "BLOCK"):
|
||||||
if checkOOBounds((self.x + x, self.y + y)) or hasattr(gameMap[self.x + x][self.y + y], "BLOCK"):
|
if checkOOBounds((self.x + x, self.y + y)) or hasattr(gameMap[self.x + x][self.y + y], "BLOCK"):
|
||||||
pusher.kills += 1
|
pusher.kills += 1
|
||||||
caller.color = white
|
caller.color = self.deathColor
|
||||||
self.die()
|
self.die()
|
||||||
return
|
return
|
||||||
raise Exception("Not crushing enemy!")
|
raise Exception("Not crushing enemy!")
|
||||||
@ -81,4 +82,35 @@ class Enemy:
|
|||||||
self.move(movementx, movementy)
|
self.move(movementx, movementy)
|
||||||
self.AITime = random.randint(150, 200)
|
self.AITime = random.randint(150, 200)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class Smart(Enemy):
|
||||||
|
def __init__(self, id, x, y):
|
||||||
|
Enemy.__init__(self, id, x, y)
|
||||||
|
self.deathColor = red
|
||||||
|
self.trackedPlayer = False
|
||||||
|
self.trackingCounter = 0
|
||||||
|
|
||||||
|
def runAI(self):
|
||||||
|
self.AITime -= 1
|
||||||
|
if self.AITime < 1:
|
||||||
|
try:
|
||||||
|
if self.trackedPlayer and self.trackedPlayer.alive:
|
||||||
|
fastDir = self.trackedPlayer.pathMap[self.x][self.y][2]
|
||||||
|
# movementx = random.choices([-1, 0, 1], weightsx)[0]
|
||||||
|
# movementy = random.choices([-1, 0, 1], weightsy)[0]
|
||||||
|
movementx = fastDir[0]
|
||||||
|
movementy = fastDir[1]
|
||||||
|
# self.move(movementx, movementy)
|
||||||
|
self.trackingCounter -= 1
|
||||||
|
if self.trackingCounter < 1:
|
||||||
|
self.AITime = random.randint(500, 1000)
|
||||||
|
self.trackedPlayer = False
|
||||||
|
self.AITime = random.randint(10, 15)
|
||||||
|
else:
|
||||||
|
closestPlayer = findClosestPlayer(self.x, self.y)
|
||||||
|
self.trackedPlayer = closestPlayer["player"]
|
||||||
|
self.trackingCounter = 8
|
||||||
|
self.AITime = random.randint(10, 15)
|
||||||
|
except Exception as error:
|
||||||
|
print(error)
|
13
mapgen.py
13
mapgen.py
@ -35,6 +35,19 @@ def generateMap():
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
for i in range(1):
|
||||||
|
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
|
||||||
for i in range(maxTries + 1):
|
for i in range(maxTries + 1):
|
||||||
|
10
player.py
10
player.py
@ -14,7 +14,7 @@ def buildPathMap(x, y):
|
|||||||
pathMap[x][y] = (x,y,(0,0))
|
pathMap[x][y] = (x,y,(0,0))
|
||||||
currentTiles = [pathMap[x][y]]
|
currentTiles = [pathMap[x][y]]
|
||||||
newTiles = set()
|
newTiles = set()
|
||||||
while len(currentTiles) > 0:
|
while True:
|
||||||
for tile in currentTiles:
|
for tile in currentTiles:
|
||||||
for i in range(-1,2):
|
for i in range(-1,2):
|
||||||
for j in range(-1,2):
|
for j in range(-1,2):
|
||||||
@ -24,6 +24,8 @@ def buildPathMap(x, y):
|
|||||||
pathMap[newX][newY] = (newX,newY,(-i,-j))
|
pathMap[newX][newY] = (newX,newY,(-i,-j))
|
||||||
if not gameMap[newX][newY]:
|
if not gameMap[newX][newY]:
|
||||||
newTiles.add(pathMap[newX][newY])
|
newTiles.add(pathMap[newX][newY])
|
||||||
|
if len(currentTiles) < 1:
|
||||||
|
break
|
||||||
currentTiles = list(newTiles)
|
currentTiles = list(newTiles)
|
||||||
newTiles = set()
|
newTiles = set()
|
||||||
return pathMap
|
return pathMap
|
||||||
@ -40,6 +42,7 @@ class Player:
|
|||||||
self.PLAYER = True
|
self.PLAYER = True
|
||||||
self.kills = 0
|
self.kills = 0
|
||||||
self.lives = 3
|
self.lives = 3
|
||||||
|
self.alive = True
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
"n": lambda: self.move(0,-1),
|
"n": lambda: self.move(0,-1),
|
||||||
@ -118,6 +121,7 @@ class Player:
|
|||||||
for i in range(maxTries + 1):
|
for i in range(maxTries + 1):
|
||||||
if self.lives < 1:
|
if self.lives < 1:
|
||||||
del players[self.id]
|
del players[self.id]
|
||||||
|
self.alive = False
|
||||||
break
|
break
|
||||||
if i == maxTries:
|
if i == maxTries:
|
||||||
raise Exception("No spots found for player!")
|
raise Exception("No spots found for player!")
|
||||||
@ -129,6 +133,10 @@ class Player:
|
|||||||
self.x = spot[0]
|
self.x = spot[0]
|
||||||
self.y = spot[1]
|
self.y = spot[1]
|
||||||
self.lives -= 1
|
self.lives -= 1
|
||||||
|
try:
|
||||||
|
self.buildOwnPathMap()
|
||||||
|
except Exception as error:
|
||||||
|
print(error)
|
||||||
break
|
break
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
continue
|
continue
|
Loading…
Reference in New Issue
Block a user