diff --git a/snake/main.py b/snake/main.py index 08eee5a..30b6957 100644 --- a/snake/main.py +++ b/snake/main.py @@ -15,6 +15,7 @@ if __name__ == '__main__': window = Window(title='Snake', size=(800, 600), background_color=(0, 128, 0)) input_manager = InputManager() game_objs = [Snake(start_position=(400, 300), + length=5, radius=10, color=(255, 0, 255))] diff --git a/snake/snake.py b/snake/snake.py index 7900eae..9cf3d67 100644 --- a/snake/snake.py +++ b/snake/snake.py @@ -1,15 +1,15 @@ import pygame from game_object import GameObject +from snake_segment import SnakeSegment class Snake(GameObject): - def __init__(self, start_position: tuple|list, radius: float|int, color: tuple) -> None: - self.__pos = start_position - self.__radius = radius - self.__color = color + def __init__(self, start_position: tuple|list, length: int, radius: float|int, color: tuple) -> None: + self.__segments = [SnakeSegment(center=(start_position[0]+2*radius*idx, start_position[1]), + radius=radius, + color=color) + for idx in range(length)] def draw(self, surface: pygame.Surface) -> None: - pygame.draw.circle(surface=surface, - color=self.__color, - center=self.__pos, - radius=self.__radius) \ No newline at end of file + for segment in self.__segments: + segment.draw(surface) \ No newline at end of file diff --git a/snake/snake_segment.py b/snake/snake_segment.py new file mode 100644 index 0000000..f504076 --- /dev/null +++ b/snake/snake_segment.py @@ -0,0 +1,15 @@ +import pygame +from game_object import GameObject + +class SnakeSegment(GameObject): + def __init__(self, center: tuple|list, radius: float|int, color: tuple) -> None: + self.__center = center + self.__radius = radius + self.__color = color + + + def draw(self, surface: pygame.Surface) -> None: + pygame.draw.circle(surface=surface, + color=self.__color, + center=self.__center, + radius=self.__radius) \ No newline at end of file