Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
def _can_see_position(pos1,
                      pos2,
                      max_length=10,
                      block_check=False,
                      strict=False,
                      distance=True):
    if block_check:
        _check = [(-1, -1), (1, -1), (0, 0), (-1, 1), (1, 1)]
    else:
        _check = [(0, 0)]

    _ret_line = []
    for _pos in _check:
        _line = render_los.draw_line(pos1[0], pos1[1], pos2[0], pos2[1])

        if not _line:
            _line = []

        if _pos == (0, 0):
            _ret_line = _line

        if len(_line) > max_length and distance:
            _ret_line = []
            continue

        for pos in _line:
            _chunk = chunks.get_chunk_from_cache(pos)

            #for item_uid in _chunk['items'][:]:
            #	if not item_uid in ITEMS:
            #		_chunk['items'].remove(item_uid)

            #for item in [ITEMS[uid] for uid in _chunk['items'] if items.is_blocking(uid)]:
            #	if tuple(item['pos'])[:2] == tuple(pos2)[:2]:
            #		continue
            #
            #	if (pos[0], pos[1]) == tuple(item['pos'])[:2]:
            #		_ret_line = []
            #		if strict:
            #			return False
            #
            #		continue

            if maps.is_solid((pos[0], pos[1], pos1[2] + 1)):
                _ret_line = []
                if strict:
                    return False

                continue

    return _ret_line
Exemplo n.º 4
0
def _can_see_position(pos1, pos2, max_length=10, block_check=False, strict=False, distance=True):
	if block_check:
		_check = [(-1, -1), (1, -1), (0, 0), (-1, 1), (1, 1)]
	else:
		_check = [(0, 0)]
	
	_ret_line = []
	for _pos in _check:
		_line = render_los.draw_line(pos1[0],
		                             pos1[1],
		                             pos2[0],
		                             pos2[1])
										 
		if not _line:
			_line = []
		
		if _pos == (0, 0):
			_ret_line = _line
		
		if len(_line) > max_length and distance:
			_ret_line = []
			continue
		
		for pos in _line:
			_chunk = chunks.get_chunk_from_cache(pos)
			
			#for item_uid in _chunk['items'][:]:
			#	if not item_uid in ITEMS:
			#		_chunk['items'].remove(item_uid)
			
			#for item in [ITEMS[uid] for uid in _chunk['items'] if items.is_blocking(uid)]:
			#	if tuple(item['pos'])[:2] == tuple(pos2)[:2]:
			#		continue
			#	
			#	if (pos[0], pos[1]) == tuple(item['pos'])[:2]:
			#		_ret_line = []
			#		if strict:
			#			return False
			#		
			#		continue
				
			if maps.is_solid((pos[0], pos[1], pos1[2]+1)):
				_ret_line = []
				if strict:
					return False
				
				continue
	
	return _ret_line
Exemplo n.º 5
0
def collision_with_solid(item, pos):
	if pos[0]<0 or pos[0]>=MAP_SIZE[0]-1 or pos[1]<0 or pos[1]>=MAP_SIZE[1]-1 or pos[2]<0 or pos[2]>=MAP_SIZE[2]-1:
		return True
	
	if maps.is_solid(pos) and item['velocity'][2]<0:
		#TODO: Bounce
		item['velocity'] = [0, 0, 0]
		item['pos'] = pos
		process_event(item, 'stop')
			
		return True
	
	if item['velocity'][2]>=0:
		_z = 1
	else:
		_z = -1
	
	if not pos[0]-1 < 0 and item['velocity'][0]<0 and WORLD_INFO['map'][pos[0]-1][pos[1]][pos[2]+_z]:
		item['velocity'][0] = -item['velocity'][0]*.8
		
		if 'max_speed' in item:
			effects.create_smoke_cloud(pos, 4)
	elif not pos[0]+1 >= MAP_SIZE[0]-1 and item['velocity'][0]>0 and WORLD_INFO['map'][pos[0]+1][pos[1]][pos[2]+_z]:
		item['velocity'][0] = -item['velocity'][0]*.8
		
		if 'max_speed' in item:
			effects.create_smoke_cloud(pos, 4)
	
	if not pos[1]-1 < 0 and item['velocity'][1]<0 and WORLD_INFO['map'][pos[0]][pos[1]-1][pos[2]+_z]:
		item['velocity'][1] = -item['velocity'][1]*.8
		
		if 'max_speed' in item:
			effects.create_smoke_cloud(pos, 4)
	elif not pos[1]+1 >= MAP_SIZE[1]-1 and item['velocity'][1]>0 and WORLD_INFO['map'][pos[0]][pos[1]+1][pos[2]+_z]:
		item['velocity'][1] = -item['velocity'][1]*.8
		
		if 'max_speed' in item:
			effects.create_smoke_cloud(pos, 4)
	
	if 'max_speed' in item:
		effects.create_vapor(pos, 5, numbers.clip(item['speed']/30, 0, 1))
	
	return False
