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