game: add: goal work
This commit is contained in:
@ -8,12 +8,20 @@ import math
|
||||
class Ball:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.size: float = config.BALL_SIZE
|
||||
self.position: Point = Point(config.BALL_SPAWN_POS_X + self.size / 2, config.BALL_SPAWN_POS_Y + self.size / 2)
|
||||
self.angle: float = math.pi * 0.25
|
||||
self.speed: float = config.BALL_SPEED_START
|
||||
self.size: float
|
||||
self.position: Point
|
||||
self.angle: float
|
||||
self.speed: float
|
||||
|
||||
self.reset()
|
||||
|
||||
def to_dict(self):
|
||||
def reset(self) -> None:
|
||||
self.size = config.BALL_SIZE
|
||||
self.position = Point(config.BALL_SPAWN_POS_X + self.size / 2, config.BALL_SPAWN_POS_Y + self.size / 2)
|
||||
self.angle = math.pi * 1
|
||||
self.speed = config.BALL_SPEED_START
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
|
||||
data: dict = {
|
||||
"size": self.size,
|
||||
@ -25,4 +33,4 @@ class Ball:
|
||||
return data
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Ball(size: {self.size}, speed: {self.speed}, director_coefficient: {self.director_coefficient}, ordinate_at_origin: {self.ordinate_at_origin}, position: {self.position})"
|
||||
return f"Ball(size: {self.size}, speed: {self.speed}, angle: {self.angle}, position: {self.position})"
|
@ -1,13 +1,23 @@
|
||||
|
||||
from .Point import Point
|
||||
from .Vector import Vector
|
||||
|
||||
import math
|
||||
|
||||
class Segment:
|
||||
|
||||
def __init__(self, start: Point, stop: Point) -> None:
|
||||
self.start: Point = start
|
||||
self.stop: Point = stop
|
||||
self.length: float = math.dist((self.start.x, self.start.y), (self.stop.x, self.stop.y))
|
||||
|
||||
def angle(self):
|
||||
return math.atan2((self.start.x - self.start.y), (self.stop.x - self.stop.y))
|
||||
|
||||
def length(self):
|
||||
return self.start.distance(self.stop)
|
||||
|
||||
def is_on(self, C: Point):
|
||||
return (self.start.distance(C) + self.stop.distance(C) == self.length())
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Segment(start: {self.start}, stop: {self.stop})"
|
||||
@ -18,7 +28,7 @@ class Segment:
|
||||
def copy(self):
|
||||
return Segment(self.start.copy(), self.stop.copy())
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self) -> dict:
|
||||
|
||||
data: dict[str: dict] = {
|
||||
"start": self.start.to_dict(),
|
||||
|
Reference in New Issue
Block a user