all repos — Legends-RPG @ cfe27f199eb035566a7a0cb057b3d0c482ee51c8

A fantasy mini-RPG built with Python and Pygame.

Viewport stays centered on player
Justin Armstrong justinmeister@gmail.com
Thu, 06 Mar 2014 23:15:31 -0800
commit

cfe27f199eb035566a7a0cb057b3d0c482ee51c8

parent

7a6a78187d162fec0124e97223e27e5ce24245bd

1 files changed, 6 insertions(+), 0 deletions(-)

jump to
M data/states/town.pydata/states/town.py

@@ -20,6 +20,7 @@ self.town_map_dict = self.create_town_sprite_sheet_dict()

self.town_map = self.create_town_map() self.viewport = self.create_viewport() self.level_surface = self.create_level_surface() + self.level_rect = self.level_surface.get_rect() self.player = Player() self.start_positions = self.set_sprite_positions()

@@ -168,6 +169,7 @@ """Updates state"""

self.keys = keys self.current_time = current_time self.player.update(keys, current_time) + self.update_viewport() self.draw_level(surface)

@@ -180,6 +182,10 @@

surface.blit(self.level_surface, (0,0), self.viewport) + def update_viewport(self): + """Viewport stays centered on character, unless at edge of map""" + self.viewport.center = self.player.rect.center + self.viewport.clamp_ip(self.level_rect)