-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
31 lines (23 loc) · 876 Bytes
/
camera.py
File metadata and controls
31 lines (23 loc) · 876 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
29
30
31
import pygame
from stgs import *
class cam:
def __init__(self, width, height):
self.camera = pygame.Rect(0, 0, width, height)
self.width = width
self.height = height
self.limit = CAMLIMIT
self.offsetY = 40
def apply(self, entity):
return entity.rect.move(self.camera.topleft)
def applyRect(self, rect):
return rect.move(self.camera.topleft)
def update(self, target):
x = -target.rect.centerx + int(winWidth / 2)
y = -target.rect.centery + int(winHeight / 2)
# limit scrolling to map size
if self.limit:
x = min(0, x) # left
y = min(self.offsetY, y) # top
x = max(-(self.width - winWidth), x) # right
y = max(-(self.height - winHeight), y) # bottom
self.camera = pygame.Rect(x, y, self.width, self.height)