se_uebungen/snake/prey.py
2026-04-23 16:55:47 +02:00

22 lines
662 B
Python

import pygame
import random
from game_object import GameObject
class Prey(GameObject):
def __init__(self, size: int, color: tuple, window_size: tuple):
self.__bounding_box = pygame.rect.Rect(0, 0, size, size)
self.__color = color
self.__window_size = window_size
self.__place_randomly()
def __place_randomly(self) -> None:
self.__bounding_box.center = [random.randint(0, max_val)
for max_val in self.__window_size]
def draw(self, surface: pygame.surface.Surface) -> None:
pygame.draw.rect(surface, color=self.__color, rect=self.__bounding_box)