def __init__(self, i, j, pix_size, info): if info['relief'] == self.WATER: self.tile = Tile('water', info, image('h_water.png')) elif info['relief'] == self.SOIL: a = randint(-10, 7) a = '' if (a <= 0) else a self.tile = Tile('soil', info, image('h_earth' + str(a) + '.png')) elif info['relief'] == self.CITY: self.tile = Tile('sity', info, image('h_town1.png')) elif info['relief'] == self.BASE: a = info['player'] self.tile = Tile('base', {}, image('h_castle' + str(a) + '.png')) self.army = None HexCell.__init__(self, i, j, None, pix_size, info, self.tile) self.properties['capacity'] = self.start_capacity
def gen_rect_map(meta, w, h): r = [] cell = None for i, m in enumerate(meta): c = [] r.append(c) for j, info in enumerate(m): c.append(RectCell(i, j, w, h, dict(info), Tile('dbg', {}, None))) return RectMap('debug', w, h, r)
def gen_recthex_map(meta, h): r = [] cell = None w = int(h / math.sqrt(3)) * 2 for i, m in enumerate(meta): c = [] r.append(c) for j, info in enumerate(m): c.append(RectCell(i, j, w, h, dict(info), Tile('dbg', {}, None))) return RectMap('debug', w, h, r)
def gen_hex_map(meta, h): r = [] cell = None for i, m in enumerate(meta): c = [] r.append(c) for j, info in enumerate(m): if cell is None: cell = HexCell(0, 0, h, None, None) k = j if not i % 2: k += 1 c.append(HexCell(i, j, h, dict(info), Tile('dbg', {}, None))) return HexMap('debug', h, r)
pyglet.resource.path.append('data') pyglet.resource.reindex() # make up some solid color images wall = pyglet.image.SolidColorImagePattern( (100, 100, 100, 255)).create_image(16, 16) blank = pyglet.image.SolidColorImagePattern( (200, 200, 200, 255)).create_image(16, 16) select = pyglet.image.SolidColorImagePattern( (0, 255, 0, 128)).create_image(16, 16) invalid = pyglet.image.SolidColorImagePattern( (255, 0, 0, 128)).create_image(16, 16) # now make up my tile types for mapping wall = Tile('wall', {'blocks': True}, wall) floor = Tile('floor', {}, blank) entrance = Tile('entrance', {'entrance': True}, blank) exit = Tile('exit', {'exit': True}, blank) tower = Tile('tower', { 'blocks': True, 'tower': True }, pyglet.resource.image('tower.png')) # size of the game window (30x20 16-pixel cells) WIDTH, HEIGHT = (30 * 16, 20 * 16) def distance(ax, ay, bx, by): '''Determine the distance between two points.''' return math.sqrt((ax - bx)**2 + (ay - by)**2)
# next case self.model.change(1) elif key == pkey.DOWN: # prev case self.model.change(-1) print(__doc__) if len(sys.argv) < 2: selector = 0 else: selector = 1 collider_cls = [RectMapCollider, RectMapWithPropsCollider][selector] director.init() tile_filled = Tile('z', {}, pyglet.image.load('white4x3.png')) maps_cache = aux.generate_maps(tile_filled) cases = [ d for d in aux.case_generator( aux.first_expansion(maps_cache, aux.common_base_cases)) ] model = Model(cases) scene = cocos.scene.Scene() label = Label("-----------------", anchor_x='center', anchor_y='center', color=(255, 255, 255, 160)) label.position = 320, 20 scene.add(label, z=10) model.label = label