private static void start() { CollisionEffect.kill(); level.reset(); double xSpeed = CalcHelp.gaussianDouble(3.5, 1); double ySpeed = CalcHelp.randomDouble(-1, 1); level.getBall().setVelocity(new Vector2d(xSpeed, ySpeed)); level.getBall().setLaunched(true); }
@Override public void paintComponent(Graphics gr) { super.paintComponent(gr); Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); if (level != null) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } level.updateLevel(); double xS = level.getScreenXShift(); double yS = level.getScreenYShift(); if (level.timeToReset() && !CollisionEffect.started()) { CollisionEffect.start(level); } if (CollisionEffect.running()) { int[] vals = CollisionEffect.update(); xS = vals[0]; yS = vals[1]; } else { CollisionEffect.kill(); } level.draw((int) xS, (int) yS, g); if (CollisionEffect.running()) { CollisionEffect.draw(g); } else if (!CollisionEffect.running() && level.timeToReset()) { level.reset(); } else { level.getBall().draw(xS, yS, g); } repaint(); } }