-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.py
47 lines (38 loc) · 1.4 KB
/
Ball.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: Sinan Utku Ulu
"""
import pygame
import parameters
from CollusionStrategies import AbstractCollusionStrategy
import numpy as np
import random
class Ball:
def __init__(self, collusion_strategy: AbstractCollusionStrategy, window):
self.x = parameters.X_BALL
self.y = parameters.Y_BALL
self.r = parameters.R_BALL
self.V = parameters.V_BALL
self.alpha = parameters.ALPHA_BALL
self.d_alpha = parameters.DELTA_ALPHA
self.initial_v_x = parameters.V_X_BALL
self.initial_v_y = parameters.V_Y_BALL
self.collusion_strategy = collusion_strategy
self.window = window
self.collusion_strategy.set_ball(self)
self.color = parameters.BALL_COLOR
def draw(self):
pygame.draw.circle(self.window, self.color, (int(round(self.x)), int(round(self.y))), self.r)
def move(self):
if self.alpha < 0:
self.alpha += 2 * np.pi
self.x += self.V * np.cos(self.alpha)
self.y += self.V * np.sin(self.alpha)
def reset(self):
rand1 = random.random()
self.alpha = parameters.ALPHA_BALL if rand1 < 0.5 else np.pi - parameters.ALPHA_BALL
rand2 = random.random()
self.alpha = self.alpha + np.pi / 12 if rand2 < 0.5 else self.alpha - np.pi / 12
self.y = parameters.Y_BALL
self.x = parameters.X_BALL