Esempio n. 1
0
def generate_light_map(width, height, solids, trees):
	global LIGHTS
	
	LIGHTS = display.create_shader(width, height)
	LIGHTS[0] += 1
	LIGHTS[1] += 1
	LIGHTS[2] += 1
	
	return LIGHTS
#	SUN = numpy.ones((constants.MAP_VIEW_HEIGHT, constants.MAP_VIEW_WIDTH))
#	SUN -= .5
Esempio n. 2
0
def generate_light_map(width, height, solids, trees):
    global LIGHTS

    LIGHTS = display.create_shader(width, height)
    LIGHTS[0] += 1
    LIGHTS[1] += 1
    LIGHTS[2] += 1

    return LIGHTS


#	SUN = numpy.ones((constants.MAP_VIEW_HEIGHT, constants.MAP_VIEW_WIDTH))
#	SUN -= .5
Esempio n. 3
0
def generate_shadow_map(width, height, solids, trees, inside):
    global SHADOWS

    SHADOWS = display.create_shader(width, height)
    SHADOWS[0] += 1
    SHADOWS[1] += 1
    SHADOWS[2] += 1

    _taken = set()

    for x, y in solids:
        if (x, y) in trees:
            continue

        for y1 in range(-3, 4):
            for x1 in range(-3, 4):
                if (x + x1,
                        y + y1) in solids or (x + x1, y + y1) in inside or (
                            x + x1, y + y1
                        ) in _taken or x + x1 >= width or y + y1 >= height:
                    continue

                _shadow = numbers.clip(
                    numbers.distance((x, y),
                                     (x + x1, y + y1)) / 5.0, .25, .6) + .25

                if _shadow < SHADOWS[0][y + y1][x + x1]:
                    SHADOWS[0][y + y1][x + x1] = _shadow
                    SHADOWS[1][y + y1][x + x1] = _shadow
                    SHADOWS[2][y + y1][x + x1] = _shadow

    _taken = set()

    for _x, _y in trees.keys():
        _tree_size = float(trees[_x, _y])

        for x, y in shapes.circle(_x, _y, int(_tree_size)):
            if (x, y) in solids or x >= width or y >= height or x < 0 or y < 0:
                continue

            _distance = numbers.float_distance((x, y), (_x, _y)) * 1.25
            _shadow = numbers.clip(1 - ((_distance / _tree_size) + .25), .1,
                                   .9)

            SHADOWS[0][y][x] = numbers.clip(SHADOWS[0][y][x] - _shadow, .45, 1)
            SHADOWS[1][y][x] = numbers.clip(SHADOWS[1][y][x] - _shadow, .45, 1)
            SHADOWS[2][y][x] = numbers.clip(SHADOWS[2][y][x] - _shadow, .45, 1)

    return SHADOWS
Esempio n. 4
0
def generate_shadow_map(width, height, solids, trees, inside):
	global SHADOWS
	
	SHADOWS = display.create_shader(width, height)
	SHADOWS[0] += 1
	SHADOWS[1] += 1
	SHADOWS[2] += 1
	
	_taken = set()
	
	for x, y in solids:
		if (x, y) in trees:
			continue
		
		for y1 in range(-3, 4):
			for x1 in range(-3, 4):
				if (x+x1, y+y1) in solids or (x+x1, y+y1) in inside or (x+x1, y+y1) in _taken or x+x1 >= width or y+y1 >= height:
					continue
				
				_shadow = numbers.clip(numbers.distance((x, y), (x+x1, y+y1))/5.0, .25, .6) + .25
			
				if _shadow < SHADOWS[0][y+y1][x+x1]:
					SHADOWS[0][y+y1][x+x1] = _shadow
					SHADOWS[1][y+y1][x+x1] = _shadow
					SHADOWS[2][y+y1][x+x1] = _shadow
	
	_taken = set()
	
	for _x, _y in trees.keys():
		_tree_size = float(trees[_x, _y])
		
		for x, y in shapes.circle(_x, _y, int(_tree_size)):
			if (x, y) in solids or x >= width or y >= height or x < 0 or y <0:
				continue
			
			_distance = numbers.float_distance((x, y), (_x, _y))*1.25
			_shadow = numbers.clip(1 - ((_distance / _tree_size) + .25), .1, .9)
			
			SHADOWS[0][y][x] = numbers.clip(SHADOWS[0][y][x]-_shadow, .45, 1)
			SHADOWS[1][y][x] = numbers.clip(SHADOWS[1][y][x]-_shadow, .45, 1)
			SHADOWS[2][y][x] = numbers.clip(SHADOWS[2][y][x]-_shadow, .45, 1)
	
	return SHADOWS
