Exemple #1
0
def rain(size):
    _running_time = WORLD_INFO['real_time_of_day'] - WORLD_INFO[
        'real_time_of_day'] / (WORLD_INFO['length_of_day'] /
                               len(WORLD_INFO['weather']['colors'])) * (
                                   WORLD_INFO['length_of_day'] /
                                   len(WORLD_INFO['weather']['colors']))

    _rate = .009

    for i in range(0, int(round(_running_time * _rate))):
        _x = random.randint(0, size[0] - 1)
        _y = random.randint(0, size[1] - 1)
        _skip = False

        if not alife.sight.is_in_fov(LIFE[SETTINGS['controlling']],
                                     (CAMERA_POS[0] + _x, CAMERA_POS[1] + _y)):
            continue

        for z in range(LIFE[SETTINGS['controlling']]['pos'][2] + 1,
                       MAP_SIZE[2]):
            if maps.is_solid((CAMERA_POS[0] + _x, CAMERA_POS[1] + _y, z)):
                _skip = True
                break

        if _skip:
            continue

        REFRESH_POSITIONS.append((_x, _y))

        gfx.tint_tile(_x, _y, tcod.blue, random.uniform(0.1, 0.6))

    #"Wind"
    if logic.can_tick():
        for i in range(random.randint(1, 4)):
            _x = random.randint(0, size[0] - 1)
            _y = random.randint(0, size[1] - 1)
            _skip = False

            if not alife.sight.is_in_fov(
                    LIFE[SETTINGS['controlling']],
                (CAMERA_POS[0] + _x, CAMERA_POS[1] + _y)):
                continue

            for z in range(LIFE[SETTINGS['controlling']]['pos'][2] + 1,
                           MAP_SIZE[2]):
                if maps.is_solid((CAMERA_POS[0] + _x, CAMERA_POS[1] + _y, z)):
                    _skip = True
                    break

            if _skip:
                continue

            effects.create_smoke((CAMERA_POS[0] + _x, CAMERA_POS[1] + _y),
                                 color=tcod.white,
                                 grow=0.1,
                                 decay=0.03,
                                 direction=195,
                                 speed=random.uniform(0.35, 0.8),
                                 max_opacity=.3)
Exemple #2
0
def rain(size):
	_running_time = WORLD_INFO['real_time_of_day'] - WORLD_INFO['real_time_of_day']/(WORLD_INFO['length_of_day']/len(WORLD_INFO['weather']['colors']))*(WORLD_INFO['length_of_day']/len(WORLD_INFO['weather']['colors']))
	
	_rate = .009
	
	for i in range(0, int(round(_running_time*_rate))):
		_x = random.randint(0, size[0]-1)
		_y = random.randint(0, size[1]-1)
		_skip = False
		
		if not alife.sight.is_in_fov(LIFE[SETTINGS['controlling']], (CAMERA_POS[0]+_x, CAMERA_POS[1]+_y)):
			continue
		
		for z in range(LIFE[SETTINGS['controlling']]['pos'][2]+1, MAP_SIZE[2]):
			if maps.is_solid((CAMERA_POS[0]+_x, CAMERA_POS[1]+_y, z)):
				_skip = True
				break
		
		if _skip:
			continue
		
		REFRESH_POSITIONS.append((_x, _y))
		
		gfx.tint_tile(_x, _y, tcod.blue, random.uniform(0.1, 0.6))
	
	#"Wind"
	if logic.can_tick():
		for i in range(random.randint(1, 4)):
			_x = random.randint(0, size[0]-1)
			_y = random.randint(0, size[1]-1)
			_skip = False
			
			if not alife.sight.is_in_fov(LIFE[SETTINGS['controlling']], (CAMERA_POS[0]+_x, CAMERA_POS[1]+_y)):
				continue
			
			for z in range(LIFE[SETTINGS['controlling']]['pos'][2]+1, MAP_SIZE[2]):
				if maps.is_solid((CAMERA_POS[0]+_x, CAMERA_POS[1]+_y, z)):
					_skip = True
					break
		
			if _skip:
				continue
			
			effects.create_smoke((CAMERA_POS[0]+_x, CAMERA_POS[1]+_y), color=tcod.white, grow=0.1, decay=0.03, direction=195, speed=random.uniform(0.35, 0.8), max_opacity=.3)
