def commands(): global MAP if controls.key_pressed('s'): maps.save_map('test', MAP) elif controls.key_pressed('l'): MAP = maps.load_map('test')
def handle_input(entity_id): if not entity_id in entities.ENTITIES or not 'player' in entities.ENTITIES[entity_id]: if controls.key_pressed(' '): battlefield.clean() battlefield.create_player() battlefield.spawn_enemies() return False if not clock.is_ticking() and controls.key_pressed(' '): clock.hang_for(0) _entity = entities.get_entity(entity_id) _move_speed = _entity['speed'] if controls.key_held('s'): #entities.trigger_event(_entity, 'accelerate', velocity=[0, _move_speed]) entities.trigger_event(_entity, 'set_direction', direction=270) entities.trigger_event(_entity, 'thrust') if controls.key_held('a'): #entities.trigger_event(_entity, 'accelerate', velocity=[-_move_speed, 0]) entities.trigger_event(_entity, 'set_direction', direction=180) entities.trigger_event(_entity, 'thrust') if controls.key_held('d'): #entities.trigger_event(_entity, 'accelerate', velocity=[_move_speed, 0]) entities.trigger_event(_entity, 'set_direction', direction=0) entities.trigger_event(_entity, 'thrust') if controls.key_held('w'): #entities.trigger_event(_entity, 'accelerate', velocity=[0, -_move_speed]) entities.trigger_event(_entity, 'set_direction', direction=90) entities.trigger_event(_entity, 'thrust') if controls.key_pressed('q'): entities.trigger_event(_entity, 'create_timer', time=120, enter_callback=lambda entity: entities.trigger_event(_entity, 'set_maximum_velocity', velocity=[80, 80]) and entities.trigger_event(_entity, 'set_speed', speed=80), exit_callback=lambda entity: entities.trigger_event(_entity, 'set_maximum_velocity', velocity=[30, 30])) if controls.key_pressed('v'): for entity_id in entities.get_sprite_groups(['hazards', 'enemies']): entities.delete_entity_via_id(entity_id) if controls.key_held_ord(controls.NUM_1): entities.trigger_event(_entity, 'shoot', direction=225) if controls.key_held_ord(controls.NUM_2): entities.trigger_event(_entity, 'shoot', direction=270) if controls.key_held_ord(controls.NUM_3): entities.trigger_event(_entity, 'shoot', direction=315) if controls.key_held_ord(controls.NUM_4): entities.trigger_event(_entity, 'shoot', direction=180) if controls.key_held_ord(controls.NUM_6): entities.trigger_event(_entity, 'shoot', direction=0) if controls.key_held_ord(controls.NUM_7): entities.trigger_event(_entity, 'shoot', direction=135) if controls.key_held_ord(controls.NUM_8): entities.trigger_event(_entity, 'shoot', direction=90) if controls.key_held_ord(controls.NUM_9): entities.trigger_event(_entity, 'shoot', direction=45) if controls.key_held_ord(controls.NUM_5): entities.trigger_event(_entity, 'shoot_alt') if controls.key_held('x'): battlefield.clean()