Exemplo n.º 6
0
def process_slice(z, world_info=None, start_id=0, map_size=MAP_SIZE):
	#print 'Processing:', z
	_runs = 0
	_slice = create_map_array(size=map_size)
	_ground = []
	_unzoned = {}
	
	for y in range(map_size[1]):
		for x in range(map_size[0]):
			if not WORLD_INFO['map'][x][y][z]:# or not maps.is_solid((x, y, z)):
				continue
		
			if maps.is_solid((x, y, z)) and z>0 and z<=map_size[2]:
				if maps.is_solid((x, y, z+1)) and maps.is_solid((x, y, z-1)):
					continue
			
			_unzoned[(x, y)] = None
	
	if world_info:
		WORLD_INFO.update(world_info)
		
	for x in range(map_size[0]):
		for y in range(map_size[1]):
			if z < map_size[2]-1 and maps.is_solid((x, y, z+1)):
				if z < map_size[2]-2 and maps.is_solid((x, y, z+2)):
					_slice[x][y] = -2
				else:
					_slice[x][y] = -1
	
	while 1:
		if world_info:
			start_id += 1
			_z_id = start_id
		else:
			WORLD_INFO['zoneid'] += 1
			_z_id = WORLD_INFO['zoneid']
		
		_ramps = set()
		_start_pos = get_unzoned(_slice, _unzoned, z, map_size=map_size)
		
		if not _start_pos:
			break
		
		_slice[_start_pos[0]][_start_pos[1]] = _z_id
		_ground = [_start_pos]
		del _unzoned[_start_pos]
		_top_left = [map_size[0], map_size[1]]
		_bot_right = [0, 0]
		_to_check = [_start_pos]
		
		if _start_pos[0] < _top_left[0]:
			_top_left[0] = _start_pos[0]
		if _start_pos[1] < _top_left[1]:
			_top_left[1] = _start_pos[1]
			
		if _start_pos[0] > _bot_right[0]:
			_bot_right[0] = _start_pos[0]
		if _start_pos[1] > _bot_right[1]:
			_bot_right[1] = _start_pos[1]
		
		while _to_check:
			_per_run = time.time()
			_runs += 1
			
			x,y = _to_check.pop(0)
			
			_skip_ramp_check = False
			if z == 2:
				if WORLD_INFO['chunk_map'][alife.chunks.get_chunk_key_at((x, y))]['max_z'] == z:
					_skip_ramp_check = True
			
			if not _slice[x][y] == _z_id:
				continue
			
			for x_mod,y_mod in [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]:
				_x = x+x_mod
				_y = y+y_mod
				
				if _x<0 or _x>=map_size[0] or _y<0 or _y>=map_size[1]:
					continue
				
				if (_x, _y) in _unzoned and not (_slice[_x][_y]):
					_slice[_x][_y] = _z_id
					_ground.append((_x, _y))
					del _unzoned[(_x, _y)]
					
					if _x < _top_left[0]:
						_top_left[0] = _x
					if _y < _top_left[1]:
						_top_left[1] = _y
						
					if _x > _bot_right[0]:
						_bot_right[0] = _x
					if _y > _bot_right[1]:
						_bot_right[1] = _y
					
					_to_check.append((_x, _y))
				
				if _skip_ramp_check:
					continue
				
				if (_x, _y, z+1) in _ramps or (_x, _y, z-1) in _ramps:
					continue
				
				#Above, Below
				if z < map_size[2]-1 and maps.get_tile((_x, _y, z+1)) and maps.is_solid((_x, _y, z+1)):
					if z < map_size[2]-2 and maps.get_tile((_x, _y, z+2)) and maps.is_solid((_x, _y, z+2)):
						pass
					else:
						if (_x, _y, z+1) in _ramps:
							continue
						
						_ramps.add((_x, _y, z+1))
						continue
				
				elif z and (not maps.get_tile((_x, _y, z)) or not maps.is_solid((_x, _y, z))) and maps.is_solid((_x, _y, z-1)):
					if (_x, _y, z-1) in _ramps:
						continue
					
					_ramps.add((_x, _y, z-1))
		
		for pos in _ground:
			WORLD_INFO['map'][pos[0]][pos[1]][z]['z_id'] = _z_id
		
		#print '\t\tRun %s: %s seconds, %s ramps' % (_runs, time.time()-_per_run, len(_ramps))
		
		if world_info:
			return {'z': z, 'id': _z_id, 'ramps': list(_ramps), 'neighbors': {}}
		else:
			WORLD_INFO['slices'][_z_id] = {'z': z, 'top_left': _top_left, 'bot_right': _bot_right, 'id': _z_id, 'ramps': list(_ramps), 'neighbors': {}}
