def handle_keyboard_input(): if controls.get_input_char_pressed('\t'): if settings.TICK_MODE == 'strategy': if ui_panel.ACTIVE_MENU: ui_panel.close() else: ui_panel.show_inventory(entity) else: _x, _y = movement.get_position(entity) camera.set_pos(_x - constants.MAP_VIEW_WIDTH / 2, _y - constants.MAP_VIEW_HEIGHT / 2) if controls.get_input_char_pressed('O'): settings.toggle_show_node_grid() elif controls.get_input_char_pressed('o'): settings.toggle_observer_mode() if controls.get_input_char_pressed('d'): _mx, _my = ui_cursor.get_map_position() for entity_id in entities.get_entity_group('life'): _entity = entities.get_entity(entity_id) if not numbers.distance( (_mx, _my), movement.get_position(_entity)): _x, _y = ui_cursor.get_screen_position() _menu = ui_menu.create(_x, _y, title='Debug') ui_menu.add_selectable(_menu, 'Show Metas', lambda: _show_metas(_entity)) ui_menu.add_selectable( _menu, 'Kill', lambda: entities.trigger_event(_entity, 'kill')) ui_menu.add_selectable(_menu, 'Overwatch', lambda: ai_debugger.register(_entity)) break if controls.get_input_char_pressed('l'): _x, _y = ui_cursor.get_screen_position() _mx, _my = ui_cursor.get_map_position() _weight = zones.get_active_weight_map()[_my, _mx] _menu = ui_menu.create(_x, _y, title='Tile Info') ui_menu.add_selectable( _menu, 'Warp', lambda: entities.trigger_event( entity, 'set_position', x=_mx, y=_my)) ui_menu.add_selectable( _menu, 'Light', lambda: effects.light(_mx, _my, 15, r=random.uniform(1.0, 1.5), g=random.uniform(1.0, 1.5), light_map='static_lighting')) ui_menu.add_selectable(_menu, 'Weight: %s' % _weight, lambda: _)
def _bullet_effects(entity, x, y): _distance = numbers.distance((x, y), entity['start_position']) _target_distance = numbers.distance((x, y), entity['end_position']) + numbers.clip(10 - _distance, 0, 10) _x, _y = movement.get_position(entity) _mod = (0.6 - (_distance / 35.0)) + random.uniform(-.1, .1) _alpha = numbers.clip(_mod, 0, 1) _crash_dist = 60 - (entity['speed'] * 2) if _alpha > 0: effects.vapor(x, y, start_alpha=_alpha) if _target_distance < 30: _size = int(round(2 * (1 - (1 * numbers.clip(numbers.clip(_target_distance, 0, 100)/60.0, 0, 1))))) + random.randint(1, 2) if _distance > _crash_dist: _size = int(round(_size * (_crash_dist/float(_distance)))) if _size > 1: effects.light(_x, _y, _size, r=1.3, g=1.3, b=1.3)
def _shoot_weapon(entity, weapon_id, target_id): _weapon = entities.get_entity(weapon_id) _x, _y = movement.get_position( entities.get_entity(_weapon['stats']['owner'])) if not target_id in entities.ENTITIES: logging.warning('Target deleted during shooting.') return _tx, _ty = movement.get_position(entities.get_entity(target_id)) _direction = numbers.direction_to((_x, _y), (_tx, _ty)) effects.muzzle_flash(_x, _y, _direction) entities.trigger_event(_weapon, 'flag_sub', flag='ammo', value=1) entities.trigger_event(entity, 'create_noise', volume=80, direction=numbers.direction_to((_x, _y), (_tx, _ty)), text='BAM', callback=lambda t, x, y: entities.trigger_event( t, 'update_target_memory', target_id=entity['_id'], key='last_seen_at', value=[x, y]), context_callback=lambda x, y: ui_dialog.create( x, y, 'Gunshot (Unknown)', title='Noise')) entity['stats']['action_points'] -= stats.get_shoot_cost(entity, weapon_id) entities.trigger_event(entity, 'get_accuracy') _accuracy = stats.get_accuracy(entity, weapon_id) _damage = flags.get_flag(_weapon, 'damage') effects.light(_x, _y, random.randint(3, 5), r=1.5, g=1.5, b=0) if _weapon['stats']['kind'] == 'explosive': items.explosive(entity, _x, _y, _tx, _ty, 4, _accuracy, _damage) else: items.bullet(entity, _x, _y, _tx, _ty, 1, _accuracy, _damage)
def _shoot_weapon(entity, weapon_id, target_id): _weapon = entities.get_entity(weapon_id) _x, _y = movement.get_position(entities.get_entity(_weapon['stats']['owner'])) if not target_id in entities.ENTITIES: logging.warning('Target deleted during shooting.') return _tx, _ty = movement.get_position(entities.get_entity(target_id)) _direction = numbers.direction_to((_x, _y), (_tx, _ty)) effects.muzzle_flash(_x, _y, _direction) entities.trigger_event(_weapon, 'flag_sub', flag='ammo', value=1) entities.trigger_event(entity, 'create_noise', volume=80, direction=numbers.direction_to((_x, _y), (_tx, _ty)), text='BAM', callback=lambda t, x, y: entities.trigger_event(t, 'update_target_memory', target_id=entity['_id'], key='last_seen_at', value=[x, y]), context_callback=lambda x, y: ui_dialog.create(x, y, 'Gunshot (Unknown)', title='Noise')) entity['stats']['action_points'] -= stats.get_shoot_cost(entity, weapon_id) entities.trigger_event(entity, 'get_accuracy') _accuracy = stats.get_accuracy(entity, weapon_id) _damage = flags.get_flag(_weapon, 'damage') effects.light(_x, _y, random.randint(3, 5), r=1.5, g=1.5, b=0) if _weapon['stats']['kind'] == 'explosive': items.explosive(entity, _x, _y, _tx, _ty, 4, _accuracy, _damage) else: items.bullet(entity, _x, _y, _tx, _ty, 1, _accuracy, _damage)
def _bullet_effects(entity, x, y): _distance = numbers.distance((x, y), entity['start_position']) _target_distance = numbers.distance( (x, y), entity['end_position']) + numbers.clip(10 - _distance, 0, 10) _x, _y = movement.get_position(entity) _mod = (0.6 - (_distance / 35.0)) + random.uniform(-.1, .1) _alpha = numbers.clip(_mod, 0, 1) _crash_dist = 60 - (entity['speed'] * 2) if _alpha > 0: effects.vapor(x, y, start_alpha=_alpha) if _target_distance < 30: _size = int( round(2 * (1 - (1 * numbers.clip( numbers.clip(_target_distance, 0, 100) / 60.0, 0, 1)))) ) + random.randint(1, 2) if _distance > _crash_dist: _size = int(round(_size * (_crash_dist / float(_distance)))) if _size > 1: effects.light(_x, _y, _size, r=1.3, g=1.3, b=1.3)
def bullet(entity, x, y, tx, ty, speed, accuracy, damage): _entity = _create(x, y, 'Bullet', '.', 0, 'bullet') _entity['owner'] = entity['_id'] _entity['start_position'] = (x, y) _entity['end_position'] = (tx, ty) _entity['speed'] = speed _entity['damage'] = damage entities.add_entity_to_group(_entity, 'bullets') timers.register(_entity) entities.trigger_event(_entity, 'set_direction', direction=numbers.direction_to( (x, y), (tx, ty)) + random.uniform(-accuracy, accuracy)) entities.trigger_event(_entity, 'create_timer', time=speed, repeat=-1, enter_callback=_bullet_tick, repeat_callback=_bullet_tick) entities.register_event(_entity, 'position_changed', lambda e, **kwargs: check_for_collisions(e)) entities.register_event( _entity, 'collision_with_entity', lambda e, target_id: entities. trigger_event(entities.get_entity(target_id), 'hit', projectile=e)) entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.delete_entity(e)) entities.register_event( _entity, 'collision_with_solid', lambda e: effects.light( movement.get_position(e)[0], movement.get_position(e)[1], random.randint(3, 4))) entities.register_event(_entity, 'collision_with_solid', lambda e: entities.delete_entity(e)) entities.register_event( _entity, 'collision_with_solid', lambda e: effects.smoke_cloud(movement.get_position(e)[0], movement.get_position(e)[1], random.uniform(2, 2.75), start_alpha=random.uniform(0.45, .65), decay_amount=1.5)) entities.register_event(_entity, 'check_next_position', check_next_position) if not '--no-fx' in sys.argv: entities.register_event( _entity, 'position_changed', lambda e, x, y, **kwargs: _bullet_effects(e, x, y))
def handle_keyboard_input(): if controls.get_input_char_pressed('\t'): if settings.TICK_MODE == 'strategy': if ui_panel.ACTIVE_MENU: ui_panel.close() else: ui_panel.show_inventory(entity) else: _x, _y = movement.get_position(entity) camera.set_pos(_x - constants.MAP_VIEW_WIDTH/2, _y - constants.MAP_VIEW_HEIGHT/2) if controls.get_input_char_pressed('O'): settings.toggle_show_node_grid() elif controls.get_input_char_pressed('o'): settings.toggle_observer_mode() if controls.get_input_char_pressed('d'): _mx, _my = ui_cursor.get_map_position() for entity_id in entities.get_entity_group('life'): _entity = entities.get_entity(entity_id) if not numbers.distance((_mx, _my), movement.get_position(_entity)): _x, _y = ui_cursor.get_screen_position() _menu = ui_menu.create(_x, _y, title='Debug') ui_menu.add_selectable(_menu, 'Show Metas', lambda: _show_metas(_entity)) ui_menu.add_selectable(_menu, 'Kill', lambda: entities.trigger_event(_entity, 'kill')) ui_menu.add_selectable(_menu, 'Overwatch', lambda: ai_debugger.register(_entity)) break if controls.get_input_char_pressed('l'): _x, _y = ui_cursor.get_screen_position() _mx, _my = ui_cursor.get_map_position() _weight = zones.get_active_weight_map()[_my, _mx] _menu = ui_menu.create(_x, _y, title='Tile Info') ui_menu.add_selectable(_menu, 'Warp', lambda: entities.trigger_event(entity, 'set_position', x=_mx, y=_my)) ui_menu.add_selectable(_menu, 'Light', lambda: effects.light(_mx, _my, 15, r=random.uniform(1.0, 1.5), g=random.uniform(1.0, 1.5), light_map='static_lighting')) ui_menu.add_selectable(_menu, 'Weight: %s' % _weight, lambda: _)
def bullet(entity, x, y, tx, ty, speed, accuracy, damage): _entity = _create(x, y, 'Bullet', '.', 0, 'bullet') _entity['owner'] = entity['_id'] _entity['start_position'] = (x, y) _entity['end_position'] = (tx, ty) _entity['speed'] = speed _entity['damage'] = damage entities.add_entity_to_group(_entity, 'bullets') timers.register(_entity) entities.trigger_event(_entity, 'set_direction', direction=numbers.direction_to((x, y), (tx, ty))+random.uniform(-accuracy, accuracy)) entities.trigger_event(_entity, 'create_timer', time=speed, repeat=-1, enter_callback=_bullet_tick, repeat_callback=_bullet_tick) entities.register_event(_entity, 'position_changed', lambda e, **kwargs: check_for_collisions(e)) entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.trigger_event(entities.get_entity(target_id), 'hit', projectile=e)) entities.register_event(_entity, 'collision_with_entity', lambda e, target_id: entities.delete_entity(e)) entities.register_event(_entity, 'collision_with_solid', lambda e: effects.light(movement.get_position(e)[0], movement.get_position(e)[1], random.randint(3, 4))) entities.register_event(_entity, 'collision_with_solid', lambda e: entities.delete_entity(e)) entities.register_event(_entity, 'collision_with_solid', lambda e: effects.smoke_cloud(movement.get_position(e)[0], movement.get_position(e)[1], random.uniform(2, 2.75), start_alpha=random.uniform(0.45, .65), decay_amount=1.5)) entities.register_event(_entity, 'check_next_position', check_next_position) if not '--no-fx' in sys.argv: entities.register_event(_entity, 'position_changed', lambda e, x, y, **kwargs: _bullet_effects(e, x, y))
def activate(zone_id): global ACTIVE_ZONE ACTIVE_ZONE = zone_id _zone = ZONES[zone_id] _noise = tcod.noise_new(2) logging.info('Bringing zone \'%s\' online...' % _zone['name']) _zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'], _zone['solids']) _zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'], _zone['solids']) display.create_surface('tiles', width=_zone['width'], height=_zone['height']) maps.render_map(_zone['tile_map'], _zone['width'], _zone['height']) post_processing.start() events.register_event('logic', post_processing.tick_sun) _static_lighting = display.create_shader(_zone['width'], _zone['height'], start_offset=1) _zone['shaders'].append( post_processing.generate_shadow_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'], _zone['inside'])) _zone['shaders'].append( post_processing.generate_light_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'])) _zone['light_maps']['static_lighting'] = _static_lighting _zone['shaders'].append(_static_lighting) _noise = tcod.noise_new(3) _zoom = 2.0 _zone['fader'] = display.create_shader(_zone['width'], _zone['height']) _shader = display.create_shader(_zone['width'], _zone['height']) for y in range(0, _zone['height']): for x in range(0, _zone['width']): if (x, y) in _zone['inside']: _height = .75 else: _noise_values = [(_zoom * x / _zone['width']), (_zoom * y / _zone['height'])] _height = .35 + numbers.clip( tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX), .35, 1) _shader[0][y, x] = 1.3 * _height _shader[1][y, x] = 1.3 * _height _shader[2][y, x] = 1.1 * _height _zone['shaders'].append(_shader) for light in _zone['lights']: effects.light(light[0], light[1], light[2], r=light[3], g=light[4], b=light[5], light_map='static_lighting') #if not '--no-fx' in sys.argv: # post_processing.run(time=8, # repeat=-1, # repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH, # constants.MAP_VIEW_HEIGHT, # 8, # _noise, # _zone['inside'])) post_processing.run( time=0, repeat=-1, repeat_callback=lambda _: post_processing.post_process_lights()) #post_processing.run(time=0, # repeat=-1, # repeat_callback=lambda _: post_processing.sunlight()) camera.set_limits(0, 0, _zone['width'] - constants.MAP_VIEW_WIDTH, _zone['height'] - constants.MAP_VIEW_HEIGHT) logging.info('Zone \'%s\' is online' % _zone['name'])
def activate(zone_id): global ACTIVE_ZONE ACTIVE_ZONE = zone_id _zone = ZONES[zone_id] _noise = tcod.noise_new(2) logging.info('Bringing zone \'%s\' online...' % _zone['name']) _zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'], _zone['solids']) _zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'], _zone['solids']) display.create_surface('tiles', width=_zone['width'], height=_zone['height']) maps.render_map(_zone['tile_map'], _zone['width'], _zone['height']) post_processing.start() events.register_event('logic', post_processing.tick_sun) _static_lighting = display.create_shader(_zone['width'], _zone['height'], start_offset=1) _zone['shaders'].append(post_processing.generate_shadow_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'], _zone['inside'])) _zone['shaders'].append(post_processing.generate_light_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'])) _zone['light_maps']['static_lighting'] = _static_lighting _zone['shaders'].append(_static_lighting) _noise = tcod.noise_new(3) _zoom = 2.0 _zone['fader'] = display.create_shader(_zone['width'], _zone['height']) _shader = display.create_shader(_zone['width'], _zone['height']) for y in range(0, _zone['height']): for x in range(0, _zone['width']): if (x, y) in _zone['inside']: _height = .75 else: _noise_values = [(_zoom * x / _zone['width']), (_zoom * y / _zone['height'])] _height = .35 + numbers.clip(tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX), .35, 1) _shader[0][y, x] = 1.3 * _height _shader[1][y, x] = 1.3 * _height _shader[2][y, x] = 1.1 * _height _zone['shaders'].append(_shader) for light in _zone['lights']: effects.light(light[0], light[1], light[2], r=light[3], g=light[4], b=light[5], light_map='static_lighting') #if not '--no-fx' in sys.argv: # post_processing.run(time=8, # repeat=-1, # repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH, # constants.MAP_VIEW_HEIGHT, # 8, # _noise, # _zone['inside'])) post_processing.run(time=0, repeat=-1, repeat_callback=lambda _: post_processing.post_process_lights()) #post_processing.run(time=0, # repeat=-1, # repeat_callback=lambda _: post_processing.sunlight()) camera.set_limits(0, 0, _zone['width']-constants.MAP_VIEW_WIDTH, _zone['height']-constants.MAP_VIEW_HEIGHT) logging.info('Zone \'%s\' is online' % _zone['name'])