def explode(): global exploding, expl_time if not exploding: exploding = True expl_time = time.time() for p in system.part[p_bubbles]: dv = p.pos - p_head.pos lv = np.linalg.norm(dv) if lv < expl_range: p.v = dv / lv / lv * expl_force # KEYBOARD CONTROLS visualizer.keyboardManager.register_button( KeyboardButtonEvent('i', KeyboardFireEvent.Pressed, move_up_set)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('k', KeyboardFireEvent.Pressed, move_down_set)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('i', KeyboardFireEvent.Released, move_updown_reset)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('k', KeyboardFireEvent.Released, move_updown_reset)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('j', KeyboardFireEvent.Pressed, move_left_set)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('l', KeyboardFireEvent.Pressed, move_right_set)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('j', KeyboardFireEvent.Released, move_leftright_reset)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('l', KeyboardFireEvent.Released, move_leftright_reset))
if self.stopped: self.impulse += 0.5 self.update_cueball_force() def fire(self): if self.stopped: self.stopped = False system.part[0].v = system.part[0].v + system.part[0].ext_force system.part[0].fix = [False, True, False] system.part[0].ext_force = [0, 0, 0] pool = Billiards() visualizer.keyboard_manager.register_button( KeyboardButtonEvent('4', KeyboardFireEvent.Hold, pool.decreaseAngle)) visualizer.keyboard_manager.register_button( KeyboardButtonEvent('6', KeyboardFireEvent.Hold, pool.increaseAngle)) visualizer.keyboard_manager.register_button( KeyboardButtonEvent('2', KeyboardFireEvent.Hold, pool.decreaseImpulse)) visualizer.keyboard_manager.register_button( KeyboardButtonEvent('8', KeyboardFireEvent.Hold, pool.increaseImpulse)) visualizer.keyboard_manager.register_button( KeyboardButtonEvent('5', KeyboardFireEvent.Pressed, pool.fire)) def main(): system.time_step = 0.00008 system.cell_system.skin = 0.4