def make_tiles(label=False):
    """Create tiles to fill the current map. This is a utility for easily making
    visible content to aid early game design or debugging.
    
    Tiles transition from top-left to bottom-right, red to blue.
    """
    # Tiles are sprites; each sprite must have a name, an image, and a rect.
    tw, th = State.map.tile_width, State.map.tile_height
    mw, mh = State.map.width, State.map.height
    layer = BasicLayer(State.map, 0)
    State.map.layers.append(layer)
    if label:
        font = pygame.font.Font(data.filepath('font', 'Vera.ttf'), 7)
        fg = Color('yellow')
        bg = Color(70, 70, 70)
    for y in range(mh):
        for x in range(mw):
            s = pygame.sprite.Sprite()
            s.name = (x, y)
            s.image = pygame.surface.Surface((tw, th))
            facx = max(float(x) / mw, 0.01)
            facy = max(float(y) / mh, 0.01)
            R = 255 - 255 * facx
            G = 0
            B = 255 * facy
            s.image.fill((R, G, B))
            s.rect = s.image.get_rect(topleft=(x * tw, y * th))
            if label:
                tag = font.render(str(s.name), 1, fg, bg)
                s.image.blit(tag, (1, 1))
            layer.add(s)
def make_tiles2():
    """Create tiles to fill the current map. This is a utility for easily making
    visible content to aid early game design or debugging.
    
    Tiles transition from top to bottom, light blue to brown.
    """
    # Tiles are sprites; each sprite must have a name, an image, and a rect.
    tw, th = State.map.tile_width, State.map.tile_height
    mw, mh = State.map.width, State.map.height
    layer = BasicLayer(State.map, 0)
    State.map.layers.append(layer)
    for y in range(mh):
        for x in range(mw):
            s = pygame.sprite.Sprite()
            s.name = (x, y)
            s.image = pygame.surface.Surface((tw, th))
            facy = max(float(y) / mh, 0.01)
            R = 200 - 100 * facy
            G = 150 - 100 * facy
            B = 249 - 249 * facy
            s.image.fill((R, G, B))
            pygame.draw.line(s.image, (R + 9, G + 9, B + 9), (0, 0), (0, th))
            s.rect = s.image.get_rect(topleft=(x * tw, y * th))
            layer.add(s)
Ejemplo n.º 3
0
def make_tiles():
    """Create tiles to fill the current map. This is a utility for easily making
    visible content to aid early game design or debugging.
    
    Tiles transition from top-left to bottom-right, red to blue.
    """
    # Tiles are sprites; each sprite must have a name, an image, and a rect.
    tw,th = State.map.tile_width, State.map.tile_height
    mw,mh = State.map.width, State.map.height
    layer = BasicLayer(State.map, 0)
    State.map.layers.append(layer)
    for y in range(mh):
        for x in range(mw):
            s = pygame.sprite.Sprite()
            s.name = (x,y)
            s.image = pygame.surface.Surface((tw,th))
            facx = max(float(x) / mw, 0.01)
            facy = max(float(y) / mh, 0.01)
            R = 255-255*facx
            G = 0
            B = 255*facy
            s.image.fill((R,G,B))
            s.rect = s.image.get_rect(topleft=(x*tw,y*th))
            layer.add(s)
