-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
32 lines (27 loc) · 890 Bytes
/
camera.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
import pygame
from constants import SCREEN_HEIGHT
class Camera:
def __init__(self):
"""
Инициализация начального сдвига
"""
self.dy = 0
def apply(self, group: pygame.sprite.Group) -> None:
"""
Сдвигает спрайты в группе
:param group: pygame.sprite.Group
:return: None
"""
for sprite in group:
sprite.rect.y += self.dy
def update(self, target: pygame.sprite.Sprite) -> None:
"""
Позиционирует камеру на объекте target
:param target: pygame.sprite.Sprite
:return: None
"""
target_center_y = target.rect.centery
if target_center_y < SCREEN_HEIGHT // 2:
self.dy = SCREEN_HEIGHT // 2 - target_center_y
else:
self.dy = 0