def draw_dialog(dialog_id): _dialog = get_dialog(dialog_id) _last_message = get_last_message(dialog_id) _x = numbers.clip(MAP_WINDOW_SIZE[0]/2-len(_last_message['text'])/2, 3, 100) _y = 10 _line_of_sight = drawing.diag_line(LIFE[_dialog['started_by']]['pos'], LIFE[_dialog['target']]['pos']) locks.unlock('camera_free') if len(_line_of_sight)<=1: _center_pos = LIFE[_dialog['started_by']]['pos'] else: _center_pos = list(_line_of_sight[len(_line_of_sight)/2]) _center_pos.append(2) if SETTINGS['controlling'] == _dialog['started_by']: _target = _dialog['target'] else: _target = _dialog['started_by'] _target_portrait = lfe.draw_life_icon(LIFE[_target]) _lines = [] gfx.camera_track(_center_pos) gfx.blit_string(_x-2, _y-2, ' '.join(LIFE[_target]['name']), 'overlay', fore_color=_target_portrait[1]) gfx.blit_string(_x-2, _y, _target_portrait[0], 'overlay', fore_color=_target_portrait[1])#, back_color=tcod.darkest_gray) _text = _last_message['text'] _y_mod = 0 while _text: _x = MAP_WINDOW_SIZE[0]/2-len(_text[:MAP_WINDOW_SIZE[0]-4])/2 gfx.blit_string(_x, _y+_y_mod, _text[:MAP_WINDOW_SIZE[0]-4], 'overlay') _text = _text[MAP_WINDOW_SIZE[0]-4:] _y_mod += 1 for choice in _dialog['choices']: _text = choice['text'][choice['text'].index('\"')+1:choice['text'].index('\"')-1] if not _text.startswith('>'): _text = '> '+_text _n_x = MAP_WINDOW_SIZE[0]/2-len(_text)/2 if _n_x < _x: _x = _n_x for choice in _dialog['choices']: _text = choice['text'][choice['text'].index('\"')+1:choice['text'].index('\"')-1] if _dialog['cursor_index'] == _dialog['choices'].index(choice): _text = '> '+_text _lines.append(_text) for line in _lines: gfx.blit_string(_x, _y+3, line, 'overlay')#, back_color=tcod.darkest_gray) _y += 2
def draw_targeting(): if SETTINGS['following'] and not SETTINGS['controlling'] == SETTINGS['following'] and LIFE[SETTINGS['following']]['path']: SELECTED_TILES[0] = [(p[0], p[1], 2) for p in LIFE[SETTINGS['following']]['path']] if LIFE[SETTINGS['controlling']] and LIFE[SETTINGS['controlling']]['targeting']: SELECTED_TILES[0] = [] for pos in drawing.diag_line(LIFE[SETTINGS['controlling']]['pos'],LIFE[SETTINGS['controlling']]['targeting']): SELECTED_TILES[0].append((pos[0],pos[1],LIFE[SETTINGS['controlling']]['pos'][2]))
def draw_targeting(): if ( SETTINGS["following"] and not SETTINGS["controlling"] == SETTINGS["following"] and LIFE[SETTINGS["following"]]["path"] ): SELECTED_TILES[0] = [(p[0], p[1], 2) for p in LIFE[SETTINGS["following"]]["path"]] if LIFE[SETTINGS["controlling"]] and LIFE[SETTINGS["controlling"]]["targeting"]: SELECTED_TILES[0] = [] for pos in drawing.diag_line(LIFE[SETTINGS["controlling"]]["pos"], LIFE[SETTINGS["controlling"]]["targeting"]): SELECTED_TILES[0].append((pos[0], pos[1], LIFE[SETTINGS["controlling"]]["pos"][2]))
def draw_targeting(): if SETTINGS['following'] and not SETTINGS['controlling'] == SETTINGS[ 'following'] and LIFE[SETTINGS['following']]['path']: SELECTED_TILES[0] = [(p[0], p[1], 2) for p in LIFE[SETTINGS['following']]['path']] if LIFE[SETTINGS['controlling']] and LIFE[ SETTINGS['controlling']]['targeting']: SELECTED_TILES[0] = [] for pos in drawing.diag_line( LIFE[SETTINGS['controlling']]['pos'], LIFE[SETTINGS['controlling']]['targeting']): SELECTED_TILES[0].append( (pos[0], pos[1], LIFE[SETTINGS['controlling']]['pos'][2]))
def tick_item(item): _z_max = bad_numbers.clip(item['pos'][2], 0, MAP_SIZE[2]-1) if item['type'] == 'bullet': _gravity = 0 else: _gravity = item['gravity'] if not is_moving(item): return False _x = item['pos'][0] _y = item['pos'][1] _break = False item['realpos'][0] += item['velocity'][0] item['realpos'][1] += item['velocity'][1] _line = drawing.diag_line(item['pos'], (int(round(item['realpos'][0])),int(round(item['realpos'][1])))) #Refresh even if we're not moving far enough to switch tiles if gfx.position_is_in_frame((_x, _y)): gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map') if not _line: item['velocity'][2] -= _gravity item['realpos'][2] = item['realpos'][2]+item['velocity'][2] item['pos'][2] = int(round(item['realpos'][2])) if maps.is_oob(item['pos']): delete_item(item) return False _z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2]-1) collision_with_solid(item, [int(round(item['realpos'][0])), int(round(item['realpos'][1])), _z_min]) for pos in _line: item['realpos'][2] += item['velocity'][2] if _gravity: item['velocity'][2] -= item['velocity'][2]*_gravity if 'drag' in item: _drag = item['drag'] else: _drag = item['gravity'] logging.warning('Improper use of gravity.') _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item) if abs(item['velocity'][0])<=1: item['velocity'][0] = 0.0 if abs(item['velocity'][1])<=1: item['velocity'][1] = 0.0 if not is_moving(item): if item['type'] == 'bullet': delete_item(item) return False item['velocity'][0] -= bad_numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel) item['velocity'][1] -= bad_numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel) item['speed'] -= bad_numbers.clip(item['speed']*_drag, 0, 100) if maps.is_oob((pos[0], pos[1], int(round(item['realpos'][2])))) or maps.is_oob(item['realpos']): delete_item(item) return False #TODO: Don't just stop the object collision_with_solid(item, (pos[0], pos[1], int(round(item['realpos'][2])))) tick_effects(item) #TODO: Don't do this here... maybe a callback or something if item['type'] == 'bullet': for _life in [LIFE[i] for i in LIFE]: if not _life['online']: continue if _life['id'] == item['shot_by'] or _life['dead']: continue if _life['pos'][0] == pos[0] and _life['pos'][1] == pos[1] and _life['pos'][2] == int(round(item['realpos'][2])): remove_from_chunk(item) item['pos'] = [pos[0],pos[1],_life['pos'][2]] add_to_chunk(item) life.damage_from_item(_life, item) if item['uid'] in ITEMS: delete_item(item) return False #if _break: # break #_z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2]-1) #if collision_with_solid(item, [pos[0], pos[1], _z_min]): # #_break = True # break #create_effects(item, pos, item['realpos'][2], _z_min) remove_from_chunk(item) if _break: item['pos'][0] = int(pos[0]) item['pos'][1] = int(pos[1]) item['pos'][2] = int(round(item['realpos'][2])) else: item['pos'][0] = int(round(item['realpos'][0])) item['pos'][1] = int(round(item['realpos'][1])) item['pos'][2] = int(round(item['realpos'][2])) add_to_chunk(item) _x = item['pos'][0] _y = item['pos'][1] if gfx.position_is_in_frame((_x, _y)): gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map') if maps.is_oob(item['pos']): delete_item(item) return False _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item) if abs(item['velocity'][0])<.35: item['velocity'][0] = 0.0 if abs(item['velocity'][1])<.35: item['velocity'][1] = 0.0 #TODO: This isn't gravity... if 'drag' in item: _drag = item['drag'] else: _drag = item['gravity'] logging.warning('Improper use of gravity.') item['velocity'][0] -= bad_numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel) item['velocity'][1] -= bad_numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel) item['speed'] -= bad_numbers.clip(item['speed']*_drag, 0, 100)
def tick_item(item): if 'CAN_BURN' in item['flags'] and item['burning'] and item['owner']: life.burn(LIFE[item['owner']], item['burning']) if 'stored_in' in item or is_item_owned(item['uid']): return False _z_max = numbers.clip(item['pos'][2], 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1) if item['velocity'][:2] == [0.0, 0.0] and WORLD_INFO['map'][item['pos'][0]][item['pos'][1]][_z_max]: return False _x = item['pos'][0] _y = item['pos'][1] #_view = gfx.get_view_by_name('map') #if 0<=_x<_view['draw_size'][0] and 0<=_y<_view['draw_size'][1]: if gfx.position_is_in_frame((_x, _y)): gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map') item['realpos'][0] += item['velocity'][0] item['realpos'][1] += item['velocity'][1] _break = False _line = drawing.diag_line(item['pos'],(int(round(item['realpos'][0])),int(round(item['realpos'][1])))) if not _line: item['velocity'][2] -= item['gravity'] item['realpos'][2] = item['realpos'][2]+item['velocity'][2] item['pos'][2] = int(round(item['realpos'][2])) if item['pos'][0]<0 or item['pos'][0]>=MAP_SIZE[0] or item['pos'][1]<0 or item['pos'][1]>=MAP_SIZE[1]: delete_item(item) return False _z_min = numbers.clip(int(round(item['realpos'][2])), 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1) if collision_with_solid(item, [item['pos'][0], item['pos'][1], _z_min]): pos = item['pos'][:] _break = True create_effects(item, item['pos'], item['realpos'][2], _z_min) for pos in _line: item['realpos'][2] += item['velocity'][2] item['velocity'][2] -= item['velocity'][2]*item['gravity'] if 'drag' in item: _drag = item['drag'] else: _drag = item['gravity'] logging.warning('Improper use of gravity.') _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item) if 0<item['velocity'][0]<0.1 or -.1<item['velocity'][0]<0: item['velocity'][0] = 0 if 0<item['velocity'][1]<0.1 or -.1<item['velocity'][1]<0: item['velocity'][1] = 0 item['velocity'][0] -= numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel) item['velocity'][1] -= numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel) item['speed'] -= numbers.clip(item['speed']*_drag, 0, 100) if 0>pos[0] or pos[0]>=MAP_SIZE[0] or 0>pos[1] or pos[1]>=MAP_SIZE[1] or item['realpos'][2]<0 or item['realpos'][2]>=MAP_SIZE[2]-1: logging.warning('Item OOM: %s', item['uid']) delete_item(item) return False if collision_with_solid(item, [pos[0], pos[1], int(round(item['realpos'][2]))]): if item['type'] == 'bullet': effects.create_light(item['pos'], (255, 0, 0), 9, 0, fade=0.1) logging.debug('Item #%s hit a wall.' % item['uid']) return False if item['type'] == 'bullet': for _life in [LIFE[i] for i in LIFE]: if _life['id'] == item['shot_by'] or _life['dead']: continue if _life['pos'][0] == pos[0] and _life['pos'][1] == pos[1] and _life['pos'][2] == int(round(item['realpos'][2])): remove_from_chunk(item) item['pos'] = [pos[0],pos[1],_life['pos'][2]] add_to_chunk(item) life.damage_from_item(_life,item,60) if item['uid'] in ITEMS: delete_item(item) return False if _break: break #_z_max = numbers.clip(int(round(item['realpos'][2]))+1, 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1) #if MAP[pos[0]][pos[1]][_z_max]: # item['velocity'][0] = 0 # item['velocity'][1] = 0 # item['velocity'][2] = 0 # item['pos'] = [pos[0],pos[1],item['pos'][2]-1] # # print 'LANDED',item['pos'] # _break = True # break _z_min = numbers.clip(int(round(item['realpos'][2])), 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1) if collision_with_solid(item, [pos[0], pos[1], _z_min]): _break = True break create_effects(item, pos, item['realpos'][2], _z_min) remove_from_chunk(item) if _break: item['pos'][0] = int(pos[0]) item['pos'][1] = int(pos[1]) item['pos'][2] = int(round(item['realpos'][2])) else: item['pos'][0] = int(round(item['realpos'][0])) item['pos'][1] = int(round(item['realpos'][1])) item['pos'][2] = int(round(item['realpos'][2])) add_to_chunk(item) _x = item['pos'][0] _y = item['pos'][1] if gfx.position_is_in_frame((_x, _y)): gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map') if item['pos'][0] < 0 or item['pos'][0] > MAP_SIZE[0] \ or item['pos'][1] < 0 or item['pos'][1] > MAP_SIZE[1]: delete_item(item) return False #elif _break: # maps.refresh_chunk(life.get_current_chunk_id(item)) _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item) if 0<item['velocity'][0]<0.1 or -.1<item['velocity'][0]<0: item['velocity'][0] = 0 if 0<item['velocity'][1]<0.1 or -.1<item['velocity'][1]<0: item['velocity'][1] = 0 #TODO: This isn't gravity... if 'drag' in item: _drag = item['drag'] else: _drag = item['gravity'] logging.warning('Improper use of gravity.') item['velocity'][0] -= numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel) item['velocity'][1] -= numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel) item['speed'] -= numbers.clip(item['speed']*_drag, 0, 100)
def draw_dialog(dialog_id): _dialog = get_dialog(dialog_id) _last_message = get_last_message(dialog_id) _x = bad_numbers.clip( MAP_WINDOW_SIZE[0] / 2 - len(_last_message['text']) / 2, 3, 100) _y = 10 _line_of_sight = drawing.diag_line(LIFE[_dialog['started_by']]['pos'], LIFE[_dialog['target']]['pos']) locks.unlock('camera_free') if len(_line_of_sight) <= 1: _center_pos = LIFE[_dialog['started_by']]['pos'] else: _center_pos = list(_line_of_sight[len(_line_of_sight) / 2]) _center_pos.append(2) if SETTINGS['controlling'] == _dialog['started_by']: _target = _dialog['target'] else: _target = _dialog['started_by'] _target_portrait = lfe.draw_life_icon(LIFE[_target]) _lines = [] gfx.camera_track(_center_pos) gfx.blit_string(_x - 2, _y - 2, ' '.join(LIFE[_target]['name']), 'overlay', fore_color=_target_portrait[1]) gfx.blit_string( _x - 2, _y, _target_portrait[0], 'overlay', fore_color=_target_portrait[1]) #, back_color=tcod.darkest_gray) _text = _last_message['text'] _y_mod = 0 while _text: _x = MAP_WINDOW_SIZE[0] / 2 - len(_text[:MAP_WINDOW_SIZE[0] - 4]) / 2 gfx.blit_string(_x, _y + _y_mod, _text[:MAP_WINDOW_SIZE[0] - 4], 'overlay') _text = _text[MAP_WINDOW_SIZE[0] - 4:] _y_mod += 1 for choice in _dialog['choices']: _text = choice['text'][choice['text'].index('\"') + 1:choice['text'].index('\"') - 1] if not _text.startswith('>'): _text = '> ' + _text _n_x = MAP_WINDOW_SIZE[0] / 2 - len(_text) / 2 if _n_x < _x: _x = _n_x for choice in _dialog['choices']: _text = choice['text'][choice['text'].index('\"') + 1:choice['text'].index('\"') - 1] if _dialog['cursor_index'] == _dialog['choices'].index(choice): _text = '> ' + _text _lines.append(_text) for line in _lines: gfx.blit_string(_x, _y + 3, line, 'overlay') #, back_color=tcod.darkest_gray) _y += 2
def tick_item(item): _z_max = bad_numbers.clip(item['pos'][2], 0, MAP_SIZE[2] - 1) if item['type'] == 'bullet': _gravity = 0 else: _gravity = item['gravity'] if not is_moving(item): return False _x = item['pos'][0] _y = item['pos'][1] _break = False item['realpos'][0] += item['velocity'][0] item['realpos'][1] += item['velocity'][1] _line = drawing.diag_line( item['pos'], (int(round(item['realpos'][0])), int(round(item['realpos'][1])))) #Refresh even if we're not moving far enough to switch tiles if gfx.position_is_in_frame((_x, _y)): gfx.refresh_view_position(_x - CAMERA_POS[0], _y - CAMERA_POS[1], 'map') if not _line: item['velocity'][2] -= _gravity item['realpos'][2] = item['realpos'][2] + item['velocity'][2] item['pos'][2] = int(round(item['realpos'][2])) if maps.is_oob(item['pos']): delete_item(item) return False _z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2] - 1) collision_with_solid(item, [ int(round(item['realpos'][0])), int(round(item['realpos'][1])), _z_min ]) for pos in _line: item['realpos'][2] += item['velocity'][2] if _gravity: item['velocity'][2] -= item['velocity'][2] * _gravity if 'drag' in item: _drag = item['drag'] else: _drag = item['gravity'] logging.warning('Improper use of gravity.') _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity( item) if abs(item['velocity'][0]) <= 1: item['velocity'][0] = 0.0 if abs(item['velocity'][1]) <= 1: item['velocity'][1] = 0.0 if not is_moving(item): if item['type'] == 'bullet': delete_item(item) return False item['velocity'][0] -= bad_numbers.clip(item['velocity'][0] * _drag, _min_x_vel, _max_x_vel) item['velocity'][1] -= bad_numbers.clip(item['velocity'][1] * _drag, _min_y_vel, _max_y_vel) item['speed'] -= bad_numbers.clip(item['speed'] * _drag, 0, 100) if maps.is_oob((pos[0], pos[1], int(round( item['realpos'][2])))) or maps.is_oob(item['realpos']): delete_item(item) return False #TODO: Don't just stop the object collision_with_solid(item, (pos[0], pos[1], int(round(item['realpos'][2])))) tick_effects(item) #TODO: Don't do this here... maybe a callback or something if item['type'] == 'bullet': for _life in [LIFE[i] for i in LIFE]: if not _life['online']: continue if _life['id'] == item['shot_by'] or _life['dead']: continue if _life['pos'][0] == pos[0] and _life['pos'][ 1] == pos[1] and _life['pos'][2] == int( round(item['realpos'][2])): remove_from_chunk(item) item['pos'] = [pos[0], pos[1], _life['pos'][2]] add_to_chunk(item) life.damage_from_item(_life, item) if item['uid'] in ITEMS: delete_item(item) return False #if _break: # break #_z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2]-1) #if collision_with_solid(item, [pos[0], pos[1], _z_min]): # #_break = True # break #create_effects(item, pos, item['realpos'][2], _z_min) remove_from_chunk(item) if _break: item['pos'][0] = int(pos[0]) item['pos'][1] = int(pos[1]) item['pos'][2] = int(round(item['realpos'][2])) else: item['pos'][0] = int(round(item['realpos'][0])) item['pos'][1] = int(round(item['realpos'][1])) item['pos'][2] = int(round(item['realpos'][2])) add_to_chunk(item) _x = item['pos'][0] _y = item['pos'][1] if gfx.position_is_in_frame((_x, _y)): gfx.refresh_view_position(_x - CAMERA_POS[0], _y - CAMERA_POS[1], 'map') if maps.is_oob(item['pos']): delete_item(item) return False _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item) if abs(item['velocity'][0]) < .35: item['velocity'][0] = 0.0 if abs(item['velocity'][1]) < .35: item['velocity'][1] = 0.0 #TODO: This isn't gravity... if 'drag' in item: _drag = item['drag'] else: _drag = item['gravity'] logging.warning('Improper use of gravity.') item['velocity'][0] -= bad_numbers.clip(item['velocity'][0] * _drag, _min_x_vel, _max_x_vel) item['velocity'][1] -= bad_numbers.clip(item['velocity'][1] * _drag, _min_y_vel, _max_y_vel) item['speed'] -= bad_numbers.clip(item['speed'] * _drag, 0, 100)