Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Camera(object):
- def __init__(self, width, height):
- self.camera = Rect(0, 0, width, height)
- self.width = width
- self.height = height
- def apply(self, entity):
- return entity.rect.move(self.camera.topleft)
- def update(self, target):
- x = -target.rect.x + int(WIN_WIDTH / 2)
- y = -target.rect.y + int(WIN_HEIGHT/2)
- #Limit scrolling to map size
- x = min(0, x) #Left
- y = min(0, y) #Top
- x = max(-(self.width - WIN_WIDTH), x) #Right
- y = max(-(self.height - WIN_HEIGHT), y)#Bottom
- self.camera = Rect(x, y, self.width, self.height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement