collision = WalkerCollisionComponent(dispatcher, owner=cop_entity) passing = PassingComponent(dispatcher, shadow_pos=(0, 15), shadow_size=(13, 3), owner=cop_entity) dispatcher.add_event( BearEvent(event_type='ecs_create', event_value=cop_entity)) dispatcher.add_event( BearEvent(event_type='ecs_add', event_value=('cop', x, y))) t = BearTerminal(font_path='bear_hug/demo_assets/cp437_12x12.png', size='85x60', title='Brutality', filter=['keyboard', 'mouse']) dispatcher = BearEventDispatcher() loop = BearLoop(t, dispatcher) dispatcher.register_listener(ClosingListener(), ['misc_input', 'tick']) dispatcher.register_listener(EntityTracker(), ['ecs_create', 'ecs_destroy']) atlas = Atlas(XpLoader('bear_hug/demo_assets/test_atlas.xp'), 'bear_hug/demo_assets/test_atlas.json') chars = [['.' for x in range(44)] for y in range(49)] colors = copy_shape(chars, 'gray') layout = ECSLayout(chars, colors) dispatcher.register_listener(layout, 'all') create_cop(atlas, dispatcher, 5, 5) create_barrel(atlas, dispatcher, 20, 20) # Dev monitor, works outside ECS monitor = DevMonitor(*atlas.get_element('dev_bg'), dispatcher=dispatcher) dispatcher.register_listener(monitor, ['tick', 'service'])
def event_dispatcher(): l = BearEventDispatcher() yield l
import sys from entities import * from listeners import * ################################################################################ # bear_hug boilerplate ################################################################################ # Launching the terminal. All kwargs are bearlibterminal terminal settings terminal = BearTerminal(font_path='cp437_12x12.png', size='91x60', title='AsciiCity', filter=['keyboard', 'mouse']) # Setting up the event loop dispatcher = BearEventDispatcher() loop = BearLoop(terminal, dispatcher) ################################################################################ # Listeners ################################################################################ # This is used to process window closing dispatcher.register_listener(ClosingListener(), ['misc_input', 'tick']) # If not subscribed, EntityTracker won't update its entity list correctly dispatcher.register_listener(EntityTracker(), ['ecs_create', 'ecs_destroy']) # Sound system jukebox = SoundListener({'shot': 'shot.wav', 'explosion': 'explosion.wav'}) # https://freesound.org/people/EMSIarma/sounds/108852/ # https://freesound.org/people/FlashTrauma/sounds/398283/ dispatcher.register_listener(jukebox, 'play_sound')
def close_game(): global building global attractor global attractor2 global emitter global score global dispatcher global t global figures global initial_figure figures = None initial_figure = None dispatcher.unregister_listener(building, 'all') dispatcher.unregister_listener(attractor, 'all') dispatcher.unregister_listener(attractor2, 'all') dispatcher.unregister_listener(emitter.fig, 'all') dispatcher.unregister_listener(emitter, 'all') dispatcher.unregister_listener(score, 'all') t.remove_widget(building) t.remove_widget(attractor2) t.remove_widget(attractor) t.remove_widget(emitter.fig) t.remove_widget(emitter) t.remove_widget(score) dispatcher = BearEventDispatcher() dispatcher.register_event_type('request_destruction') dispatcher.register_event_type('request_installation') dispatcher.register_event_type('h7') dispatcher.register_event_type('v7') dispatcher.register_event_type('square') dispatcher.register_event_type('game_lost') # This is a patent black magic, but it solves some very # weird bug with restarting loop.queue = dispatcher dispatcher.register_listener(loop, 'service') dispatcher.register_listener(r, 'service') dispatcher.register_listener(score, ['h7', 'v7', 'square']) dispatcher.register_listener(restart, 'key_down') dispatcher.register_listener(losing, 'game_lost') dispatcher.register_listener(ClosingListener(), ['misc_input', 'tick']) losing.clean()
loop.queue = dispatcher dispatcher.register_listener(loop, 'service') dispatcher.register_listener(r, 'service') dispatcher.register_listener(score, ['h7', 'v7', 'square']) dispatcher.register_listener(restart, 'key_down') dispatcher.register_listener(losing, 'game_lost') dispatcher.register_listener(ClosingListener(), ['misc_input', 'tick']) losing.clean() # Standart BLT boilerplate t = BearTerminal(font_path='cp437_12x12.png', size='60x50', title='Indirectris', filter=['keyboard', 'mouse']) dispatcher = BearEventDispatcher() dispatcher.register_event_type('request_destruction') dispatcher.register_event_type('request_installation') dispatcher.register_event_type('h7') dispatcher.register_event_type('v7') dispatcher.register_event_type('square') dispatcher.register_event_type('game_lost') loop = BearLoop(t, dispatcher) closing = ClosingListener() dispatcher.register_listener(closing, ['misc_input', 'tick']) # Game objects # Init here so that the same objects can be reused (and safely created and # destroyed) between multiple games atlas = Atlas(XpLoader('indirectris.xp'), 'indirectris.json') field = None
""" def __init__(self, chars, colors, dispatcher): super().__init__(chars, colors) counter = FPSCounter() dispatcher.register_listener(counter, 'tick') self.add_child(counter, (2, 4)) # Have to remember mouser for terminal setter self.mouser = MousePosWidget() dispatcher.register_listener(self.mouser, ['tick', 'misc_input']) self.add_child(self.mouser, (2, 7)) t = BearTerminal(size='50x45', title='Test window', filter=['keyboard', 'mouse']) dispatcher = BearEventDispatcher() loop = BearLoop(t, dispatcher) dispatcher.register_listener(ClosingListener(), ['misc_input', 'tick']) # Fireworks box box = FireworkBox([['.' for x in range(38)] for x in range(10)], [['gray' for x in range(38)] for x in range(10)], dispatcher) dispatcher.register_listener(box, ['key_down', 'service']) # A tank, TXTLoader test loader = TxtLoader('bear_hug/demo_assets/tank.txt') tank1 = Widget(*loader.get_image_region(0, 0, 5, 6)) tank2 = Widget(*loader.get_image_region(6, 0, 5, 6)) # XPLoader tests # A tree without layer2 apples