Пример #1
0
def execute(script, **kvargs):
	for function in script:
		_args = parse_arguments(script[function], **kvargs)
		
		if function == 'CREATE_AND_OWN_ITEM':
			_i = items.create_item(_args[0], position=_args[1])
			life.add_item_to_inventory(kvargs['owner'], _i)
		elif function == 'DELETE':
			items.delete_item(ITEMS[kvargs['item_uid']])
		elif function == 'LIGHT_FOLLOW':
			_item = ITEMS[kvargs['item_uid']]
			
			effects.create_light(items.get_pos(kvargs['item_uid']),
			                     (255, 255, 255),
			                     _item['brightness'],
			                     _item['light_shake'],
			                     follow_item=kvargs['item_uid'])
		elif function == 'LIGHT_FOLLOW_REMOVE':
			_item = ITEMS[kvargs['item_uid']]
			
			effects.delete_light_at(items.get_pos(kvargs['item_uid']))
		elif function == 'TOGGLE_BLOCK':
			_item = ITEMS[kvargs['item_uid']]
			
			if _item['blocking']:
				_item['blocking'] = False
			else:
				_item['blocking'] = True
		else:
			logging.error('Script: \'%s\' is not a valid function.' % function)
Пример #2
0
def execute(script, **kvargs):
    for function in script:
        _args = parse_arguments(script[function], **kvargs)

        if function == 'CREATE_AND_OWN_ITEM':
            _i = items.create_item(_args[0], position=_args[1])
            life.add_item_to_inventory(kvargs['owner'], _i)
        elif function == 'DELETE':
            items.delete_item(ITEMS[kvargs['item_uid']])
        elif function == 'LIGHT_FOLLOW':
            _item = ITEMS[kvargs['item_uid']]

            effects.create_light(items.get_pos(kvargs['item_uid']),
                                 (255, 255, 255),
                                 _item['brightness'],
                                 _item['light_shake'],
                                 follow_item=kvargs['item_uid'])
        elif function == 'LIGHT_FOLLOW_REMOVE':
            _item = ITEMS[kvargs['item_uid']]

            effects.delete_light_at(items.get_pos(kvargs['item_uid']))
        elif function == 'TOGGLE_BLOCK':
            _item = ITEMS[kvargs['item_uid']]

            if _item['blocking']:
                _item['blocking'] = False
            else:
                _item['blocking'] = True
        else:
            logging.error('Script: \'%s\' is not a valid function.' % function)
