import pygame.draw from common.drawableItem import DrawableItem from enums import color from config.sys import * import pymunk from enums.color import BLACK class BaseBilliard(DrawableItem): def __init__(self, score: int, category: int, color: tuple[int, int, int], pos=(0, 0)): self.__score = score self.__color = color self.__rigid_body = pymunk.Body(BALL_MASS, 1) self.__rigid_body.position = pos self.__shape = pymunk.Circle(self.__rigid_body, BALL_RADIUS) self.__shape.collision_type = category self.__shape.elasticity = 1.0 self.__rigid_body.velocity = pymunk.Vec2d.zero() self.activity = True @property def score(self): return self.__score @property def category(self): return self.__shape.collision_type @property def color(self): return self.__color @property def rigid_body(self): return self.__rigid_body @property def shape(self): return self.__shape @property def pos(self): return self.__rigid_body.position @pos.setter def pos(self, pos: tuple[float, float]): self.__rigid_body.position = pos def draw(self, window): pygame.draw.circle(window, self.__color, self._get_relative_pos(self.pos), BALL_RADIUS) pygame.draw.circle(window, BLACK, self._get_relative_pos(self.pos), BALL_RADIUS, 1) pass def resistance(self): length = self.__rigid_body.velocity.length if length == 0: return if length < TABLE_FRICTION_FACTOR / FPS: self.__rigid_body.velocity = pymunk.Vec2d.zero() return v = self.__rigid_body.velocity.scale_to_length(length - TABLE_FRICTION_FACTOR / FPS) if v.length <= 1: v = pymunk.Vec2d.zero() self.__rigid_body.velocity = v def is_stable(self): return self.__rigid_body.velocity.length <= 1.0 or self.__rigid_body.velocity == pymunk.Vec2d.zero()