/**
   * Set up all of the data.
   *
   * <p>This is called from a separate init method in order to limit the amount of resource loading
   * that is done by the thread that called the startApp method.
   */
  public void init() throws Exception {
    // TODO: [Exercise 3][step 1] - initialization code. Please, don't forget to fix the missing
    // imports and fields
    mazeDesign = new MazeGameDesign(); // [Exercise3]
    jamesSprite = mazeDesign.getJamesS(); // [Exercise3]
    dukeSprite = mazeDesign.getDukeS(); // [Exercise3]
    dukeSprite.defineReferencePixel(dukeSprite.getWidth() / 2, 0); // [Exercise3]
    dukeSpriteAnimator = new SpriteAnimationTask(dukeSprite, false); // [Exercise3]
    myWalls = mazeDesign.getMaze1(); // [Exercise3]
    mazeDesign.updateLayerManagerForLevel1(this); // [Exercise3]

    timer = new Timer(); // [Exercise3]
    timer.scheduleAtFixedRate(dukeSpriteAnimator, 0, mazeDesign.dukeSseq001Delay); // [Exercise3]
    // this sets the view screen so that the player is
    // in the center.
    myViewWindowX = dukeSprite.getX() - ((DISP_HEIGHT - SQUARE_WIDTH) / 2);
    myViewWindowY = dukeSprite.getY() - ((DISP_HEIGHT - SQUARE_WIDTH) / 2);

    System.gc();
  }
示例#2
0
 public boolean collidesWith(Sprite s, boolean pixelLevel) {
   java.awt.Rectangle r1 =
       new java.awt.Rectangle(this.getX(), this.getY(), getWidth(), getHeight());
   java.awt.Rectangle r2 = new java.awt.Rectangle(s.getX(), s.getY(), s.getWidth(), s.getHeight());
   return r1.intersects(r2);
 }