コード例 #1
0
  /**
   * Main update code (We don't want any allocations happening anywhere in the main loop).
   *
   * @param delta The amount of time that has passed since the previous update
   */
  public void update(float delta) {
    float[] paddleCenterY = {mTouchLocs[0].y, mTouchLocs[1].y};

    if (!mPaused) {
      mGameLogic.update(delta, paddleCenterY);
      mGameLogic.updateBallSprite(mBall);
      mGameLogic.updatePaddleSprites(mPaddles);
    } else if (mStartNextRound) {
      mGameLogic.initRound();
      mPaused = false;
      mStartNextRound = false;
    }
  }
コード例 #2
0
  /** called by the game logic when a point scored */
  public boolean pointScored(int winner, int hits) {
    if (mPongListener != null) {
      if (mPongListener.pointScored(winner, hits)) {
        mPaused = true;
        return true;
      }
    }

    mGameLogic.initRound();
    return false;
  }
コード例 #3
0
  /**
   * Load game assets and initialize
   *
   * @param gl openGL context reference
   */
  public void loadAssets(GL10 gl) {
    GLGfx.initGfx(40);

    // Get the density for banner size calcs.
    DisplayMetrics metrics = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mDensity = metrics.density;

    // initialize the only texture
    try {
      AssetManager assetMgr = mActivity.getAssets();
      mTex = Texture.createTextureFromStream((GL11) gl, true, assetMgr.open("assets_tex.png"));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // setup the sprites
    mPaddles = new Sprite[2];
    mPaddles[0] = new Sprite9Patch(PADDLE_TEXRECT, PADDLE_SIZE);
    mPaddles[1] = new Sprite9Patch(PADDLE_TEXRECT, PADDLE_SIZE);
    mBall = new Sprite(BALL_TEXRECT);
    mBack = new Sprite(BACK_TEXRECT);

    // position the background image so it is centered in the game area drawn at it's native size if
    // it fits
    // if it doesn't fit scale it so it draws as large as possible
    float gameAreaHeight = getHeight() - BANNER_HEIGHT * mDensity;
    float scale = (BACK_SIZE.y > gameAreaHeight) ? (gameAreaHeight / BACK_SIZE.y) : 1.0f;
    float bgX = (getWidth() - (scale * BACK_SIZE.x)) / 2.0f;
    float bgY = (BANNER_HEIGHT * mDensity) + (gameAreaHeight - (scale * BACK_SIZE.y)) / 2.0f;

    mBack.setPosAndSize(bgX, bgY, scale * BACK_SIZE.x, scale * BACK_SIZE.y);

    // Initialize the game
    mGameLogic.setupRect(new RectF(0.0f, BANNER_HEIGHT * mDensity, getWidth(), getHeight()));
    mGameLogic.initRound();
  }