Update actors/pill.py

This commit is contained in:
2025-04-15 22:18:22 +02:00
parent 9e137a333c
commit e53b52b1d7

View File

@@ -1,5 +1,5 @@
import pygame import pygame
from .enums import PillType from enums import PillType
class Pill(pygame.sprite.Sprite): class Pill(pygame.sprite.Sprite):
def __init__(self, x, y, pill_type: PillType): def __init__(self, x, y, pill_type: PillType):
@@ -7,16 +7,38 @@ class Pill(pygame.sprite.Sprite):
self.x = x self.x = x
self.y = y self.y = y
self.pill_type = pill_type self.pill_type = pill_type
self.eaten = False
self.radius = 2 if pill_type == PillType.NORMAL else 6 self.radius = 2 if pill_type == PillType.NORMAL else 6
self.color = (255, 255, 255) self.color = (255, 255, 255)
self.image = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA) self.image = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA)
pygame.draw.circle(self.image, self.color, (self.radius, self.radius), self.radius) pygame.draw.circle(self.image, self.color, (self.radius, self.radius), self.radius)
self.rect = self.image.get_rect(center=(x, y)) self.rect = self.image.get_rect(center=(x, y))
def check_eaten(self, pacman_rect, game_state):
if not self.eaten and self.rect.colliderect(pacman_rect):
self.eaten = True
self.kill()
return self.on_eaten(game_state)
return 0
def on_eaten(self, game_state):
"""Override this in subclasses to apply effects when eaten"""
return 0
class NormalPill(Pill): class NormalPill(Pill):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__(x, y, PillType.NORMAL) super().__init__(x, y, PillType.NORMAL)
def on_eaten(self, game_state):
game_state["score"] += 100
return 100
class PowerPill(Pill): class PowerPill(Pill):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__(x, y, PillType.POWER) super().__init__(x, y, PillType.POWER)
def on_eaten(self, game_state):
game_state["score"] += 500
game_state["ghost_mode"] = "frightened"
game_state["frightened_timer"] = pygame.time.get_ticks() # Optional
return 500