Exemplo n.º 7
0
def collision_with_solid(item, pos):
	_x_diff = bad_numbers.clip(item['pos'][0]-pos[0], -1, 1)
	_y_diff = bad_numbers.clip(item['pos'][1]-pos[1], -1, 1)
	
	if maps.is_solid(pos) and item['velocity'][2]<0:
		#TODO: Bounce
		item['velocity'] = [0, 0, 0]
		#item['pos'] = pos
		
		item['pos'][0] = pos[0]+_x_diff
		item['pos'][1] = pos[1]+_y_diff
		item['realpos'][0] = float(pos[0])+_x_diff
		item['realpos'][1] = float(pos[1])+_y_diff
		
		print '*** STOP ***'
		
		process_event(item, 'stop')
			
		return True
	
	if item['velocity'][2]>=0:
		_z = 1
	else:
		_z = -1
	
	_is_solid = (pos[0], pos[1], pos[2]+_z)
	
	#if not pos[0]-1 < 0 and item['velocity'][0]<0 and WORLD_INFO['map'][pos[0]-1][pos[1]][pos[2]+_z]:
	#	item['velocity'][0] = -item['velocity'][0]*.8
	#
	if _x_diff<0 and _is_solid:
		item['pos'][0] = pos[0]+_x_diff
		item['realpos'][0] = float(pos[0])+_x_diff
		
		if not item['velocity'][0]<0:
			item['velocity'][0] = -item['velocity'][0]*.8
		
		#print '*** bounce ***', _x_diff, item['pos'], pos
		
		#if 'max_speed' in item:
		#	effects.create_smoke_cloud(pos, 4)
	elif _x_diff>0 and _is_solid:
		item['pos'][0] = pos[0]+_x_diff
		item['realpos'][0] = float(pos[0])+_x_diff
		
		if not item['velocity'][0]>0:
			item['velocity'][0] = -item['velocity'][0]*.8
		
		#print '*** bounce ***', _x_diff, item['pos'], pos
		
		#if 'max_speed' in item:
		#	effects.create_smoke_cloud(pos, 4)
	
	if _y_diff<0 and _is_solid:
		item['pos'][1] = pos[1]+_y_diff
		item['realpos'][1] = float(pos[1])+_y_diff
		
		if not item['velocity'][1]<0:
			item['velocity'][1] = -item['velocity'][1]*.8
		
		#print '*** bounce ***', _x_diff, item['pos'], pos
		
		#if 'max_speed' in item:
		#	effects.create_smoke_cloud(pos, 4)
	elif _y_diff>0 and _is_solid:
		item['pos'][1] = pos[1]+_x_diff
		item['realpos'][1] = float(pos[1])+_x_diff
		
		if not item['velocity'][1]>0:
			item['velocity'][1] = -item['velocity'][1]*.8
		
		#print '*** bounce ***', _x_diff, item['pos'], pos
		
		#if 'max_speed' in item:
		#	effects.create_smoke_cloud(pos, 4)
	
	return maps.is_solid(pos)
