Example #1
0
def highlighttile(surf, x, y, looker=None):
    x, y = terrain.nearesttile(x, y)
    h, h0, (gx, gy), ps = terrain.tileinfo(x, y, looker)
    x0, x1 = min(x for x,y in ps), max(x for x,y in ps)
    y0, y1 = min(y for x,y in ps), max(y for x,y in ps)
    s = pygame.Surface(((x1-x0+1), (y1-y0+1))).convert_alpha()
    s.fill((0,0,0,0))
    ps = [(x-x0,y-y0) for x,y in ps]
    pygame.draw.polygon(s, (255, 0, 0, 50), ps)
#    pygame.draw.lines(s, (255, 0, 0, 100), True, ps, 1)
    surf.blit(s, (x0,y0))
Example #2
0
 def compute(self):
     self.surf = pygame.Surface((self.w, self.h)).convert()
     self.lines = bool(settings.tbcolor)
     if self.lines:
         lsurf = pygame.Surface((self.w, self.h)).convert_alpha()
         lsurf.fill((0,0,0,0))
     x0 = int(self.x0 * self.w / settings.tilex // 1) - 1
     x1 = int((self.x0 + 1) * self.w / settings.tilex // 1) + 2
     y0 = int(-(self.y0 + 1) * self.h / settings.tiley // 1)
     onscreen, y = True, y0
     while onscreen:
         onscreen = False
         for x in range(x0, x1):
             if (x + y) % 2: continue
             h, h0, (gx, gy), ps = terrain.tileinfo(x, y, self)
             g = gx * settings.lightx + gy * settings.lighty
             gtexture.putterrain(self.surf, h, h0, g, ps)
             if self.lines:
                 pygame.draw.lines(lsurf, settings.tbcolor, False, ps[0:3], 1)
             if max(py for px, py in ps) > 0:
                 onscreen = True
             yield
         y += 1
     onscreen, y = True, y0 - 1
     while onscreen:
         onscreen = False
         for x in range(x0, x1):
             if (x + y) % 2: continue
             h, h0, (gx, gy), ps = terrain.tileinfo(x, y, self)
             g = gx * settings.lightx + gy * settings.lighty
             gtexture.putterrain(self.surf, h, h0, g, ps)
             if self.lines:
                 pygame.draw.lines(lsurf, settings.tbcolor, False, ps[0:3], 1)
             if min(py for px, py in ps) < self.h:
                 onscreen = True
             yield
         y -= 1
     if self.lines:
         self.surf.blit(lsurf, (0,0))
     self.ready = True
Example #3
0
def minichunk(x0, y0):
    if (x0, y0) not in minimaps:
        t0 = time.time()
        a = settings.mchunksize
        s = pygame.Surface((a, a))
#        arr = pygame.surfarray.pixels3d(s)
        for y in range(a):
            for x in range(-1,a):
                if (x + y) % 2 == 0: continue
                h, h0, (gx, gy), ps = terrain.tileinfo(x0*a+x, y0*a+(a-1-y))
                g = gx * settings.lightx + gy * settings.lighty
                c = gtexture.hcolor(h, h0, g)
                s.set_at((x, y), c)
                s.set_at((x+1, y), c)
#                arr[x,y,:] = gtexture.hcolor(terrain.iheight(x0*a+x, y0*a+(a-1-y)), 0, 0)
        minimaps[(x0,y0)] = s.convert()
#        print(x0, y0, time.time() - t0)
    return minimaps[(x0,y0)]