Exemple #3
0
def main():
    _player_moved = False
    _refresh_map = False

    get_input()
    handle_input()

    if not LIFE[SETTINGS["controlling"]]["dead"]:
        if LIFE[SETTINGS["controlling"]]["asleep"]:
            gfx.fade_to_black(255)
            gfx.start_of_frame()
            gfx.end_of_frame()

        while LIFE[SETTINGS["controlling"]]["asleep"]:
            _played_moved = True
            _refresh_map = True

            gfx.title(LIFE[SETTINGS["controlling"]]["asleep_reason"])
            logic.tick_all_objects(ignore_tickrate=True, ignore_pause=True)

            if LIFE[SETTINGS["controlling"]]["dead"]:
                break
    else:
        _player_moved = True

    if _refresh_map:
        gfx.refresh_view("map")

    if not _player_moved:
        logic.tick_all_objects(ignore_tickrate=True)

    draw_targeting()
    move_camera(SETTINGS["camera_track"])

    # TODO: Deselect so we can get rid of this call
    if SELECTED_TILES[0]:
        gfx.refresh_view("map")

    if not SETTINGS["last_camera_pos"] == SETTINGS["camera_track"][:]:
        if EVENTS or MENUS:
            _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["following"]], judge=False, get_chunks=True)
            alife.brain.flag(LIFE[SETTINGS["following"]], "visible_chunks", value=_visible_chunks)

            _cam_x = numbers.clip(
                LIFE[SETTINGS["following"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2
            )
            _cam_y = numbers.clip(
                LIFE[SETTINGS["following"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2
            )

        else:
            _visible_chunks = sight.scan_surroundings(LIFE[SETTINGS["controlling"]], judge=False, get_chunks=True)
            alife.brain.flag(LIFE[SETTINGS["controlling"]], "visible_chunks", value=_visible_chunks)

        SETTINGS["last_camera_pos"] = SETTINGS["camera_track"][:]

    _cam_x = numbers.clip(
        LIFE[SETTINGS["controlling"]]["pos"][0] - MAP_WINDOW_SIZE[0] / 2, 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0] / 2
    )
    _cam_y = numbers.clip(
        LIFE[SETTINGS["controlling"]]["pos"][1] - MAP_WINDOW_SIZE[1] / 2, 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1] / 2
    )

    maps.render_lights()

    if "--worldmap" in sys.argv:
        render_map.render_map(WORLD_INFO["map"], force_camera_pos=(_cam_x, _cam_y, 2))
    else:
        render_map.render_map(
            WORLD_INFO["map"], los=LIFE[SETTINGS["controlling"]]["fov"], force_camera_pos=(_cam_x, _cam_y, 2)
        )

    items.draw_items()
    life.draw_life()

    if LIFE[SETTINGS["controlling"]]["dead"] and not EVENTS:
        if not death():
            return False

    if SETTINGS["draw life info"] and SETTINGS["following"]:
        life.draw_life_info()

    gfx.draw_message_box()

    menus.align_menus()
    menus.draw_menus()

    gfx.draw_status_line()
    gfx.draw_console()
    gfx.start_of_frame()
    gfx.end_of_frame()

    if "--fps" in sys.argv:
        print tcod.sys_get_fps()

    if (SETTINGS["recording"] and logic.can_tick()) or "--worldmap" in sys.argv:
        gfx.screenshot()

        if "--worldmap" in sys.argv:
            SETTINGS["running"] = False
Exemple #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)
		
		#RGB_LIGHT_BUFFER[0] *= LOS_BUFFER[0]
		#RGB_LIGHT_BUFFER[1] *= LOS_BUFFER[0]
		#RGB_LIGHT_BUFFER[2] *= LOS_BUFFER[0]
		
		if logic.can_tick():
			if light['fade']:
				light['brightness'] -= light['fade']
			
			if light['brightness'] <= 0:
				_remove_lights.append(light)
	
	for light in _remove_lights:
		effects.delete_light(light)