更新 2p
parent
676c64789d
commit
fff106ad2d
59
2p
59
2p
|
@ -158,8 +158,8 @@ def draw_maze(maze):
|
|||
def draw_menu():
|
||||
font = pygame.font.Font(None, 36)
|
||||
title_text = font.render("Labirints", True, RED)
|
||||
start_text = font.render("Press 1 to Control Player", True, BLACK)
|
||||
start_text2 = font.render("Press 2 to Control Villain", True, BLACK)
|
||||
start_text = font.render("Press 1 to Control Player 1", True, BLACK)
|
||||
start_text2 = font.render("Press 2 to Control Player 2", True, BLACK)
|
||||
quit_text = font.render("Press Q to Quit", True, BLACK)
|
||||
|
||||
screen.blit(title_text, (width // 2 - title_text.get_width() // 2, height // 2 - 100))
|
||||
|
@ -169,15 +169,16 @@ def draw_menu():
|
|||
|
||||
pygame.display.flip()
|
||||
|
||||
player = Player(32, 32)
|
||||
player1 = Player(32, 32)
|
||||
player2 = Player(736, 736)
|
||||
cheese = Cheese(416, 416) # Cheese position
|
||||
villain = Villain(704, 704, player) # Villain's starting position
|
||||
villain2 = Villain(32, 32, player) # Second villain's starting position
|
||||
villain = Villain(704, 704, player1) # Villain's starting position
|
||||
villain2 = Villain(32, 32, player2) # Second villain's starting position
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
running = True
|
||||
show_menu = True
|
||||
control_player = True # 初始设置玩家控制主角
|
||||
control_player = True # 初始设置玩家1控制主角
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
@ -201,14 +202,14 @@ while running:
|
|||
dx, dy = 0, 0
|
||||
|
||||
if keys[pygame.K_LEFT]:
|
||||
dx = -player.speed
|
||||
dx = -player1.speed
|
||||
elif keys[pygame.K_RIGHT]:
|
||||
dx = player.speed
|
||||
dx = player1.speed
|
||||
|
||||
if keys[pygame.K_UP]:
|
||||
dy = -player.speed
|
||||
dy = -player1.speed
|
||||
elif keys[pygame.K_DOWN]:
|
||||
dy = player.speed
|
||||
dy = player1.speed
|
||||
|
||||
if dx != 0 and dy != 0:
|
||||
if keys[pygame.K_LEFT]:
|
||||
|
@ -221,26 +222,27 @@ while running:
|
|||
dx = 0
|
||||
|
||||
walls, roads = draw_maze(maze)
|
||||
player.move(dx, dy, walls)
|
||||
player.update_image(dx, dy)
|
||||
player1.move(dx, dy, walls)
|
||||
player1.update_image(dx, dy)
|
||||
|
||||
villain.move_towards_player(walls)
|
||||
|
||||
if player.rect.colliderect(villain.rect):
|
||||
print("Game Over! You were caught by the villain.")
|
||||
if player1.rect.colliderect(villain.rect):
|
||||
print("Game Over! Player 1 was caught by the villain.")
|
||||
running = False
|
||||
|
||||
if player.rect.colliderect(cheese.rect):
|
||||
player.cheese_count += 1
|
||||
print("You collected a cheese! Total cheese count:", player.cheese_count)
|
||||
if player1.rect.colliderect(cheese.rect):
|
||||
player1.cheese_count += 1
|
||||
print("Player 1 collected a cheese! Total cheese count:", player1.cheese_count)
|
||||
cheese.rect.topleft = random.choice(roads).topleft # Move cheese to a random position on a road
|
||||
if player.cheese_count >= 10:
|
||||
print("Congratulations! You collected 10 cheeses!")
|
||||
if player1.cheese_count >= 10:
|
||||
print("Congratulations! Player 1 collected 10 cheeses!")
|
||||
running = False
|
||||
|
||||
screen.fill(BLUE)
|
||||
draw_maze(maze)
|
||||
player.draw(screen)
|
||||
player1.draw(screen)
|
||||
player2.draw(screen)
|
||||
villain.draw(screen)
|
||||
pygame.display.flip()
|
||||
else:
|
||||
|
@ -248,14 +250,14 @@ while running:
|
|||
dx, dy = 0, 0
|
||||
|
||||
if keys[pygame.K_a]:
|
||||
dx = -villain2.speed
|
||||
dx = -player2.speed
|
||||
elif keys[pygame.K_d]:
|
||||
dx = villain2.speed
|
||||
dx = player2.speed
|
||||
|
||||
if keys[pygame.K_w]:
|
||||
dy = -villain2.speed
|
||||
dy = -player2.speed
|
||||
elif keys[pygame.K_s]:
|
||||
dy = villain2.speed
|
||||
dy = player2.speed
|
||||
|
||||
if dx != 0 and dy != 0:
|
||||
if keys[pygame.K_a]:
|
||||
|
@ -268,15 +270,16 @@ while running:
|
|||
dx = 0
|
||||
|
||||
walls, roads = draw_maze(maze)
|
||||
villain2.move(dx, dy, walls)
|
||||
player2.move(dx, dy, walls)
|
||||
|
||||
if villain2.rect.colliderect(player.rect):
|
||||
print("Game Over! The second villain caught you.")
|
||||
if player2.rect.colliderect(villain2.rect):
|
||||
print("Game Over! Player 2 was caught by the second villain.")
|
||||
running = False
|
||||
|
||||
screen.fill(BLUE)
|
||||
draw_maze(maze)
|
||||
player.draw(screen)
|
||||
player1.draw(screen)
|
||||
player2.draw(screen)
|
||||
villain.draw(screen)
|
||||
villain2.draw(screen)
|
||||
pygame.display.flip()
|
||||
|
|
Loading…
Reference in New Issue