-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpact_effect.py
More file actions
23 lines (19 loc) · 840 Bytes
/
impact_effect.py
File metadata and controls
23 lines (19 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pygame
from settings import *
class ImpactEffect(pygame.sprite.Sprite):
def __init__(self, position, color):
super().__init__()
self.image = pygame.Surface((10, 10), pygame.SRCALPHA)
self.color = color
self.rect = self.image.get_rect(center=position)
self.lifetime = 10
self.max_radius = 20
def update(self):
self.lifetime -= 1
if self.lifetime <= 0:
self.kill()
current_radius = int(self.max_radius * (1 - (self.lifetime / 10)))
alpha = int(255 * (self.lifetime / 10))
self.image.fill((0, 0, 0, 0))
pygame.draw.circle(self.image, (self.color[0], self.color[1], self.color[2], alpha), (self.max_radius, self.max_radius), current_radius, 2)
self.rect = self.image.get_rect(center=self.rect.center)