@Override public synchronized void update(double time) { xCtrl.update(time); yCtrl.update(time); directionCtrl.update(time); textManager.update(time); }
public synchronized void draw(Canvas canvas) { Transformation2D parent = canvas.getTransformation(); Transformation2D t = g2d.translate(xCtrl.getCurrent() * 100.0, yCtrl.getCurrent() * 100.0); Transformation2D r = g2d.rotate(directionCtrl.getCurrent() * Math.PI * -0.5, g2d.newPoint2D(50, 50)); Transformation2D pt = g2d.combine(parent, t); Transformation2D ptr = g2d.combine(pt, r); canvas.setTransformation(ptr); antDrawer.drawAnt(canvas, antInfo); canvas.setTransformation(pt); textManager.draw(canvas); canvas.setTransformation(parent); }
private synchronized void doMove() { switch (antInfo.getDirection()) { case 0: case 2: { yCtrl.setGoal((double) antInfo.getLocation().getY()); yCtrl.setDuration(moveDuration); waitFor(yCtrl); break; } case 1: case 3: { xCtrl.setGoal((double) antInfo.getLocation().getX()); xCtrl.setDuration(moveDuration); waitFor(xCtrl); break; } } }
public GraphicsAnt( GraphicsAntWarsGUI factory, IAntInfo antInfo, IAntDrawer antDrawer, G2D g2d, ColorFactory cf) { this.factory = factory; this.textManager = new VisualManagerImpl<>(true); this.antInfo = antInfo; this.antDrawer = antDrawer; this.g2d = g2d; this.cf = cf; DoubleInterpolator di = new DoubleInterpolator(); xCtrl = new LinearChaserImpl<>(di, 1.0); yCtrl = new LinearChaserImpl<>(di, 1.0); directionCtrl = new LinearChaserImpl<>(new DoubleCircularInterpolation(4), 0.25); xCtrl.setCurrent((double) antInfo.getLocation().getX()); yCtrl.setCurrent((double) antInfo.getLocation().getY()); directionCtrl.setCurrent((double) antInfo.getDirection()); xCtrl.setGoal((double) antInfo.getLocation().getX()); yCtrl.setGoal((double) antInfo.getLocation().getY()); directionCtrl.setGoal((double) antInfo.getDirection()); }
private synchronized void shake() { directionCtrl.setGoal(antInfo.getDirection() + 0.1); directionCtrl.setDuration(turnDuration * 0.1); waitFor(directionCtrl); if (antInfo.getDirection() > 0) { directionCtrl.setGoal(antInfo.getDirection() - 0.1); } else { directionCtrl.setGoal(3.9); } directionCtrl.setDuration(turnDuration * 0.1); waitFor(directionCtrl); directionCtrl.setGoal((double) antInfo.getDirection()); directionCtrl.setDuration(turnDuration * 0.1); waitFor(directionCtrl); }
private synchronized void doTurn() { directionCtrl.setGoal((double) antInfo.getDirection()); directionCtrl.setDuration(turnDuration); waitFor(directionCtrl); }
@Override public synchronized void playAttackAnimation(int damage) { switch (antInfo.getDirection()) { case 0: { yCtrl.setGoal((double) antInfo.getLocation().getY() + 0.5f); yCtrl.setDuration(attackDuration); waitFor(yCtrl); yCtrl.setGoal((double) antInfo.getLocation().getY()); yCtrl.setDuration(attackDuration); waitFor(yCtrl); break; } case 1: { xCtrl.setGoal((double) antInfo.getLocation().getX() + 0.5f); xCtrl.setDuration(attackDuration); waitFor(xCtrl); xCtrl.setGoal((double) antInfo.getLocation().getX()); xCtrl.setDuration(attackDuration); waitFor(xCtrl); break; } case 2: { yCtrl.setGoal((double) antInfo.getLocation().getY() - 0.5f); yCtrl.setDuration(attackDuration); waitFor(yCtrl); yCtrl.setGoal((double) antInfo.getLocation().getY()); yCtrl.setDuration(attackDuration); waitFor(yCtrl); break; } case 3: xCtrl.setGoal((double) antInfo.getLocation().getX() - 0.5f); xCtrl.setDuration(attackDuration); waitFor(xCtrl); xCtrl.setGoal((double) antInfo.getLocation().getX()); xCtrl.setDuration(attackDuration); waitFor(xCtrl); break; } }