se_uebungen/snake/snake_segment.py
2026-04-23 16:33:28 +02:00

28 lines
937 B
Python

import pygame
from game_object import GameObject
class SnakeSegment(GameObject):
def __init__(self, center: tuple|list, radius: float|int, color: tuple) -> None:
self.__bounding_box = pygame.rect.Rect(0, 0, radius*2, radius*2)
self.__bounding_box.center = center
self.__color = color
def draw(self, surface: pygame.Surface) -> None:
pygame.draw.circle(surface=surface,
color=self.__color,
center=self.__bounding_box.center,
radius=self.__bounding_box.width*0.5)
def get_position(self) -> tuple:
return self.__bounding_box.center
def get_radius(self) -> int|float:
return self.__bounding_box.width*0.5
def get_color(self) -> tuple:
return self.__color
def get_bounding_boxes(self) -> list[pygame.rect.Rect]:
return [self.__bounding_box]