コード例 #1
0
 def tocamera(self, cam):
     # ix, iy are chunk-coords
     c0 = (XY(cam.rect.left, cam.rect.top) / QUANTS_PER_CHUNK).intize()
     c1 = (XY(cam.rect.right, cam.rect.bottom) / QUANTS_PER_CHUNK).intize()
     for ix in range(c0.x - 1, c1.x + 1):
         for iy in range(c0.y - 1, c1.y + 1):
             ixy = XY(ix, iy)
             # point on screen where chunk is rendered
             scr_targetxy = cam.worldtoscreen(
                 ixy * PIXELS_PER_CHUNK * QUANTS_PER_PIXEL  # QUANTS_PER_CHUNK
             ).floor()
             cam.sur.blit(self.getchunk(ixy).image, scr_targetxy.totuple())
コード例 #2
0
 def __init__(self, _index):
     self.index = _index
     self.contents = self.initmap()
     self.image = pygame.Surface((int(PIXELS_PER_CHUNK), int(PIXELS_PER_CHUNK)))
     
     for ix in range(0, TILES_PER_CHUNK):
         for iy in range(0, TILES_PER_CHUNK):
             try:
                 self.image.blit(
                     tiles[self.get(XY(ix, iy))].sprite,  # sprite in tile i
                     (
                         ix * QUANTS_PER_TILE / QUANTS_PER_PIXEL,
                         iy * QUANTS_PER_TILE / QUANTS_PER_PIXEL
                     )
                 )
             except TypeError:
                 print(self.contents[ix])
                 raise
コード例 #3
0
ファイル: camera.py プロジェクト: NegDelta/pygmalion
 def screentoworld(self, xy: XY) -> XY:
     return xy * QUANTS_PER_PIXEL + XY(self.rect.left, self.rect.top)
コード例 #4
0
ファイル: camera.py プロジェクト: NegDelta/pygmalion
 def rectworldtoscreen(self, r: pygame.Rect) -> pygame.Rect:
     acc = r.copy()
     acc.width, acc.height = acc.width / QUANTS_PER_PIXEL, acc.height / QUANTS_PER_PIXEL
     acc.topleft = self.worldtoscreen(XY(r.left, r.top)).totuple()
     return acc
コード例 #5
0
ファイル: camera.py プロジェクト: NegDelta/pygmalion
 def worldtoscreen(self, xy: XY) -> XY:
     return (xy - XY(self.rect.left, self.rect.top)) / QUANTS_PER_PIXEL
コード例 #6
0
 def set_to(self, _tindex, val):
     if type(_tindex) != XY:
         _tindex = XY(_tindex[0], _tindex[1])
     cindex = _tindex // TILES_PER_CHUNK
     tindex = _tindex % TILES_PER_CHUNK
     self.getchunk(cindex).set_to(tindex, val)
コード例 #7
0
 def get(self, _tindex) -> int:
     if type(_tindex) != XY:
         _tindex = XY(_tindex[0], _tindex[1])
     cindex = _tindex // TILES_PER_CHUNK
     tindex = _tindex % TILES_PER_CHUNK
     return self.getchunk(cindex).get(tindex)
コード例 #8
0
def gettilefrompt(pt: XY) -> XY:
    return XY(
        int(pt[0] // QUANTS_PER_TILE),
        int(pt[1] // QUANTS_PER_TILE)
    )