-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBall.py
31 lines (22 loc) · 982 Bytes
/
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
import math
import random
import pygame
from pygame import Vector2
from utils import utils
class Ball:
def __init__(self,pos,radius,color):
self.color = color
self.radius = radius
self.circle_body = utils.world.CreateDynamicBody(position=(utils.from_Pos((pos.x, pos.y))))
self.circle_shape = self.circle_body.CreateCircleFixture(radius=self.radius, density=1, friction=0.0, restitution=1.0)
self.circle_body.userData = self
self.destroyFlag = False
def draw(self):
for fixture in self.circle_body.fixtures:
self.draw_circle(fixture.shape, self.circle_body, fixture)
def draw_circle(self,circle, body, fixture):
position = utils.to_Pos(body.transform * circle.pos)
pygame.draw.circle(utils.screen, self.color, [int(x) for x in position], int(circle.radius * utils.PPM))
def getPos(self):
p = utils.to_Pos(self.circle_body.position)
return Vector2(p[0],p[1])