Add lives
This commit is contained in:
parent
238a4a26eb
commit
c5f484b327
@ -32,11 +32,11 @@ def main():
|
||||
(pygame.K_e, "ne"),
|
||||
(pygame.K_d, "e"),
|
||||
(pygame.K_c, "se"),
|
||||
(pygame.K_x, "s"),
|
||||
(pygame.K_s, "s"),
|
||||
(pygame.K_z, "sw"),
|
||||
(pygame.K_a, "w"),
|
||||
(pygame.K_q, "nw"),
|
||||
(pygame.K_s, "p"),
|
||||
(pygame.K_LSHIFT, "p"),
|
||||
],
|
||||
))
|
||||
players["2"] = (Player(
|
||||
@ -117,8 +117,8 @@ def main():
|
||||
screen.blit(frame_4, ((tile*spot.x)+2, (tile*spot.y)+2))
|
||||
elif isinstance(spot, Player):
|
||||
screen.blit(frame_0, ((tile*spot.x)+2, (tile*spot.y)+2))
|
||||
scoreSurface = game_font.render(f'{spot.id}: {spot.kills}', False, black)
|
||||
screen.blit(scoreSurface, (300*int(spot.id), screen_height - bottomBarHeight + 20))
|
||||
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))
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick(60)
|
||||
|
@ -21,7 +21,7 @@ class Enemy:
|
||||
self.id = id
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.AITime = random.randint(150, 200)
|
||||
self.AITime = random.randint(350, 600)
|
||||
self.ENEMY = True
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ def generateMap():
|
||||
except Exception as error:
|
||||
continue
|
||||
|
||||
for i in range(25):
|
||||
for i in range(60):
|
||||
for j in range(50):
|
||||
try:
|
||||
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
|
||||
|
20
player.py
20
player.py
@ -12,6 +12,7 @@ class Player:
|
||||
self.pull = False
|
||||
self.PLAYER = True
|
||||
self.kills = 0
|
||||
self.lives = 3
|
||||
|
||||
commands = {
|
||||
"n": lambda: self.move(0,-1),
|
||||
@ -74,4 +75,21 @@ class Player:
|
||||
raise Exception("Cannot push other players.")
|
||||
|
||||
def die(self):
|
||||
del players[self.id]
|
||||
maxTries = 5
|
||||
for i in range(maxTries + 1):
|
||||
if self.lives < 1:
|
||||
del players[self.id]
|
||||
break
|
||||
if i == maxTries:
|
||||
raise Exception("No spots found for player!")
|
||||
try:
|
||||
spot = [random.randint(0, tileCountx - 1), random.randint(0, tileCounty - 1)]
|
||||
if gameMap[spot[0]][spot[1]]:
|
||||
raise Exception("spot taken!")
|
||||
gameMap[spot[0]][spot[1]] = self
|
||||
self.x = spot[0]
|
||||
self.y = spot[1]
|
||||
self.lives -= 1
|
||||
break
|
||||
except Exception as error:
|
||||
continue
|
Loading…
Reference in New Issue
Block a user