-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircleshape.py
More file actions
35 lines (28 loc) · 1.03 KB
/
circleshape.py
File metadata and controls
35 lines (28 loc) · 1.03 KB
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
import pygame
from constants import SCREEN_HEIGHT, SCREEN_WIDTH
# Base class for game objects
class CircleShape(pygame.sprite.Sprite):
def __init__(self, x, y, radius):
# we will be using this later
if hasattr(self, "containers"):
super().__init__(self.containers)
else:
super().__init__()
self.position = pygame.Vector2(x, y)
self.velocity = pygame.Vector2(0, 0)
self.radius = radius
def draw(self, screen):
# sub-classes must override
pass
def update(self, dt):
# sub-classes must override
if self.position.x > SCREEN_WIDTH:
self.position.x = 0
elif self.position.x < 0:
self.position.x = SCREEN_WIDTH
if self.position.y > SCREEN_HEIGHT:
self.position.y = 0
elif self.position.y < 0:
self.position.y = SCREEN_HEIGHT
def collision(self, other) -> bool:
return self.position.distance_to(other.position) < self.radius + other.radius