Exemple #1
0
 /**
  * Update the state of the box panel with the animation set
  *
  * @param timesArray Array of times in set
  */
 private void updateBoxPanel(DateTime[] timesArray) {
   if (boxPanel != null) {
     boxPanel.setNumTimes(timesArray.length);
     if (anime != null) {
       boxPanel.setOnIndex(anime.getCurrent());
     }
     if (propertiesDialog != null) {
       propertiesDialog.boxPanel.applyProperties(this.boxPanel);
     }
   }
 }
Exemple #2
0
  /**
   * The animation changed. Handle the change.
   *
   * @param evt The event
   */
  private void handleAnimationPropertyChange(PropertyChangeEvent evt) {
    //        System.err.println ("Handlechange:" +evt.getPropertyName());
    if (evt.getPropertyName().equals(Animation.ANI_VALUE)) {
      debug("handleAnimationPropertyChange value :" + evt.getPropertyName());
      Real eventValue = (Real) evt.getNewValue();
      // if there's nothing to do, return;
      if ((eventValue == null) || eventValue.isMissing()) {
        return;
      }

      /** The Animation associated with this widget */
      DateTime time = null;
      try {
        time = new DateTime(eventValue);
      } catch (VisADException ve) {;
      }
      final DateTime theDateTime = time;
      final int theIndex = ((anime != null) ? anime.getCurrent() : -1);
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              boolean oldValue = ignoreTimesCbxEvents;
              try {
                ignoreTimesCbxEvents = true;
                //                        synchronized (timesCbxMutex) {
                xcnt++;

                timesCbx.setSelectedItem(theDateTime);
                //                        }
                if ((boxPanel != null) && (theIndex >= 0)) {
                  boxPanel.setOnIndex(theIndex);
                }
                timesCbx.repaint();
              } finally {
                ignoreTimesCbxEvents = oldValue;
              }
            }
          });
      shareValue();
    } else if (evt.getPropertyName().equals(Animation.ANI_SET)) {
      if (ignoreAnimationSetChange) {
        return;
      }
      updateIndicatorInner((Set) evt.getNewValue(), true);
    }
  }
Exemple #3
0
 /** Share the index of the animation step. */
 protected void shareIndex() {
   doShare(SHARE_INDEX, new Integer(anime.getCurrent()));
 }
Exemple #4
0
  public void update() {

    if (crush) {
      if (animation.getCurrent() == crushSprites.length - 1) {
        crush = false;
      }
    }

    if (crush) {
      if (leftCrush) {
        dx -= (moveSpeed + 0.3);
        if (dx < -(maxSpeed + 2.0)) dx = -(maxSpeed + 2.0);
      } else {
        if (rightCrush) {
          dx += moveSpeed + 0.3;
          if (dx > maxSpeed + 2.0) dx = maxSpeed + 2.0;
        } else {
          if (dx < 0) {
            dx += stopSpeed;
            if (dx > 0) dx = 0;
          }
          if (dx > 0) {
            dx -= stopSpeed;
            if (dx < 0) dx = 0;
          }
        }
      }
    }

    if (!crush && !blockMove && left) {
      dx -= moveSpeed;
      if (dx < -maxSpeed) dx = -maxSpeed;
    } else {
      if (!crush && !blockMove && right) {
        dx += moveSpeed;
        if (dx > maxSpeed) dx = maxSpeed;
      } else {
        if (dx < 0) {
          dx += stopSpeed;
          if (dx > 0) dx = 0;
        }
        if (dx > 0) {
          dx -= stopSpeed;
          if (dx < 0) dx = 0;
        }
      }
    }

    if (jumping) {
      sfx.get("jumping").play();

      falling = true;
      jumping = false;
      dy = startJumping;
      upCrush = false;
    }

    if (falling) {
      if (reverse) {
        if (gravity > 0) {
          gravity *= -1;
          startJumping *= -1;
        }

        dy += gravity;
        if (dy < -maxFallingSpeed) dy = -maxFallingSpeed;

      } else {
        if (gravity < 0) {
          gravity *= -1;
          startJumping *= -1;
        }

        dy += gravity;
        if (dy > maxFallingSpeed) dy = maxFallingSpeed;
      }
    } else {
      dy = 0;
    }

    curRow = mp.getRowMap((int) y);
    curCol = mp.getColMap((int) x);

    toX = x + dx;
    toY = y + dy;

    tempX = x;
    tempY = y;

    calculateCorners(x, toY);
    if (dy < 0) {
      if (reverse) {
        if (bottomLeft || bottomRight) {
          dy = 0;
          falling = false;
          tempY = curRow * mp.getMapSize() + height1 / 2;
        } else {
          tempY += dy;
        }
      } else {
        if (topLeft || topRight) {
          dy = 0;
          tempY = curRow * mp.getMapSize() + height1 / 2;
        } else {
          tempY += dy;
        }
      }
    }
    if (dy > 0) {
      if (reverse) {
        if (topLeft || topRight) {
          dy = 0;
          tempY = (curRow + 1) * mp.getMapSize() - height1 / 2;
        } else {
          tempY += dy;
        }
      } else {
        if (bottomLeft || bottomRight) {
          dy = 0;
          falling = false;
          tempY = (curRow + 1) * mp.getMapSize() - height1 / 2;
        } else {
          tempY += dy;
        }
      }
    }

    calculateCorners(toX, y);
    if (dx < 0) {
      if (topLeft || bottomLeft) {
        dx = 0;
        tempX = curCol * mp.getMapSize() + width1 / 2;
      } else {
        tempX += dx;
      }
    }
    if (dx > 0) {
      if (topRight || bottomRight) {
        dx = 0;
        tempX = (curCol + 1) * mp.getMapSize() - width1 / 2;
      } else {
        tempX += dx;
      }
    }

    if (!falling) {
      if (reverse) {
        calculateCorners(x, y - 1);
      } else {
        calculateCorners(x, y + 1);
      }

      if (!bottomRight && !bottomLeft) falling = true;
    }

    x = tempX;
    y = tempY;

    if (!blockMove) {
      mp.setX((int) (GamePanel.WIDTH / 2 - x));
      mp.setY((int) (GamePanel.HEIGHT / 2 - y));
    }

    if (crush) {
      animation.setFrame(crushSprites);
      animation.setDelay(400);
      animation.setSpeed(10);
    } else {
      if (left || right) {
        animation.setFrame(walkSprites);
        animation.setDelay(100);
        animation.setSpeed(15);
      } else {
        if (telekinesTo || telekinesFrom) {
          animation.setFrame(telekinesSprites);
          animation.setDelay(400);
          animation.setSpeed(8);
        } else {
          animation.setFrame(idSprites);
          animation.setDelay(400);
          animation.setSpeed(5);
        }
      }
    }

    if (dy < 0) {
      if (!reverse) {
        animation.setFrame(jumpSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      } else {
        animation.setFrame(fallSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      }
    }
    if (dy > 0) {
      if (reverse) {
        animation.setFrame(jumpSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      } else {
        animation.setFrame(fallSprites);
        animation.setDelay(100);
        animation.setSpeed(10);
      }
    }

    animation.update();

    if (left) {
      factingRight = false;
    } else {
      if (right) {
        factingRight = true;
      }
    }
  }