You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.6 KiB
66 lines
2.6 KiB
import pygame.draw
|
|
import pymunk
|
|
|
|
from common.drawableItem import DrawableItem
|
|
from common.game.gameData import GameData
|
|
from common.game.hole import Hole
|
|
from config.sys import *
|
|
from enums.color import BLACK, GREEN
|
|
|
|
|
|
class Table(DrawableItem):
|
|
def __init__(self, game_data: GameData):
|
|
self.__size = TABLE_SIZE
|
|
self.__game_data = game_data
|
|
self.__cushing_body = [
|
|
pymunk.Body(body_type=pymunk.Body.STATIC),
|
|
pymunk.Body(body_type=pymunk.Body.STATIC),
|
|
pymunk.Body(body_type=pymunk.Body.STATIC),
|
|
pymunk.Body(body_type=pymunk.Body.STATIC),
|
|
pymunk.Body(body_type=pymunk.Body.STATIC),
|
|
pymunk.Body(body_type=pymunk.Body.STATIC)
|
|
]
|
|
self.__cushing_shape: list[pymunk.Segment] = [
|
|
pymunk.Segment(self.__cushing_body[0], (0, HOLE_RADIUS), (0, TABLE_HEIGHT - HOLE_RADIUS), 1),
|
|
pymunk.Segment(self.__cushing_body[1], (HOLE_RADIUS, TABLE_HEIGHT),
|
|
(TABLE_WIDTH / 2 - HOLE_RADIUS, TABLE_HEIGHT), 1),
|
|
pymunk.Segment(self.__cushing_body[2], (TABLE_WIDTH / 2 + HOLE_RADIUS, TABLE_HEIGHT),
|
|
(TABLE_WIDTH - HOLE_RADIUS, TABLE_HEIGHT), 1),
|
|
pymunk.Segment(self.__cushing_body[3], (TABLE_WIDTH, TABLE_HEIGHT - HOLE_RADIUS),
|
|
(TABLE_WIDTH, HOLE_RADIUS), 1),
|
|
pymunk.Segment(self.__cushing_body[4], (HOLE_RADIUS, 0),
|
|
(TABLE_WIDTH / 2 - HOLE_RADIUS, 0), 1),
|
|
pymunk.Segment(self.__cushing_body[5], (TABLE_WIDTH / 2 + HOLE_RADIUS, 0),
|
|
(TABLE_WIDTH - HOLE_RADIUS, 0), 1),
|
|
]
|
|
self.__holes = [
|
|
Hole((0, 0), game_data), Hole((TABLE_WIDTH / 2, 0), game_data),
|
|
Hole((TABLE_WIDTH, 0), game_data),Hole((0, TABLE_HEIGHT), game_data),
|
|
Hole((TABLE_WIDTH / 2, TABLE_HEIGHT), game_data),Hole((TABLE_WIDTH, TABLE_HEIGHT), game_data)
|
|
]
|
|
for _ in self.__cushing_shape:
|
|
_.elasticity = 1.0
|
|
pass
|
|
|
|
def draw(self, window):
|
|
pos1 = self._get_relative_pos((0, 0))
|
|
pos2 = (TABLE_WIDTH, TABLE_HEIGHT)
|
|
pygame.draw.rect(window, GREEN, (pos1, pos2))
|
|
for _ in self.__cushing_shape:
|
|
pygame.draw.line(window, BLACK, self._get_relative_pos(_.a), self._get_relative_pos(_.b), TABLE_LINE_WIDTH)
|
|
for _ in self.__holes:
|
|
_.draw(window)
|
|
pass
|
|
|
|
@property
|
|
def cushing_body(self):
|
|
return self.__cushing_body
|
|
|
|
@property
|
|
def cushing_shape(self):
|
|
return self.__cushing_shape
|
|
|
|
def goal(self, space, balls):
|
|
for _ in self.__holes:
|
|
_.goal(space, balls)
|