-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
25 lines (19 loc) · 770 Bytes
/
camera.py
File metadata and controls
25 lines (19 loc) · 770 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
import pygame
from pygame import sprite
from settings import *
class Camera(sprite.Sprite):
def __init__(self, game, width=winWidth, height=winHeight):
self.camera = pygame.Rect(0, 0, width, height)
self.width = width
self.height = height
self.game = game
sprite.Sprite.__init__(self, game.sprites)
def apply(self, entity):
return entity.rect.move(self.camera.topleft)
def applyRect(self, rect):
return rect.move(self.camera.topleft)
def update(self):
self.target = self.game.currentBlock
x = 0#x = -self.target.rect.centerx + int(winWidth / 2)
y = -self.target.rect.centery + int(winHeight / 2)
self.camera = pygame.Rect(x, y, self.width, self.height)