Exemplo n.º 1
0
  public boolean wallCollision(Bullet bullet) {
    Rectangle boundingBox = bullet.getBoundingBox();
    int tile;
    int tileWidth = tileMap.getTileWidth();
    int tileHeight = tileMap.getTileHeight();

    /*
     * nested four loop only is grabbing the 4 corners of the
     * bullet's hit box and checking the type of tiles that they
     * contact. The current bullets range from 8x8 to 17x17, so they
     * all can contact the same range of tiles at any given time:
     * 1-4 A bullet expires on contact with a solid object(besides
     * ring bullets)
     */

    for (int y = bullet.yPos;
        y <= bullet.yPos + boundingBox.getHeight();
        y += boundingBox.getHeight()) {
      for (int x = bullet.xPos;
          x <= bullet.xPos + boundingBox.getWidth();
          x += boundingBox.getWidth()) {
        int tileCoordX = (int) (x + distanceScrolled) / tileWidth;
        int tileCoordY = y / tileHeight;

        tile = tileMap.getTile(((tileCoordY) * tileMap.getTileMapWidth()) + (tileCoordX));
        if (tile < 17 || 23 < tile) {
          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 2
0
  /** @param canvas */
  private void drawTiles(Canvas canvas) {
    mPaint.setShadowLayer(0, 0, 0, 0);

    if (null != mTiles) {

      for (int tilen = 0; tilen < mTiles.getTilesNum(); tilen++) {

        BitmapHolder tile = mTiles.getTile(tilen);

        /*
         * Scale, then move under the plane which is at center
         */
        boolean nochart = false;
        if (null == tile) {
          nochart = true;
        } else if (null == tile.getBitmap()) {
          nochart = true;
        }
        if (nochart) {
          continue;
        }

        /*
         * Pretty straightforward. Pan and draw individual tiles.
         */
        tile.getTransform().setScale(mScale.getScaleFactor(), mScale.getScaleCorrected());
        tile.getTransform()
            .postTranslate(
                getWidth() / 2.f
                    - BitmapHolder.WIDTH / 2.f * mScale.getScaleFactor()
                    + ((tilen % mTiles.getXTilesNum()) * BitmapHolder.WIDTH
                            - BitmapHolder.WIDTH * (int) (mTiles.getXTilesNum() / 2))
                        * mScale.getScaleFactor()
                    + mPan.getMoveX() * mScale.getScaleFactor()
                    + mPan.getTileMoveX() * BitmapHolder.WIDTH * mScale.getScaleFactor()
                    - (float) mMovement.getOffsetLongitude() * mScale.getScaleFactor(),
                getHeight() / 2.f
                    - BitmapHolder.HEIGHT / 2.f * mScale.getScaleCorrected()
                    + mPan.getMoveY() * mScale.getScaleCorrected()
                    + ((tilen / mTiles.getXTilesNum()) * BitmapHolder.HEIGHT
                            - BitmapHolder.HEIGHT * (int) (mTiles.getYTilesNum() / 2))
                        * mScale.getScaleCorrected()
                    + mPan.getTileMoveY() * BitmapHolder.HEIGHT * mScale.getScaleCorrected()
                    - (float) mMovement.getOffsetLatitude() * mScale.getScaleCorrected());

        Bitmap b = tile.getBitmap();
        if (null != b) {
          canvas.drawBitmap(b, tile.getTransform(), mPaint);
        }
      }
    }
  }