Ejemplo n.º 1
0
 @Override
 public void mouseDragged(MouseEvent e) {
   WormSprite sprite = getScreen().getSelectedWormSprite();
   if (sprite != null) {
     double[] wormXY = sprite.getCenterLocation();
     double currentOrientation = sprite.getOrientation();
     this.angle =
         Math.PI - currentOrientation + Math.atan2((e.getY() - wormXY[1]), (wormXY[0] - e.getX()));
   }
 }
Ejemplo n.º 2
0
 @Override
 protected void doUpdate(double dt) {
   WormSprite sprite = getScreen().getWormSprite(getWorm());
   try {
     if (getElapsedTime() >= jumpDuration) {
       if (!hasJumped) {
         hasJumped = true;
         getFacade().jump(getWorm(), GUIConstants.JUMP_TIME_STEP);
         if (getFacade().isAlive(getWorm())) {
           double x = getFacade().getX(getWorm());
           double y = getFacade().getY(getWorm());
           sprite.setCenterLocation(getScreen().getScreenX(x), getScreen().getScreenY(y));
         }
         finished = true;
       }
     } else {
       double[] xy = getFacade().getJumpStep(getWorm(), getElapsedTime());
       sprite.setCenterLocation(getScreen().getScreenX(xy[0]), getScreen().getScreenY(xy[1]));
     }
   } catch (ModelException e) {
     e.printStackTrace();
     afterExecutionCancelled();
   }
 }