コード例 #1
0
  /** Draws the tank, bullets, planes, and background to the provided Canvas. */
  private void doDraw(Canvas canvas) {

    // draw some background

    canvas.drawBitmap(mBackgroundImage, 0, 0, null);
    /*	Paint mPaint = new Paint();
     	mPaint.setColor(0xFF94B0FF);
     	canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mPaint);
    */
    // draw the aircrafts

    for (Iterator it = aircrafts.iterator(); it.hasNext(); ) {
      FunctionalAircraft a = (FunctionalAircraft) it.next();
      if (a != null) a.draw(canvas);
    }

    // draw the bullets

    for (Iterator it = bullets.iterator(); it.hasNext(); ) {
      FunctionalBullet b = (FunctionalBullet) it.next();
      if (b != null) b.draw(canvas);
    }

    // Draw the tank
    tank.draw(canvas);

    // Hud draw
    hud.draw(canvas);
  }
コード例 #2
0
  /**
   * Figures the lander state (x, y, fuel, ...) based on the passage of realtime. Does not
   * invalidate(). Called at the start of draw(). Detects the end-of-game and sets the UI to the
   * next state.
   */
  private void updatePhysics(long timer) {
    timer = (long) (timer); // adjust the overall speed
    //	Log.i("update", "fisicacaaa");

    tank.update(timer);

    FunctionalBullet b;
    int i = 0;
    while (!bullets.isEmpty() && bullets.size() > i) {
      b = bullets.get(i);
      if (b.isOver()) bullets.remove(i);
      else {
        b.update(timer);
        i++;
      }
    }

    FunctionalAircraft a;
    i = 0;
    while (!aircrafts.isEmpty() && aircrafts.size() > i) {
      a = aircrafts.get(i);
      if (a.isOver()) aircrafts.remove(i);
      else {
        a.update(timer);
        ////
        int j = 0;
        while (j < bullets.size()) {
          b = bullets.get(j);
          if (a.isFlying() && b.isFlying())
            if (a.impactDetected(b)) {
              hud.addImpact();
              a.setImpact();
              b.setImpact();
              aircrafts.add(new FunctionalAircraft());

              // Vibrate for 300 milliseconds
              vibrator.vibrate(100);
            }
          j++;
        }
        i++;
      }
    }
    newaircraftimer += timer;
    if (newaircraftimer > 3000) {
      aircrafts.add(new FunctionalAircraft());
      newaircraftimer = 0;
    }
    // hud.update(timer);

  }