Пример #3
0
def render_lights(size=MAP_WINDOW_SIZE, show_weather=True):
    if not SETTINGS['draw lights']:
        return False

    reset_lights(size=size)
    _weather_light = weather.get_lighting()

    #Not entirely my code. Made some changes to someone's code from libtcod's Python forum.
    RGB_LIGHT_BUFFER[0] = numpy.add(RGB_LIGHT_BUFFER[0], _weather_light[0])
    RGB_LIGHT_BUFFER[1] = numpy.add(RGB_LIGHT_BUFFER[1], _weather_light[1])
    RGB_LIGHT_BUFFER[2] = numpy.add(RGB_LIGHT_BUFFER[2], _weather_light[2])
    (x, y) = SETTINGS['light mesh grid']

    if show_weather:
        weather.generate_effects(size)

    _remove_lights = []
    for light in WORLD_INFO['lights']:
        _x_range = light['pos'][0] - CAMERA_POS[0]
        _y_range = light['pos'][1] - CAMERA_POS[1]

        if _x_range <= -20 or _x_range >= size[0] + 20:
            continue

        if _y_range <= -20 or _y_range >= size[1] + 20:
            continue

        if not 'old_pos' in light:
            light['old_pos'] = (0, 0, -2)
        else:
            light['old_pos'] = light['pos'][:]

        if 'follow_item' in light:
            if not light['follow_item'] in ITEMS:
                _remove_lights.append(light)
                continue

            light['pos'] = items.get_pos(light['follow_item'])[:]

        _render_x = light['pos'][0] - CAMERA_POS[0]
        _render_y = light['pos'][1] - CAMERA_POS[1]
        _x = bad_numbers.clip(light['pos'][0] - (size[0] / 2), 0, MAP_SIZE[0])
        _y = bad_numbers.clip(light['pos'][1] - (size[1] / 2), 0, MAP_SIZE[1])
        _top_left = (_x, _y, light['pos'][2])

        #TODO: Render only on move
        if not tuple(light['pos']) == tuple(light['old_pos']):
            light['los'] = cython_render_los.render_los(
                (light['pos'][0], light['pos'][1]),
                light['brightness'] * 2,
                view_size=size,
                top_left=_top_left)

        los = light['los'].copy()

        _x_scroll = _x - CAMERA_POS[0]
        _x_scroll_over = 0
        _y_scroll = _y - CAMERA_POS[1]
        _y_scroll_over = 0

        if _x_scroll < 0:
            _x_scroll_over = _x_scroll
            _x_scroll = los.shape[1] + _x_scroll

        if _y_scroll < 0:
            _y_scroll_over = _y_scroll
            _y_scroll = los.shape[0] + _y_scroll

        los = numpy.roll(los, _y_scroll, axis=0)
        los = numpy.roll(los, _x_scroll, axis=1)
        los[_y_scroll_over:_y_scroll, ] = 1
        los[:, _x_scroll_over:_x_scroll] = 1

        if SETTINGS['diffuse light']:
            _y, _x = diffuse_light((y, x))
            (x, y) = numpy.meshgrid(_x, _y)

        sqr_distance = (x - (_render_x))**2.0 + (y - (_render_y))**2.0

        brightness = bad_numbers.clip(
            random.uniform(light['brightness'] * light['shake'],
                           light['brightness']), 0.01, 50) / sqr_distance
        brightness *= los
        #brightness *= LOS_BUFFER[0]

        #_mod = (abs((WORLD_INFO['length_of_day']/2)-WORLD_INFO['real_time_of_day'])/float(WORLD_INFO['length_of_day']))*5.0
        #_mod = bad_numbers.clip(_mod-1, 0, 1)
        #(255*_mod, 165*_mod, 0*_mod)
        #print brightness
        #light['brightness'] = 25
        #light['color'][0] = 255*(light['brightness']/255.0)
        #light['color'][1] = (light['brightness']/255.0)
        #light['color'][2] = 255*(light['brightness']/255.0)
        RGB_LIGHT_BUFFER[0] -= (
            brightness.clip(0, 2) * (light['color'][0])
        )  #numpy.subtract(RGB_LIGHT_BUFFER[0], light['color'][0]).clip(0, 255)
        RGB_LIGHT_BUFFER[1] -= (
            brightness.clip(0, 2) * (light['color'][1])
        )  #numpy.subtract(RGB_LIGHT_BUFFER[1], light['color'][1]).clip(0, 255)
        RGB_LIGHT_BUFFER[2] -= (
            brightness.clip(0, 2) * (light['color'][2])
        )  #numpy.subtract(RGB_LIGHT_BUFFER[2], light['color'][2]).clip(0, 255)
