Add animation, gore, pathing
This commit is contained in:
parent
c5f484b327
commit
5786ac0d32
@ -32,7 +32,7 @@ def main():
|
||||
(pygame.K_e, "ne"),
|
||||
(pygame.K_d, "e"),
|
||||
(pygame.K_c, "se"),
|
||||
(pygame.K_s, "s"),
|
||||
(pygame.K_x, "s"),
|
||||
(pygame.K_z, "sw"),
|
||||
(pygame.K_a, "w"),
|
||||
(pygame.K_q, "nw"),
|
||||
@ -53,7 +53,7 @@ def main():
|
||||
(pygame.K_KP_1, "sw"),
|
||||
(pygame.K_KP_4, "w"),
|
||||
(pygame.K_KP_7, "nw"),
|
||||
(pygame.K_KP_5, "p"),
|
||||
(pygame.K_KP_0, "p"),
|
||||
],
|
||||
))
|
||||
# players["3"] = (Player(
|
||||
@ -112,11 +112,13 @@ def main():
|
||||
if not spot:
|
||||
continue
|
||||
elif isinstance(spot, Block):
|
||||
pygame.draw.rect(screen, blue, spot.sprite)
|
||||
pygame.draw.rect(screen, spot.color, spot.sprite)
|
||||
elif isinstance(spot, Enemy):
|
||||
screen.blit(frame_4, ((tile*spot.x)+2, (tile*spot.y)+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):
|
||||
screen.blit(frame_0, ((tile*spot.x)+2, (tile*spot.y)+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)
|
||||
screen.blit(scoreSurface, (500*int(spot.id) - 400, screen_height - bottomBarHeight + 20))
|
||||
|
||||
|
@ -7,9 +7,10 @@ from enemies import *
|
||||
class Block:
|
||||
def __init__(self, id, x, y):
|
||||
self.id = id
|
||||
self.BLOCK = True
|
||||
self.color = blue
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.BLOCK = True
|
||||
|
||||
self.sprite = pygame.Rect((x*tile) + 2, (y*tile) + 2, tile - 2, tile - 2)
|
||||
|
||||
|
@ -19,10 +19,11 @@ def findClosestPlayer(x, y):
|
||||
class Enemy:
|
||||
def __init__(self, id, x, y):
|
||||
self.id = id
|
||||
self.ENEMY = True
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.renderPos = (x,y)
|
||||
self.AITime = random.randint(350, 600)
|
||||
self.ENEMY = True
|
||||
|
||||
|
||||
def die(self):
|
||||
@ -33,6 +34,7 @@ class Enemy:
|
||||
wallCrush = self.x + x > tileCountx - 1 or self.y + y > tileCounty - 1 or self.x + x < 0 or self.y + y < 0
|
||||
if wallCrush or hasattr(gameMap[self.x + x][self.y + y], "BLOCK"):
|
||||
pusher.kills += 1
|
||||
caller.color = random.choice([grey, green])
|
||||
self.die()
|
||||
return
|
||||
raise Exception("Not crushing enemy!")
|
||||
|
@ -5,6 +5,7 @@ bar_color = pygame.Color('white')
|
||||
red = pygame.Color('brown4')
|
||||
blue = pygame.Color('cadetblue3')
|
||||
green = pygame.Color('green3')
|
||||
grey = pygame.Color("gray26")
|
||||
black = pygame.Color("black")
|
||||
|
||||
tile = 34
|
||||
|
@ -47,6 +47,7 @@ def generateMap():
|
||||
gameMap[spot[0]][spot[1]] = player
|
||||
player.x = spot[0]
|
||||
player.y = spot[1]
|
||||
player.pathMap = player.buildOwnPathMap()
|
||||
break
|
||||
except Exception as error:
|
||||
continue
|
52
player.py
52
player.py
@ -1,13 +1,41 @@
|
||||
import pygame
|
||||
import uuid
|
||||
|
||||
from globals import *
|
||||
from blocks import *
|
||||
|
||||
def buildPathMap(x, y):
|
||||
pathMap = []
|
||||
for i in range(tileCountx):
|
||||
column = []
|
||||
for j in range(tileCounty):
|
||||
column.append(False)
|
||||
pathMap.append(column)
|
||||
pathMap[x][y] = (x,y,(0,0))
|
||||
currentTiles = [pathMap[x][y]]
|
||||
newTiles = set()
|
||||
while len(currentTiles) > 0:
|
||||
for tile in currentTiles:
|
||||
for i in range(-1,2):
|
||||
for j in range(-1,2):
|
||||
newX = tile[0] + i
|
||||
newY = tile[1] + j
|
||||
outOfBounds = newX > tileCountx - 1 or newY > tileCounty - 1 or newX < 0 or newY < 0
|
||||
if (i != 0 or j != 0) and not outOfBounds and not pathMap[newX][newY]:
|
||||
pathMap[newX][newY] = (newX,newY,(-i,-j))
|
||||
if not gameMap[newX][newY]:
|
||||
newTiles.add(pathMap[newX][newY])
|
||||
currentTiles = list(newTiles)
|
||||
newTiles = set()
|
||||
return pathMap
|
||||
|
||||
class Player:
|
||||
def __init__(self, id, x, y, sprite, keys):
|
||||
self.id = id
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.renderPos = (x,y)
|
||||
self.pathMap = []
|
||||
self.sprite = sprite
|
||||
self.pull = False
|
||||
self.PLAYER = True
|
||||
@ -30,6 +58,9 @@ class Player:
|
||||
self.pullKey = key[0]
|
||||
else:
|
||||
self.commands.append([key[0], commands[key[1]], 0, 0])
|
||||
|
||||
def buildOwnPathMap(self):
|
||||
self.pathMap = buildPathMap(self.x, self.y)
|
||||
|
||||
def useKeys(self, keys):
|
||||
try:
|
||||
@ -38,13 +69,17 @@ class Player:
|
||||
else:
|
||||
self.pull = False
|
||||
for command in self.commands:
|
||||
if keys[command[0]]:
|
||||
if command[2] == 0 or (command[2] > 10 and command[3] > 2):
|
||||
command[1]()
|
||||
try:
|
||||
if keys[command[0]]:
|
||||
if command[2] == 0 or (command[2] > 10 and command[3] > 2):
|
||||
command[1]()
|
||||
command[3] = 0
|
||||
command[2] += 1
|
||||
command[3] += 1
|
||||
else:
|
||||
command[2] = 0
|
||||
command[3] = 0
|
||||
command[2] += 1
|
||||
command[3] += 1
|
||||
else:
|
||||
except:
|
||||
command[2] = 0
|
||||
command[3] = 0
|
||||
except:
|
||||
@ -63,6 +98,11 @@ class Player:
|
||||
self.x += x
|
||||
self.y += y
|
||||
gameMap[self.x][self.y] = self
|
||||
for id, player in players.items():
|
||||
try:
|
||||
player.buildOwnPathMap()
|
||||
except Exception as error:
|
||||
print(error)
|
||||
try:
|
||||
if pulling:
|
||||
gameMap[self.x - 2*x][self.y - 2*y].pulled(x, y)
|
||||
|
Loading…
x
Reference in New Issue
Block a user