import pygame import pymunk from common.drawableItem import DrawableItem from common.game.billiards.baseBilliard import BaseBilliard from common.game.billiards.cueBall import CueBall from common.game.gameData import GameData from config.sys import CUE_LENGTH, CUE_WIDTH, BALL_RADIUS from enums.color import BLACK, WHITE class Cue(DrawableItem): def __init__(self, cue_ball: CueBall, game_data: GameData): self.__cue_ball = cue_ball self.__mouse_pos: tuple[float, float] = (0, 0) self.__game_data = game_data pass def draw(self, window: pygame.Surface): if not self.__cue_ball: return if not self.__game_data.is_stable(): return cue_ball_pos = self.__cue_ball.pos mouse_pos = pymunk.Vec2d(self.__mouse_pos[0], self.__mouse_pos[1]) cue_vector_x = (self._get_relative_pos(cue_ball_pos) - mouse_pos)[0] cue_vector_y = (self._get_relative_pos(cue_ball_pos) - mouse_pos)[1] cue_vector = pymunk.Vec2d(cue_vector_x, cue_vector_y).scale_to_length(CUE_LENGTH) pygame.draw.line(window, WHITE, self._get_relative_pos(cue_ball_pos), mouse_pos - (mouse_pos - self._get_relative_pos(cue_ball_pos)).scale_to_length(BALL_RADIUS), 1) pygame.draw.circle(window, WHITE, mouse_pos, BALL_RADIUS, 1) pygame.draw.line(window, BLACK, self._get_relative_pos(cue_ball_pos), self._get_relative_pos(cue_ball_pos) + cue_vector, CUE_WIDTH) pass @property def mouse_pos(self): return self.__mouse_pos @mouse_pos.setter def mouse_pos(self, mouse_pos): self.__mouse_pos = mouse_pos