本文整理汇总了Python中numbers.clip函数的典型用法代码示例。如果您正苦于以下问题:Python clip函数的具体用法?Python clip怎么用?Python clip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clip函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: is_confident
def is_confident(life):
_friendly_confidence = 0
_threat_confidence = 0
for target_id in judgement.get_trusted(life, visible=False):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
_recent_mod = numbers.clip(_knows['last_seen_time'], 0, 300)/300.0
if _knows['last_seen_time']:
_friendly_confidence += _recent_mod
else:
_friendly_confidence += judgement.get_ranged_combat_rating_of_target(life, target_id)*_recent_mod
for target_id in judgement.get_threats(life, ignore_escaped=True):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
_recent_mod = numbers.clip(_knows['last_seen_time'], 0, 300)/300.0
if _knows['last_seen_time']:
_threat_confidence += 2*_recent_mod
else:
_threat_confidence += judgement.get_ranged_combat_rating_of_target(life, target_id)*_recent_mod
return _friendly_confidence > _threat_confidence
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:31,代码来源:stats.py
示例2: update_targets_around_noise
def update_targets_around_noise(life, noise):
_most_likely_target = {'target': None, 'last_seen_time': 0}
if 'target' in noise and not life['id'] == noise['target']:
_visiblity = numbers.clip(sight.get_stealth_coverage(LIFE[noise['target']]), 0.0, 1.0)
_visiblity = numbers.clip(_visiblity+(numbers.distance(life['pos'], LIFE[noise['target']]['pos']))/(sight.get_vision(life)/2), 0, 1.0)
if _visiblity >= sight.get_visiblity_of_position(life, LIFE[noise['target']]['pos']):
brain.meet_alife(life, LIFE[noise['target']])
life['know'][noise['target']]['escaped'] = 1
life['know'][noise['target']]['last_seen_at'] = noise['pos'][:]
life['know'][noise['target']]['last_seen_time'] = 0
for target in life['know'].values():
if not target['escaped'] or not target['last_seen_at'] or target['dead']:
continue
if numbers.distance(target['last_seen_at'], noise['pos']) > noise['volume']:
continue
if judgement.is_target_threat(life, target['life']['id']):
if not _most_likely_target['target'] or target['last_seen_time'] < _most_likely_target['last_seen_time']:
_most_likely_target['last_seen_time'] = target['last_seen_time']
_most_likely_target['target'] = target
if _most_likely_target['target']:
_most_likely_target['target']['escaped'] = 1
_most_likely_target['target']['last_seen_at'] = noise['pos'][:]
_most_likely_target['target']['last_seen_time'] = 1
logging.debug('%s heard a noise, attributing it to %s.' % (' '.join(life['name']), ' '.join(_most_likely_target['target']['life']['name'])))
开发者ID:athros,项目名称:Reactor-3,代码行数:32,代码来源:noise.py
示例3: get_overwatch_hardship
def get_overwatch_hardship(no_mod=True):
_stats = WORLD_INFO['overwatch']
_situation = get_player_situation()
if not _situation:
return 0
if no_mod:
_mod = 1
else:
if len(_situation['online_alife']) == len(_situation['trusted_online_alife']):
_mod = _stats['last_updated']/float(WORLD_INFO['ticks'])
else:
_mod = numbers.clip((_stats['last_updated']*1.5)/float(WORLD_INFO['ticks']), 0, 1.0)
#TODO: Decay
#_stats['loss_experienced'] *= _dec
#_stats['danger_experienced'] *= _dec
#_stats['injury'] *= _dec
#_stats['human_encounters'] *= _dec
_hardship = _stats['loss_experienced']
_hardship += _stats['danger_experienced']
_hardship += _stats['injury']
_hardship += _stats['human_encounters']*4
_hardship *= _mod
return numbers.clip(float(_hardship), 0.0, 10.0)
开发者ID:athros,项目名称:Reactor-3,代码行数:28,代码来源:core.py
示例4: check_chunks
def check_chunks(self, force=False):
if not force and WORLD_INFO["ticks"] - self.last_checked < self.check_every:
return False
self.last_checked = WORLD_INFO["ticks"]
for life in [l for l in LIFE.values() if l["online"]]:
_x_min = numbers.clip(life["pos"][0] - MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1 - MAP_WINDOW_SIZE[0])
_y_min = numbers.clip(life["pos"][1] - MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1 - MAP_WINDOW_SIZE[1])
_x_max = numbers.clip(life["pos"][0] + MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1)
_y_max = numbers.clip(life["pos"][1] + MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1)
_refresh = False
for y in range(_y_min, _y_max, WORLD_INFO["chunk_size"]):
for x in range(_x_min, _x_max, WORLD_INFO["chunk_size"]):
maps.load_cluster_at_position_if_needed((x, y))
SETTINGS["loading"] = True
if "player" in life:
_refresh = True
if _refresh:
gfx.refresh_view("map")
SETTINGS["loading"] = False
开发者ID:athros,项目名称:Reactor-3,代码行数:26,代码来源:threads.py
示例5: draw_chunk_map
def draw_chunk_map(life=None, show_faction_ownership=False):
_x_min = numbers.clip(CAMERA_POS[0]/WORLD_INFO['chunk_size'], 0, MAP_SIZE[0]/WORLD_INFO['chunk_size'])
_y_min = numbers.clip(CAMERA_POS[1]/WORLD_INFO['chunk_size'], 0, MAP_SIZE[1]/WORLD_INFO['chunk_size'])
_x_max = numbers.clip(_x_min+WINDOW_SIZE[0], 0, MAP_SIZE[0]/WORLD_INFO['chunk_size'])
_y_max = numbers.clip(_y_min+WINDOW_SIZE[1], 0, MAP_SIZE[1]/WORLD_INFO['chunk_size'])
_life_chunk_key = None
if life:
_life_chunk_key = lfe.get_current_chunk_id(life)
for x in range(_x_min, _x_max):
_d_x = x-(CAMERA_POS[0]/WORLD_INFO['chunk_size'])
if 0>_d_x >= WINDOW_SIZE[0]:
continue
for y in range(_y_min, _y_max):
_d_y = y-(CAMERA_POS[1]/WORLD_INFO['chunk_size'])
_draw = True
_fore_color = tcod.darker_gray
_back_color = tcod.darkest_gray
if 0>_d_y >= WINDOW_SIZE[1]:
continue
_chunk_key = '%s,%s' % (x*WORLD_INFO['chunk_size'], y*WORLD_INFO['chunk_size'])
if life:
if not _chunk_key in life['known_chunks']:
_draw = False
if _draw:
_type = WORLD_INFO['chunk_map'][_chunk_key]['type']
_char = 'x'
if _type in ['building', 'town']:
_fore_color = tcod.light_gray
_char = 'B'
elif _type in ['outpost', 'factory']:
_fore_color = tcod.desaturated_green
_back_color = tcod.desaturated_han
_char = 'M'
elif _type == 'field':
_fore_color = tcod.yellow
elif _type == 'forest':
_fore_color = tcod.dark_green
elif _type in ['road', 'driveway']:
_fore_color = tcod.white
_back_color = tcod.black
_char = '.'
if _chunk_key == _life_chunk_key and time.time()%1>=.5:
_fore_color = tcod.white
_char = 'X'
gfx.blit_char_to_view(_d_x, _d_y, _char, (_fore_color, _back_color), 'chunk_map')
else:
gfx.blit_char_to_view(_d_x, _d_y, 'x', (tcod.darker_gray, tcod.darkest_gray), 'chunk_map')
开发者ID:athros,项目名称:Reactor-3,代码行数:59,代码来源:maps.py
示例6: death
def death():
FADE_TO_WHITE[0] += 0.5
_time_since_death = FADE_TO_WHITE[0]
_time_alive = numbers.clip(
(LIFE[SETTINGS["controlling"]]["time_of_death"] - LIFE[SETTINGS["controlling"]]["created"])
/ float(WORLD_INFO["length_of_day"]),
0.1,
9999,
)
_string = "You die."
_sub_string = LIFE[SETTINGS["controlling"]]["cause_of_death"]
_col = int(round(255 * numbers.clip((_time_since_death / 100.0) - random.uniform(0, 0.15), 0, 1)))
if _time_alive == 1:
_sub_sub_string = "Lived 1 day"
else:
_sub_sub_string = "Lived %s days" % (_time_alive)
gfx.fade_to_black(1)
gfx.blit_string(
(MAP_WINDOW_SIZE[0] / 2) - len(_string) / 2,
MAP_WINDOW_SIZE[1] / 2,
_string,
"map",
fore_color=tcod.Color(_col, 0, 0),
back_color=tcod.Color(0, 0, 0),
)
gfx.blit_string(
(MAP_WINDOW_SIZE[0] / 2) - len(_sub_string) / 2,
(MAP_WINDOW_SIZE[1] / 2) + 2,
_sub_string,
"map",
fore_color=tcod.Color(int(round(_col * 0.75)), int(round(_col * 0.75)), int(round(_col * 0.75))),
back_color=tcod.Color(0, 0, 0),
)
gfx.blit_string(
(MAP_WINDOW_SIZE[0] / 2) - len(_sub_sub_string) / 2,
(MAP_WINDOW_SIZE[1] / 2) + 4,
_sub_sub_string,
"map",
fore_color=tcod.Color(int(round(_col * 0.75)), int(round(_col * 0.75)), int(round(_col * 0.75))),
back_color=tcod.Color(0, 0, 0),
)
if _time_since_death >= 350:
worldgen.save_world()
worldgen.reset_world()
gfx.clear_scene()
SETTINGS["running"] = 1
return False
return True
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:58,代码来源:reactor-3.py
示例7: draw_message_box
def draw_message_box():
_view = get_view_by_name('message_box')
if not _is_view_dirty(_view):
return False
_set_view_clean(_view)
#blit_string(1, 0, 'Messages', 'message_box', fore_color=tcod.white)
_y_mod = 1
_lower = numbers.clip(0,len(MESSAGE_LOG)-MESSAGE_LOG_MAX_LINES,100000)
_i = -1
for msg in MESSAGE_LOG[_lower:len(MESSAGE_LOG)]:
if msg['count']:
_text = '%s (x%s)' % (msg['msg'], msg['count']+1)
else:
_text = msg['msg']
if msg['style'] == 'damage':
_fore_color = tcod.red
elif msg['style'] == 'speech':
_fore_color = tcod.gray
elif msg['style'] == 'action':
_fore_color = tcod.lighter_crimson
elif msg['style'] == 'important':
_fore_color = tcod.Color(150,150,255)
elif msg['style'] == 'radio':
_fore_color = tcod.Color(225,245,169)
elif msg['style'] == 'good':
_fore_color = tcod.light_green
elif msg['style'] == 'player_combat_good':
_fore_color = tcod.green
elif msg['style'] == 'player_combat_bad':
_fore_color = tcod.crimson
else:
_fore_color = tcod.white
_c = 9*((_i>0)+1)
_back_color = tcod.Color(_c, _c, _c)
_i = -_i
while _text:
_print_text = _text[:_view['draw_size'][0]-2]
_padding = ' '*numbers.clip(_view['draw_size'][0], 0, _view['draw_size'][0]-len(_print_text)-2)
blit_string(1, _y_mod, _print_text+_padding, 'message_box', fore_color=_fore_color, back_color=_back_color)
_y_mod += 1
_text = _text[_view['draw_size'][0]-2:]
if _y_mod > MESSAGE_LOG_MAX_LINES:
break
if not _text.startswith(' ') and _text:
_text = ' '+_text
if _y_mod > MESSAGE_LOG_MAX_LINES:
break
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:58,代码来源:graphics.py
示例8: draw_intro
def draw_intro():
_stime = time.time()
_title_time = time.time()
_warning_time = None
_warning_message = VERSION
_sub_mod = 0
_sub_time = 0
_shadow = 50
_burn = 8.0
_char_alpha = {c: random.uniform(.15, .7) for c in SUB_LINE}
#Why did I base this on time.time()?
while time.time()-_stime<=5:
_text = INTRO
if time.time()-_stime<=1:
_text = list(_text)
random.shuffle(_text)
_text = ''.join(_text)
else:
if not _sub_time:
_sub_time = time.time()
if 4.0>time.time()-_stime:
_burn *= 1.005
elif time.time()-_stime>=4.0 and _burn>255:
_burn = 255
_text = INTRO
_mod = int(round(255*numbers.clip(time.time()-_title_time, 0, 1)))
console_set_default_foreground(0, Color(_mod, _mod, _mod))
console_print(0, (WINDOW_SIZE[0]/2)-len(_text)/2, (WINDOW_SIZE[1]/2)-2, _text)
if time.time()-_stime>=1:
if not _warning_time:
_warning_time = time.time()
_mod = int(round(255*numbers.clip(time.time()-_warning_time, 0, 1)))
console_set_default_foreground(0, Color(_mod/2, _mod/2, _mod/2))
console_print(0, 0, WINDOW_SIZE[1]-1, _warning_message)
if time.time()-_stime>=1.2:
_i = 0
for c in SUB_LINE:
_c_mod = _char_alpha[c]
_mod = numbers.clip(time.time()-_warning_time, 0, 1)
console_set_default_foreground(0, Color(int(round((200*_mod)*_c_mod)), 0, 0))
console_print(0, _i+(WINDOW_SIZE[0]/2)-len(SUB_LINE)/2, (WINDOW_SIZE[1]/2), c)
_char_alpha[c] = numbers.clip(_char_alpha[c]*1.015, 0, 1)
_i += 1
console_flush()
SETTINGS['running'] = 1
开发者ID:athros,项目名称:Reactor-3,代码行数:57,代码来源:mainmenu.py
示例9: calculate_fire
def calculate_fire(fire):
_neighbor_intensity = 0
_neighbor_lit = False
for x in range(-1, 2):
_x = fire['pos'][0]+x
if _x<0 or _x>=MAP_SIZE[0]:
continue
for y in range(-1, 2):
if not x and not y:
continue
_y = fire['pos'][1]+y
if _y<0 or _y>=MAP_SIZE[1]:
continue
_effects = [EFFECTS[eid] for eid in EFFECT_MAP[_x][_y] if EFFECTS[eid]['type'] == 'fire']
for effect in _effects:
_neighbor_intensity += effect['intensity']
if 'light' in effect:
_neighbor_lit = True
if not _effects:
_tile = WORLD_INFO['map'][_x][_y][fire['pos'][2]]
_raw_tile = tiles.get_raw_tile(_tile)
_heat = tiles.get_flag(WORLD_INFO['map'][_x][_y][fire['pos'][2]], 'heat')
_current_burn = int(round(fire['intensity']))
_max_burn = int(round(_current_burn*.23))
if tiles.flag(_tile, 'heat', numbers.clip(_heat+(fire['intensity']*.01), 0, 8))>=_raw_tile['burnable']:
if _raw_tile['burnable'] and _max_burn:
create_fire((_x, _y, fire['pos'][2]), intensity=random.randint(1, numbers.clip(1+_max_burn, 2, 8)))
_intensity = ((64-_neighbor_intensity)/64.0)*random.uniform(0, SETTINGS['fire burn rate'])
fire['intensity'] -= _intensity
for life in [LIFE[life_id] for life_id in LIFE_MAP[fire['pos'][0]][fire['pos'][1]]]:
lfe.burn(life, fire['intensity'])
for item in items.get_items_at(fire['pos']):
items.burn(item, fire['intensity'])
update_effect(fire)
if fire['intensity'] <= 0.25:
unregister_effect(fire)
if 'light' in fire:
fire['light']['brightness'] -= numbers.clip(_intensity*.015, 0, 5)
elif not _neighbor_lit:
fire['light'] = create_light(fire['pos'], (255, 69, 0), 17*(fire['intensity']/8.0), 0.25)
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:56,代码来源:effects.py
示例10: move_camera
def move_camera(pos, scroll=False):
_orig_pos = CAMERA_POS[:]
CAMERA_POS[0] = numbers.clip(pos[0]-(WINDOW_SIZE[0]/2),0,MAP_SIZE[0]-WINDOW_SIZE[0])
CAMERA_POS[1] = numbers.clip(pos[1]-(WINDOW_SIZE[1]/2),0,MAP_SIZE[1]-WINDOW_SIZE[1])
CAMERA_POS[2] = pos[2]
if not _orig_pos == CAMERA_POS:
gfx.refresh_view('map')
elif SETTINGS['controlling'] and not alife.brain.get_flag(LIFE[SETTINGS['controlling']], 'redraw') == pos:
gfx.refresh_view('map')
开发者ID:athros,项目名称:Reactor-3,代码行数:10,代码来源:terraform.py
示例11: position_is_in_frame
def position_is_in_frame(pos):
_view = get_active_view()
if not _view:
return False
if pos[0] >= CAMERA_POS[0] and pos[0] < numbers.clip(CAMERA_POS[0]+_view['view_size'][0]-1, 0, MAP_SIZE[0]) and \
pos[1] >= CAMERA_POS[1] and pos[1] < numbers.clip(CAMERA_POS[1]+_view['view_size'][1]-1, 0, MAP_SIZE[1]):
return True
return False
开发者ID:athros,项目名称:Reactor-3,代码行数:11,代码来源:graphics.py
示例12: death
def death():
_player = LIFE[SETTINGS['controlling']]
maps.reset_lights()
FADE_TO_WHITE[0] += .5
_time_since_death = FADE_TO_WHITE[0]
_time_alive = round(numbers.clip((_player['time_of_death']-_player['created'])/float(WORLD_INFO['length_of_day']), 0.1, 9999), 2)
_string = 'You die.'
_sub_string = _player['cause_of_death']
_col = int(round(255*numbers.clip((_time_since_death/100.0)-random.uniform(0, 0.15), 0, 1)))
if _time_alive == 1:
_sub_sub_string = 'Lived 1 day'
else:
if _time_alive < 1:
_sub_sub_string = 'Lived less than a day'
else:
_sub_sub_string = 'Lived %0.1f days' % (_time_alive)
gfx.fade_to_black(1)
gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_string)/2,
MAP_WINDOW_SIZE[1]/2,
_string,
'map',
fore_color=tcod.Color(_col, 0, 0),
back_color=tcod.Color(0, 0, 0))
gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_sub_string)/2,
(MAP_WINDOW_SIZE[1]/2)+2,
_sub_string,
'map',
fore_color=tcod.Color(int(round(_col*.75)), int(round(_col*.75)), int(round(_col*.75))),
back_color=tcod.Color(0, 0, 0))
gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_sub_sub_string)/2,
(MAP_WINDOW_SIZE[1]/2)+4,
_sub_sub_string,
'map',
fore_color=tcod.Color(int(round(_col*.75)), int(round(_col*.75)), int(round(_col*.75))),
back_color=tcod.Color(0, 0, 0))
if _time_since_death>=350:
worldgen.save_world()
worldgen.reset_world()
gfx.clear_scene()
SETTINGS['running'] = 1
return False
return True
开发者ID:athros,项目名称:Reactor-3,代码行数:54,代码来源:reactor-3.py
示例13: is_confident
def is_confident(life):
if 'player' in life:
return False
_friendly_confidence = judgement.get_ranged_combat_rating_of_target(life, life['id'])
_threat_confidence = 0
for target_id in judgement.get_trusted(life, visible=False):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
if _knows['last_seen_time']>30:
if brain.get_alife_flag(life, target_id, 'threat_score'):
_recent_mod = 1-(numbers.clip(_knows['last_seen_time'], 0, 300)/300.0)
_score = brain.get_alife_flag(life, target_id, 'threat_score')
_friendly_confidence += _score*_recent_mod
else:
_friendly_confidence += 1
else:
_score = judgement.get_ranged_combat_rating_of_target(life, target_id)
brain.flag_alife(life, target_id, 'threat_score', value=_score)
_friendly_confidence += _score
for target_id in judgement.get_threats(life, ignore_escaped=False):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
if _knows['last_seen_time']:
if brain.get_alife_flag(life, target_id, 'threat_score'):
if _knows['last_seen_time']>50:
_recent_mod = 1-(numbers.clip(_knows['last_seen_time'], 0, 600)/600.0)
else:
_recent_mod = 1
_score = brain.get_alife_flag(life, target_id, 'threat_score')
_threat_confidence += _score*_recent_mod
else:
_threat_confidence += 1
else:
_score = judgement.get_ranged_combat_rating_of_target(life, target_id, inventory_check=False)
brain.flag_alife(life, target_id, 'threat_score', value=_score)
_threat_confidence += _score
return _friendly_confidence-_threat_confidence>=-2
开发者ID:athros,项目名称:Reactor-3,代码行数:52,代码来源:stats.py
示例14: get_vision
def get_vision(life):
if not 'CAN_SEE' in life['life_flags']:
return 0
if 'player' in life:
_fov_mod = 1
else:
_fov_mod = numbers.clip(1-(life['think_rate']/float(life['think_rate_max'])), 0.5, 1)
_world_light = tcod.white-weather.get_lighting()
_light_percentage = numbers.clip(((_world_light.r+_world_light.g+_world_light.b)*.30)/200.0, 0, 1)
return int(round((life['vision_max']*_light_percentage)*_fov_mod))
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:13,代码来源:sight.py
示例15: move_camera
def move_camera(pos, scroll=False):
_orig_pos = CAMERA_POS[:]
CAMERA_POS[0] = numbers.clip(pos[0] - (MAP_WINDOW_SIZE[0] / 2), 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0])
CAMERA_POS[1] = numbers.clip(pos[1] - (MAP_WINDOW_SIZE[1] / 2), 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1])
CAMERA_POS[2] = pos[2]
if not _orig_pos == CAMERA_POS:
gfx.refresh_view("map")
elif SETTINGS["controlling"] and not alife.brain.get_flag(LIFE[SETTINGS["controlling"]], "redraw") == pos:
gfx.refresh_view("map")
if SETTINGS["controlling"]:
alife.brain.flag(LIFE[SETTINGS["controlling"]], "redraw", value=pos[:])
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:13,代码来源:reactor-3.py
示例16: search_for_target
def search_for_target(life, target_id):
#TODO: Variable size instead of hardcoded
_know = brain.knows_alife_by_id(life, target_id)
_size = 30
if brain.alife_has_flag(life, target_id, 'search_map'):
_search_map = brain.get_alife_flag(life, target_id, 'search_map')
else:
_search_map = maps.create_search_map(life, _know['last_seen_at'], _size)
brain.flag_alife(life, target_id, 'search_map', value=_search_map)
lfe.stop(life)
lfe.walk_to(life, _know['last_seen_at'][:2])
if life['path'] or lfe.find_action(life, matches=[{'action': 'move'}]):
return False
_lowest = {'score': -1, 'pos': None}
_x_top_left = numbers.clip(_know['last_seen_at'][0]-(_size/2), 0, MAP_SIZE[0])
_y_top_left = numbers.clip(_know['last_seen_at'][1]-(_size/2), 0, MAP_SIZE[1])
for x in range(0, _size):
_x = _x_top_left+x
if _x >= MAP_SIZE[0]-1:
continue
for y in range(0, _size):
_y = _y_top_left+y
if _y >= MAP_SIZE[1]-1:
continue
if not _search_map[y, x]:
continue
if sight.can_see_position(life, (_x, _y)):
_search_map[y, x] = 0
if _search_map[y, x]>0 and (not _lowest['pos'] or _search_map[y, x] <= _lowest['score']):
_lowest['score'] = _search_map[y, x]
_lowest['pos'] = (_x, _y, x, y)
if _lowest['pos']:
x, y, _x, _y = _lowest['pos']
if travel_to_position(life, (x, y, _know['last_seen_at'][2]), stop_on_sight=True):
_search_map[_y, _x] = 0
else:
_know['escaped'] = 2
开发者ID:hovatterz,项目名称:Reactor-3,代码行数:50,代码来源:movement.py
示例17: handle_camera
def handle_camera(entity_id, min_zoom=3.5, max_zoom=14.5, max_enemy_distance=2400, center_distance=600.0):
if not entity_id in entities.ENTITIES:
display.CAMERA['zoom_speed'] = .005
display.CAMERA['next_zoom'] = 4.5
return False
if not clock.is_ticking():
return False
_player = entities.get_entity(entity_id)
_center_pos = _player['position'].copy()
_median_distance = []
if 'in_space' in _player and _player['in_space']:
_distance_to_center = numbers.distance(_player['position'], (worlds.get_size()[0]/2, worlds.get_size()[1]/2))
_min_zoom = 2.0
_max_zoom = max_zoom
display.CAMERA['next_zoom'] = numbers.clip(_max_zoom*((_distance_to_center/3000.0)-1), _min_zoom, _max_zoom)
elif _player['death_timer'] == -1:
for enemy_id in entities.get_sprite_groups(['enemies', 'hazards']):
_enemy = entities.get_entity(enemy_id)
if 'player' in _enemy:
continue
_dist = numbers.distance(_player['position'], _enemy['position'])
if _dist>=max_enemy_distance:
continue
_median_distance.append(_dist)
_center_pos = numbers.interp_velocity(_center_pos, _enemy['position'], 0.5)
if not _median_distance:
_median_distance = [0]
_distance_to_nearest_enemy = sum(_median_distance)/len(_median_distance)
_min_zoom = min_zoom
_max_zoom = max_zoom
display.CAMERA['next_zoom'] = numbers.clip(_max_zoom*(_distance_to_nearest_enemy/float(center_distance)), _min_zoom, _max_zoom)
else:
display.CAMERA['zoom_speed'] = .05
display.CAMERA['next_zoom'] = 1.5
if display.CAMERA['next_zoom'] < 5:
display.CAMERA['next_center_on'] = _center_pos
else:
display.CAMERA['next_center_on'] = _player['position'].copy()
开发者ID:witheld9,项目名称:vector-kill,代码行数:50,代码来源:player.py
示例18: hit_laser
def hit_laser(bullet, target_id):
for i in range(random.randint(2, 3)):
_effect = effects.create_particle(bullet['position'][0]+random.randint(-6, 6),
bullet['position'][1]+random.randint(-6, 6),
'explosion.png',
background=False,
scale=random.uniform(.4, .8),
flashes=random.randint(15, 25),
flash_chance=0.7)
_effect['velocity'] = numbers.interp_velocity(bullet['velocity'], entities.get_entity(target_id)['velocity'], .1)
_effect['velocity'][0] = numbers.clip(_effect['velocity'][0], -6, 6)
_effect['velocity'][1] = numbers.clip(_effect['velocity'][1], -6, 6)
entities.trigger_event(entities.get_entity(target_id), 'accelerate', velocity=numbers.interp_velocity(entities.get_entity(target_id)['velocity'], bullet['velocity'], .4))
开发者ID:witheld9,项目名称:vector-kill,代码行数:15,代码来源:bullet.py
示例19: reload_slices
def reload_slices():
for _slice in WORLD_INFO['slices'].values():
#logging.debug('Loading slice: %s' % _slice['id'])
_size = [_slice['bot_right'][0]-_slice['top_left'][0], _slice['bot_right'][1]-_slice['top_left'][1]]
_size[0] = numbers.clip(_size[0], 1, MAP_SIZE[0])
_size[1] = numbers.clip(_size[1], 1, MAP_SIZE[1])
_slice['_map'] = zones.create_map_array(size=_size)
for pos in _slice['map']:
_xx = _slice['top_left'][0]+1
_yy = _slice['top_left'][1]+1
_slice['_map'][pos[0]-_xx][pos[1]-_yy] = 1
开发者ID:athros,项目名称:Reactor-3,代码行数:15,代码来源:maps.py
示例20: loop
def loop():
_remove_labels = []
for label in LABELS.values():
if time.time()-label.time_created > label.show_for and not label.show_for == -1:
if label.color[3]>0:
label.color = (label.color[0], label.color[1], label.color[2], numbers.clip(label.color[3]-label.fade_out_speed, 0, 255))
else:
_remove_labels.append(label)
else:
if label.color[3] < 255:
label.color = (label.color[0], label.color[1], label.color[2], numbers.clip(label.color[3]+label.fade_in_speed, 0, 255))
for label in _remove_labels:
del LABELS[label._id]
开发者ID:witheld9,项目名称:vector-kill,代码行数:15,代码来源:display.py
注:本文中的numbers.clip函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论