Пример #4
0
def render_lights(size=MAP_WINDOW_SIZE, show_weather=True):
	if not SETTINGS['draw lights']:
		return False

	reset_lights(size=size)
	_weather_light = weather.get_lighting()
	
	#Not entirely my code. Made some changes to someone's code from libtcod's Python forum.
	RGB_LIGHT_BUFFER[0] = numpy.add(RGB_LIGHT_BUFFER[0], _weather_light[0])
	RGB_LIGHT_BUFFER[1] = numpy.add(RGB_LIGHT_BUFFER[1], _weather_light[1])
	RGB_LIGHT_BUFFER[2] = numpy.add(RGB_LIGHT_BUFFER[2], _weather_light[2])
	(x, y) = SETTINGS['light mesh grid']
	
	if show_weather:
		weather.generate_effects(size)

	_remove_lights = []
	for light in WORLD_INFO['lights']:
		_x_range = light['pos'][0]-CAMERA_POS[0]
		_y_range = light['pos'][1]-CAMERA_POS[1]
		
		if _x_range <= -20 or _x_range>=size[0]+20:
			continue
		
		if _y_range <= -20 or _y_range>=size[1]+20:
			continue
		
		if not 'old_pos' in light:
			light['old_pos'] = (0, 0, -2)
		else:
			light['old_pos'] = light['pos'][:]
		
		if 'follow_item' in light:
			if not light['follow_item'] in ITEMS:
				_remove_lights.append(light)
				continue
				
			light['pos'] = items.get_pos(light['follow_item'])[:]
		
		_render_x = light['pos'][0]-CAMERA_POS[0]
		_render_y = light['pos'][1]-CAMERA_POS[1]
		_x = numbers.clip(light['pos'][0]-(size[0]/2),0,MAP_SIZE[0])
		_y = numbers.clip(light['pos'][1]-(size[1]/2),0,MAP_SIZE[1])
		_top_left = (_x,_y,light['pos'][2])
		
		#TODO: Render only on move
		if not tuple(light['pos']) == tuple(light['old_pos']):
			light['los'] = cython_render_los.render_los((light['pos'][0],light['pos'][1]), light['brightness']*2, view_size=size, top_left=_top_left)
		
		los = light['los'].copy()
		
		_x_scroll = _x-CAMERA_POS[0]
		_x_scroll_over = 0
		_y_scroll = _y-CAMERA_POS[1]
		_y_scroll_over = 0
		
		if _x_scroll<0:
			_x_scroll_over = _x_scroll
			_x_scroll = los.shape[1]+_x_scroll
		
		if _y_scroll<0:
			_y_scroll_over = _y_scroll
			_y_scroll = los.shape[0]+_y_scroll
		
		los = numpy.roll(los, _y_scroll, axis=0)
		los = numpy.roll(los, _x_scroll, axis=1)
		los[_y_scroll_over:_y_scroll,] = 1
		los[:,_x_scroll_over:_x_scroll] = 1
		
		if SETTINGS['diffuse light']:
			_y, _x = diffuse_light((y, x))
			(x, y) = numpy.meshgrid(_x, _y)
		
		sqr_distance = (x - (_render_x))**2.0 + (y - (_render_y))**2.0
		
		brightness = numbers.clip(random.uniform(light['brightness']*light['shake'], light['brightness']), 0.01, 50) / sqr_distance
		brightness *= los
		#brightness *= LOS_BUFFER[0]
		
		#_mod = (abs((WORLD_INFO['length_of_day']/2)-WORLD_INFO['real_time_of_day'])/float(WORLD_INFO['length_of_day']))*5.0	
		#_mod = numbers.clip(_mod-1, 0, 1)
		#(255*_mod, 165*_mod, 0*_mod)
		#print brightness
		#light['brightness'] = 25
		#light['color'][0] = 255*(light['brightness']/255.0)
		#light['color'][1] = (light['brightness']/255.0)
		#light['color'][2] = 255*(light['brightness']/255.0)
		RGB_LIGHT_BUFFER[0] -= (brightness.clip(0, 2)*(light['color'][0]))#numpy.subtract(RGB_LIGHT_BUFFER[0], light['color'][0]).clip(0, 255)
		RGB_LIGHT_BUFFER[1] -= (brightness.clip(0, 2)*(light['color'][1]))#numpy.subtract(RGB_LIGHT_BUFFER[1], light['color'][1]).clip(0, 255)
		RGB_LIGHT_BUFFER[2] -= (brightness.clip(0, 2)*(light['color'][2]))#numpy.subtract(RGB_LIGHT_BUFFER[2], light['color'][2]).clip(0, 255)