Esempio n. 5
0
def activate(zone_id):
    global ACTIVE_ZONE

    ACTIVE_ZONE = zone_id

    _zone = ZONES[zone_id]
    _noise = tcod.noise_new(2)

    logging.info('Bringing zone \'%s\' online...' % _zone['name'])

    _zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'],
                                           _zone['solids'])
    _zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'],
                                               _zone['solids'])

    display.create_surface('tiles',
                           width=_zone['width'],
                           height=_zone['height'])

    maps.render_map(_zone['tile_map'], _zone['width'], _zone['height'])

    post_processing.start()

    events.register_event('logic', post_processing.tick_sun)

    _static_lighting = display.create_shader(_zone['width'],
                                             _zone['height'],
                                             start_offset=1)
    _zone['shaders'].append(
        post_processing.generate_shadow_map(_zone['width'], _zone['height'],
                                            _zone['solids'], _zone['trees'],
                                            _zone['inside']))
    _zone['shaders'].append(
        post_processing.generate_light_map(_zone['width'], _zone['height'],
                                           _zone['solids'], _zone['trees']))
    _zone['light_maps']['static_lighting'] = _static_lighting
    _zone['shaders'].append(_static_lighting)

    _noise = tcod.noise_new(3)
    _zoom = 2.0
    _zone['fader'] = display.create_shader(_zone['width'], _zone['height'])
    _shader = display.create_shader(_zone['width'], _zone['height'])

    for y in range(0, _zone['height']):
        for x in range(0, _zone['width']):
            if (x, y) in _zone['inside']:
                _height = .75
            else:
                _noise_values = [(_zoom * x / _zone['width']),
                                 (_zoom * y / _zone['height'])]
                _height = .35 + numbers.clip(
                    tcod.noise_get_turbulence(_noise, _noise_values,
                                              tcod.NOISE_SIMPLEX), .35, 1)

            _shader[0][y, x] = 1.3 * _height
            _shader[1][y, x] = 1.3 * _height
            _shader[2][y, x] = 1.1 * _height

    _zone['shaders'].append(_shader)

    for light in _zone['lights']:
        effects.light(light[0],
                      light[1],
                      light[2],
                      r=light[3],
                      g=light[4],
                      b=light[5],
                      light_map='static_lighting')

    #if not '--no-fx' in sys.argv:
    #	post_processing.run(time=8,
    #		                repeat=-1,
    #		                repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH,
    #		                                                                              constants.MAP_VIEW_HEIGHT,
    #		                                                                              8,
    #		                                                                              _noise,
    #		                                                                              _zone['inside']))
    post_processing.run(
        time=0,
        repeat=-1,
        repeat_callback=lambda _: post_processing.post_process_lights())
    #post_processing.run(time=0,
    #                    repeat=-1,
    #                    repeat_callback=lambda _: post_processing.sunlight())

    camera.set_limits(0, 0, _zone['width'] - constants.MAP_VIEW_WIDTH,
                      _zone['height'] - constants.MAP_VIEW_HEIGHT)

    logging.info('Zone \'%s\' is online' % _zone['name'])
Esempio n. 6
0
def activate(zone_id):
	global ACTIVE_ZONE
	
	ACTIVE_ZONE = zone_id
	
	_zone = ZONES[zone_id]
	_noise = tcod.noise_new(2)
	
	logging.info('Bringing zone \'%s\' online...' % _zone['name'])
	
	_zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'], _zone['solids'])
	_zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'], _zone['solids'])
	
	display.create_surface('tiles', width=_zone['width'], height=_zone['height'])
	
	maps.render_map(_zone['tile_map'], _zone['width'], _zone['height'])
	
	post_processing.start()
	
	events.register_event('logic', post_processing.tick_sun)
	
	_static_lighting = display.create_shader(_zone['width'], _zone['height'], start_offset=1)
	_zone['shaders'].append(post_processing.generate_shadow_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'], _zone['inside']))
	_zone['shaders'].append(post_processing.generate_light_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees']))
	_zone['light_maps']['static_lighting'] = _static_lighting
	_zone['shaders'].append(_static_lighting)
	
	_noise = tcod.noise_new(3)
	_zoom = 2.0
	_zone['fader'] = display.create_shader(_zone['width'], _zone['height'])
	_shader = display.create_shader(_zone['width'], _zone['height'])
	
	for y in range(0, _zone['height']):
		for x in range(0, _zone['width']):
			if (x, y) in _zone['inside']:
				_height = .75
			else:
				_noise_values = [(_zoom * x / _zone['width']),
					             (_zoom * y / _zone['height'])]
				_height = .35 + numbers.clip(tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX), .35, 1)
			
			_shader[0][y, x] = 1.3 * _height
			_shader[1][y, x] = 1.3 * _height
			_shader[2][y, x] = 1.1 * _height
	
	_zone['shaders'].append(_shader)
	
	for light in _zone['lights']:
		effects.light(light[0], light[1], light[2], r=light[3], g=light[4], b=light[5], light_map='static_lighting')
	
	#if not '--no-fx' in sys.argv:
	#	post_processing.run(time=8,
	#		                repeat=-1,
	#		                repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH,
	#		                                                                              constants.MAP_VIEW_HEIGHT,
	#		                                                                              8,
	#		                                                                              _noise,
	#		                                                                              _zone['inside']))
	post_processing.run(time=0,
		                repeat=-1,
		                repeat_callback=lambda _: post_processing.post_process_lights())
	#post_processing.run(time=0,
	#                    repeat=-1,
	#                    repeat_callback=lambda _: post_processing.sunlight())
	
	camera.set_limits(0, 0, _zone['width']-constants.MAP_VIEW_WIDTH, _zone['height']-constants.MAP_VIEW_HEIGHT)
	
	logging.info('Zone \'%s\' is online' % _zone['name'])