-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircleshape.py
39 lines (31 loc) · 1.06 KB
/
circleshape.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
import pygame
from constants import *
# 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
pass
def check_collision(self, other):
distance = self.position.distance_to(other.position)
if distance < self.radius + other.radius:
return True
return False
class Shot(CircleShape):
def __init__(self, x, y):
super().__init__(x, y, SHOT_RADIUS)
def draw(self, screen):
pygame.draw.circle(screen, "white", self.position, self.radius, 2)
def update(self, dt):
self.position += self.velocity * dt