Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Camera(object):
  2. def __init__(self, width, height):
  3. self.camera = Rect(0, 0, width, height)
  4. self.width = width
  5. self.height = height
  6.  
  7. def apply(self, entity):
  8. return entity.rect.move(self.camera.topleft)
  9.  
  10. def update(self, target):
  11. x = -target.rect.x + int(WIN_WIDTH / 2)
  12. y = -target.rect.y + int(WIN_HEIGHT/2)
  13.  
  14. #Limit scrolling to map size
  15. x = min(0, x) #Left
  16. y = min(0, y) #Top
  17. x = max(-(self.width - WIN_WIDTH), x) #Right
  18. y = max(-(self.height - WIN_HEIGHT), y)#Bottom
  19. self.camera = Rect(x, y, self.width, self.height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement