-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
80 lines (47 loc) · 2.38 KB
/
camera.py
File metadata and controls
80 lines (47 loc) · 2.38 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import level_data
import constants
import pygame
#state - 'экран'
#def camera_config (camera, target_rect):
# l = -target_rect.rect.x + 810/2
# t = -target_rect.rect.y + 420/2
# w,h = camera.width, camera.height
#
# l = min(0, l) # Не движемся дальше левой границы
# l = max(-(camera.width-810), l) # Не движемся дальше правой границы
# t = max(-(camera.height-420), t) # Не движемся дальше нижней границы
# t = min(0, t) # Не движемся дальше верхней границы
#
#
# return pygame.Rect (l,t,w,h)
#def camera_config (camera, target_rect, screen_width, screen_height):
# l = -target_rect.x + screen_width/2
# t = -target_rect.y + screen_height/2
# w,h = camera.width, camera.height
#
# l = min(0, l) # Не движемся дальше левой границы
# l = max(-(camera.width - screen_width), l) # Не движемся дальше правой границы
# t = max(-(camera.height- screen_height), t) # Не движемся дальше нижней границы
# t = min(0, t) # Не движемся дальше верхней границы
#
#
# return pygame.Rect (l,t,w,h)
class Camera ():
def __init__ (self, width, height, screen_width, screen_height):
#self.camera_config = camera_config
self.state = pygame.Rect (0, 0, width, height)
self.screen_width = screen_width
self.screen_height = screen_height
def camera_config (self,camera, target_rect):
l = -target_rect.x + self.screen_width/2
t = -target_rect.y + self.screen_height/2
w,h = camera.width, camera.height
l = min(0, l) # Не движемся дальше левой границы
l = max(-(camera.width - self.screen_width), l) # Не движемся дальше правой границы
t = max(-(camera.height- self.screen_height), t) # Не движемся дальше нижней границы
t = min(0, t) # Не движемся дальше верхней границы
return pygame.Rect (l,t,w,h)
def apply(self, target):
return target.rect.move(self.state.topleft)
def update(self, target):
self.state = self.camera_config(self.state, target.rect)