Exemplo n.º 8
0
def collision_with_solid(item, pos):
    _x_diff = bad_numbers.clip(item['pos'][0] - pos[0], -1, 1)
    _y_diff = bad_numbers.clip(item['pos'][1] - pos[1], -1, 1)

    if maps.is_solid(pos) and item['velocity'][2] < 0:
        #TODO: Bounce
        item['velocity'] = [0, 0, 0]
        #item['pos'] = pos

        item['pos'][0] = pos[0] + _x_diff
        item['pos'][1] = pos[1] + _y_diff
        item['realpos'][0] = float(pos[0]) + _x_diff
        item['realpos'][1] = float(pos[1]) + _y_diff

        print '*** STOP ***'

        process_event(item, 'stop')

        return True

    if item['velocity'][2] >= 0:
        _z = 1
    else:
        _z = -1

    _is_solid = (pos[0], pos[1], pos[2] + _z)

    #if not pos[0]-1 < 0 and item['velocity'][0]<0 and WORLD_INFO['map'][pos[0]-1][pos[1]][pos[2]+_z]:
    #	item['velocity'][0] = -item['velocity'][0]*.8
    #
    if _x_diff < 0 and _is_solid:
        item['pos'][0] = pos[0] + _x_diff
        item['realpos'][0] = float(pos[0]) + _x_diff

        if not item['velocity'][0] < 0:
            item['velocity'][0] = -item['velocity'][0] * .8

        #print '*** bounce ***', _x_diff, item['pos'], pos

        #if 'max_speed' in item:
        #	effects.create_smoke_cloud(pos, 4)
    elif _x_diff > 0 and _is_solid:
        item['pos'][0] = pos[0] + _x_diff
        item['realpos'][0] = float(pos[0]) + _x_diff

        if not item['velocity'][0] > 0:
            item['velocity'][0] = -item['velocity'][0] * .8

        #print '*** bounce ***', _x_diff, item['pos'], pos

        #if 'max_speed' in item:
        #	effects.create_smoke_cloud(pos, 4)

    if _y_diff < 0 and _is_solid:
        item['pos'][1] = pos[1] + _y_diff
        item['realpos'][1] = float(pos[1]) + _y_diff

        if not item['velocity'][1] < 0:
            item['velocity'][1] = -item['velocity'][1] * .8

        #print '*** bounce ***', _x_diff, item['pos'], pos

        #if 'max_speed' in item:
        #	effects.create_smoke_cloud(pos, 4)
    elif _y_diff > 0 and _is_solid:
        item['pos'][1] = pos[1] + _x_diff
        item['realpos'][1] = float(pos[1]) + _x_diff

        if not item['velocity'][1] > 0:
            item['velocity'][1] = -item['velocity'][1] * .8

        #print '*** bounce ***', _x_diff, item['pos'], pos

        #if 'max_speed' in item:
        #	effects.create_smoke_cloud(pos, 4)

    return maps.is_solid(pos)