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