-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircleshape.py
More file actions
28 lines (21 loc) · 825 Bytes
/
Copy pathcircleshape.py
File metadata and controls
28 lines (21 loc) · 825 Bytes
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
import pygame
# Base class for game objects
class CircleShape(pygame.sprite.Sprite):
containers: tuple[pygame.sprite.Group, ...]
def __init__(self, x: float, y: float, radius: float) -> None:
# we will be using this later
if hasattr(self, "containers"):
super().__init__(*self.containers)
else:
super().__init__()
self.position: pygame.Vector2 = pygame.Vector2(x, y)
self.velocity = pygame.Vector2(0, 0)
self.radius = radius
def draw(self, screen: pygame.Surface) -> None:
# must override
pass
def update(self, dt: float) -> None:
# must override
pass
def collides_with(self, other: "CircleShape") -> bool:
return self.position.distance_to(other.position) <= self.radius + other.radius