更新 2p

main
Vincents Xun 2024-04-26 07:21:30 +00:00
parent fff106ad2d
commit 35c7a1ce20
1 changed files with 12 additions and 10 deletions

22
2p
View File

@ -94,7 +94,7 @@ class Player(pygame.sprite.Sprite):
class Cheese(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.image.load('cheese.png').convert_alpha()
self.image = pygame.image.load('images/cheese/cheese.png').convert_alpha()
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
@ -149,7 +149,7 @@ def draw_maze(maze):
roads.append(pygame.Rect(x * 32, y * 32, 32, 32))
elif char == 'C': # Cheese
roads.append(pygame.Rect(x * 32, y * 32, 32, 32))
screen.blit(pygame.image.load('cheese.png'), (x * 32, y * 32))
screen.blit(pygame.image.load('images/cheese/cheese.png'), (x * 32, y * 32))
elif char == 'V': # Villain
roads.append(pygame.Rect(x * 32, y * 32, 32, 32))
screen.blit(pygame.image.load('villain.png'), (x * 32, y * 32))
@ -171,7 +171,7 @@ def draw_menu():
player1 = Player(32, 32)
player2 = Player(736, 736)
cheese = Cheese(416, 416) # Cheese position
cheese_group = pygame.sprite.Group()
villain = Villain(704, 704, player1) # Villain's starting position
villain2 = Villain(32, 32, player2) # Second villain's starting position
@ -231,19 +231,21 @@ while running:
print("Game Over! Player 1 was caught by the villain.")
running = False
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 player1.cheese_count >= 10:
print("Congratulations! Player 1 collected 10 cheeses!")
running = False
for cheese in cheese_group:
if player1.rect.colliderect(cheese.rect):
player1.cheese_count += 1
cheese_group.remove(cheese)
print("Player 1 collected a cheese! Total cheese count:", player1.cheese_count)
if player1.cheese_count >= 10:
print("Congratulations! Player 1 collected 10 cheeses!")
running = False
screen.fill(BLUE)
draw_maze(maze)
player1.draw(screen)
player2.draw(screen)
villain.draw(screen)
cheese_group.draw(screen)
pygame.display.flip()
else:
keys = pygame.key.get_pressed()