Ejemplo n.º 4
0
def make_map():
    map = State.map
    tw,th = map.tile_width,map.tile_height
    mw,mh = map.width,map.height
    ## Layer 0: Sky with stars.
    layeri = 0
    layer = BasicLayer(map, layeri)
    layer.parallax = Vec2d(.25,.25)
    make_grid = False
    make_labels = False
    for y in range(mh):
        for x in range(mw):
            sprite = pygame.sprite.Sprite()
            sprite.name = x,y
            sprite.image = pygame.surface.Surface((tw,th))
            sprite.rect = sprite.image.get_rect(topleft=(tw*x,th*y))
            for p in [(randrange(256),randrange(256)) for i in range(randrange(30,45))]:
                pygame.draw.line(sprite.image, Color('white'), p, p)
            # Tile debugging.
            if make_labels:
                font = gummworld2.ui.hud_font
                tex = font.render(str(sprite.name), True, Color('yellow'))
                sprite.image.blit(tex, (1,1))
            if make_grid:
                pygame.draw.rect(sprite.image, Color('darkgrey'), sprite.image.get_rect(), 1)
            layer.add(sprite)
    ## A great big moon.
    x = 2 * layer.tile_width
    y = 1 * layer.tile_height
    moon_sprite = layer.objects.intersect_objects(Rect(x,y,1,1))[0]
    pygame.draw.circle(moon_sprite.image, Color(255,255,170), (128,128), 75)
    map.layers.append(layer)
    ## Layer 1: Mountains.
    layeri += 1
    layer = BasicLayer(map, layeri)
    layer.parallax = Vec2d(.55,.55)
    skyline = [(0,th-randrange(randrange(100,150),th-1))]
    for y in range(mh):
        for x in range(mw):
            sprite = pygame.sprite.Sprite()
            sprite.name = x,y
            sprite.image = pygame.surface.Surface((tw,th))
            sprite.image.set_colorkey(Color('black'))
            if y == mh-1:
                skyline = [(tw-1,th-1), (0,th-1), (0,skyline[-1][1])]
                vertices = randrange(3,5)
                points = []
                for i in range(0,tw+1,tw/vertices):
                    i += randrange(25,75)
                    if i >= tw: i = tw - 1
                    points.append((i,th-randrange(randrange(150,th-1),th-1)))
                    if i == tw - 1: break
                points.sort()
                skyline.extend(points)
                pygame.draw.polygon(sprite.image, Color(18,5,5), skyline)
                pygame.draw.lines(sprite.image, Color(25,22,18), False, skyline[2:], 6)
            sprite.rect = sprite.image.get_rect(topleft=(tw*x,th*y))
            layer.add(sprite)
    map.layers.append(layer)
    ## Layer 2,3,4: Trees.
    tree_data = [
        # color         parallax      treetops numtrees
        (Color(0,16,0), Vec2d(.65,.65), th*8/16, 100),
        (Color(0,22,0), Vec2d(.8,.8), th*11/16,  75),
        (Color(0,33,0), Vec2d(1.,1.),   th*15/16, 50),
    ]
    make_grid = False
    make_labels = False
    for color,parallax,treetops,numtrees in tree_data:
        layeri += 1
        layer = BasicLayer(map, layeri)
        layer.parallax = parallax
        skyline = [(0,th-randrange(randrange(100,150),th-1))]
        for y in range(mh):
            ox = []
            rx = []
            for x in range(mw):
                # Null tile if it is "in the sky" and tile debugging is off.
                if y < mh-1 and not (make_grid or make_labels):
##                    layer.add(None)
                    continue
                sprite = pygame.sprite.Sprite()
                sprite.name = x,y
                sprite.image = pygame.surface.Surface((tw,th))
                sprite.image.set_colorkey(Color('black'))
                sprite.rect = sprite.image.get_rect(topleft=(tw*x,th*y))
                # Draw trees on ground tiles.
                if y == mh-1:
                    for i,o in enumerate(ox):
                        pygame.draw.circle(sprite.image, color, o, rx[i])
                    del ox[:],rx[:]
                    for i in range(numtrees):
                        r = randrange(25,35)
                        o = randrange(r,tw), randrange(treetops,th)
                        pygame.draw.circle(sprite.image, color, o, r)
                        if o[0]+r >= tw:
                            ox.append((o[0]-tw, o[1]))
                            rx.append(r)
                # Tile debugging.
                if make_labels:
                    font = gummworld2.ui.hud_font
                    tex = font.render(str(sprite.name), True, Color('yellow'))
                    sprite.image.blit(tex, (1,1))
                if make_grid:
                    pygame.draw.rect(sprite.image, color, sprite.image.get_rect(), 1)
                layer.add(sprite)
        map.layers.append(layer)