Changeset 87:75d8ad4bf9b5


Ignore:
Timestamp:
Sep 1, 2013, 9:18:47 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Hack in viewport

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r86 r87  
    6767        self.keys.handle_event(ev)
    6868
     69    def _calc_viewport(self, level_surface, display_surface):
     70        level_size = level_surface.get_size()
     71        display_size = display_surface.get_size()
     72        protagnist_pos = self.protagonist.physicser.render_position(
     73                level_surface)
     74        x_wide = display_size[0] // 2
     75        y_wide = display_size[1] // 2
     76        if protagnist_pos[0] < x_wide:
     77            x = 0
     78        elif protagnist_pos[0] > level_size[0] - x_wide:
     79            x = level_size[0] - display_size[0]
     80        else:
     81            x = protagnist_pos[0] - x_wide
     82        if protagnist_pos[1] < y_wide:
     83            y = 0
     84        elif protagnist_pos[1] > level_size[1] - y_wide:
     85            y = level_size[1] - display_size[1]
     86        else:
     87            y = protagnist_pos[1] - y_wide
     88        return pygame.rect.Rect(x, y, display_size[0], display_size[1])
     89
    6990    def render(self, surface):
    7091        #surface.fill(pygame.color.Color(0, 0, 0))
     
    7394        self.toy_switch.render(mysurface)
    7495        self.protagonist.render(mysurface)
    75         surface.blit(mysurface, (0, 0))
     96        render_rect = self._calc_viewport(mysurface, surface)
     97        surface.blit(mysurface, (0, 0), render_rect)
    7698
    7799    def tick_protagonist(self):
Note: See TracChangeset for help on using the changeset viewer.