source: regenerate_level_data.py

Last change on this file was 408:02a6de5629d6, checked in by Neil Muller <drnlmuller@…>, 11 years ago

Levels can include starting equipment

  • Property exe set to *
File size: 2.5 KB
Line 
1#!/usr/bin/env python
2
3import os.path
4
5import pygame
6from pygame.locals import SWSURFACE, SRCALPHA
7
8from gamelib import tiles, buildings, equipment
9import regenerate_pngs
10
11LEVEL_PATH = "data/levels"
12TILE_WIDTH = 20
13TILE_HEIGHT = 20
14TILES_X = 8
15TILES_Y = 8
16WIDTH = TILES_X * TILE_WIDTH
17HEIGHT = TILES_Y * TILE_HEIGHT
18
19def generate_image(name, basepath):
20    fn, _ = os.path.splitext(os.path.basename(name))
21    svg_name = os.path.join(basepath, fn+".svg")
22    if not os.path.exists(svg_name):
23        print 'Skipping %s, as it seems to be missing' % svg_name
24        return None
25    png_name = os.path.join(LEVEL_PATH, fn+".png")
26    regenerate_pngs.svg_to_png(svg_name, png_name, TILE_WIDTH, TILE_HEIGHT)
27    return pygame.image.load(png_name)
28
29def get_tile_mappings():
30    tile_map = {}
31    for building in buildings.BUILDINGS:
32        tn = building.TILE_NO
33        image = generate_image(building.IMAGE, regenerate_pngs.SPRITE_PATH)
34        if image:
35            tile_map[tn] = image
36    for tn, (_, tile_png) in tiles.TileMap.DEFAULT_TILES.items():
37        if tn not in tile_map:
38            tile_map[tn] = generate_image(tile_png, regenerate_pngs.TILE_PATH)
39    return tile_map
40
41def get_code_mappings():
42    code_map = {}
43    # Needs better handling of wings
44    for tn, sprites in equipment.EQUIP_MAP.iteritems():
45        image = generate_image('chkn', regenerate_pngs.SPRITE_PATH)
46        need_wing = False
47        for equip in sprites:
48            sub_image = generate_image(equip.CHICKEN_IMAGE_FILE,
49                    regenerate_pngs.SPRITE_PATH)
50            image.blit(sub_image, (0, 0))
51            if equip.UNDER_LIMB:
52                need_wing = True
53        if need_wing:
54            sub_image = generate_image('wing', regenerate_pngs.SPRITE_PATH)
55            image.blit(sub_image, (0, 0))
56        if image:
57            code_map[tn] = image
58    return code_map
59
60if __name__ == '__main__':
61    s = pygame.Surface((WIDTH, HEIGHT), SWSURFACE|SRCALPHA, 32)
62    s.fill((0,0,0,0))
63    for n, img in get_tile_mappings().items():
64        rect = (TILE_WIDTH*(n % TILES_X), TILE_HEIGHT*(n / TILES_X), TILE_WIDTH, TILE_HEIGHT)
65        print n, rect
66        s.blit(img, rect)
67    pygame.image.save(s, os.path.join(LEVEL_PATH, "tiles.tga"))
68    s.fill((0,0,0,0))
69    for n, img in get_code_mappings().items():
70        rect = (TILE_WIDTH*(n % TILES_X), TILE_HEIGHT*(n / TILES_X), TILE_WIDTH, TILE_HEIGHT)
71        print n, rect
72        s.blit(img, rect)
73    pygame.image.save(s, os.path.join(LEVEL_PATH, "codes.tga"))
Note: See TracBrowser for help on using the repository browser.