コード例 #1
0
ファイル: MapController.java プロジェクト: neosam/ld30game
  public void applyPhysics(World world) {
    final Iterator<MapLayer> layerIterator = tiledMap.getLayers().iterator();
    while (layerIterator.hasNext()) {
      final MapLayer mapLayer = layerIterator.next();
      if (mapLayer instanceof TiledMapTileLayer) {
        final TiledMapTileLayer tiledLayer = (TiledMapTileLayer) mapLayer;
        final int width = tiledLayer.getWidth();
        final int height = tiledLayer.getHeight();
        for (int y = 0; y < height; y++) {
          for (int x = 0; x < width; x++) {
            final TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y);
            if (cell == null) {
              continue;
            }
            final boolean dirt = cell.getTile().getProperties().containsKey("dirt");
            final boolean noWall = cell.getTile().getProperties().containsKey("nowall");
            if (!noWall) {
              addBody(world, x + offset.x, y + offset.y, dirt);
            }
          }
        }
      }
    }

    for (String portalName : portals.keySet()) {
      final Vector2 portalPosition = portals.get(portalName);
      addPortalBody(world, portalName, portalPosition);
    }

    final Vector2 finish = getTriggerPoint("finish");
    if (finish != null) {
      addFinish(world, finish);
    }
  }
コード例 #2
0
ファイル: Turret.java プロジェクト: Aeo-Informatik/Bomberman
  public void explodeLeft() {
    // Explode LEFT
    for (int x = 1; x <= explosionRange; x++) {
      // If explosion hits block
      if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()))) {
        // Set ending texture and break out of loop
        TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
        cellDown.setTile(new StaticTiledMapTile(explosionLeftEnd));
        cellDown.getTile().getProperties().put("deadly", null);

        map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellDown);
        break;
      }

      if (x != explosionRange) // If not end of explosion
      {
        // Set cell with middle explosion texture
        TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
        cell.setTile(new StaticTiledMapTile(explosionXMiddle));
        cell.getTile().getProperties().put("deadly", null);

        map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cell);

      } else {
        TiledMapTileLayer.Cell cellLeft = new TiledMapTileLayer.Cell();
        cellLeft.setTile(new StaticTiledMapTile(explosionLeftEnd));
        cellLeft.getTile().getProperties().put("deadly", null);

        map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellLeft);
      }
    }
  }
コード例 #3
0
ファイル: Turret.java プロジェクト: Aeo-Informatik/Bomberman
  public void explodeDown() {
    for (int y = 1; y <= explosionRange; y++) {
      // If explosion hits block
      if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX(), cellPos.getY() - y))) {
        // Set ending texture and break out of loop
        TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
        cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
        cellDown.getTile().getProperties().put("deadly", null);

        map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
        break;
      }

      if (y != explosionRange) // If not end of explosion
      {
        TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
        cell.setTile(new StaticTiledMapTile(explosionYMiddle));
        cell.getTile().getProperties().put("deadly", null);

        map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cell);
      } else {
        // Set end of explosion
        TiledMapTileLayer.Cell cellUp = new TiledMapTileLayer.Cell();
        cellUp.setTile(new StaticTiledMapTile(explosionDownEnd));
        cellUp.getTile().getProperties().put("deadly", null);

        map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellUp);
      }
    }
  }
コード例 #4
0
ファイル: Turret.java プロジェクト: Aeo-Informatik/Bomberman
  public void deleteLeft() {
    for (int x = 1; x <= explosionRange; x++) {
      TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
      cell.setTile(new StaticTiledMapTile(emptyBlock));

      // If explosion hits block
      if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()))) {
        // Delete explosion effect
        map.getBombLayer().setCell(cellPos.getX() - x, cellPos.getY(), cell);

        // Delete block
        deleteBlock(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()));

        break;
      }

      // Explosion down
      map.getBombLayer().setCell(cellPos.getX() - x, cellPos.getY(), cell);
      deleteBlock(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()));
    }
  }
コード例 #5
0
ファイル: Coin.java プロジェクト: Aeo-Informatik/Bomberman
  @Override
  public void render() {
    // Render item
    TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
    cell.setTile(new StaticTiledMapTile(animEffects.getFrame(TextureManager.coinAnim, true)));
    map.getItemLayer().setCell(cellPos.getX(), cellPos.getY(), cell);

    super.deleteItemThroughBomb();

    if (isMainPlayerCollectingItem() == true) {
      itemEffect();
    }

    if (getPlayerIdCollectingItem() != -1) {
      sound = AudioManager.getSingleCoin();
      soundId = sound.play();
    }

    Player player = entityManager.getPlayerManager().getCurrentPlayerObject();
    if (player != null && sound != null) {
      player.playSoundInDistance(sound, soundId, pos, Constants.COINMOD);
    }
  }
コード例 #6
0
ファイル: MapController.java プロジェクト: neosam/ld30game
 public void draw(Batch batch) {
   batch.begin();
   final Iterator<MapLayer> layerIterator = tiledMap.getLayers().iterator();
   while (layerIterator.hasNext()) {
     final MapLayer mapLayer = layerIterator.next();
     if (mapLayer instanceof TiledMapTileLayer) {
       final TiledMapTileLayer tiledLayer = (TiledMapTileLayer) mapLayer;
       final int width = tiledLayer.getWidth();
       final int height = tiledLayer.getHeight();
       for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
           final TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y);
           if (cell == null) {
             continue;
           }
           final TextureRegion textureRegion = cell.getTile().getTextureRegion();
           batch.draw(textureRegion, x + offset.x, y + offset.y, 1, 1);
         }
       }
     }
   }
   batch.end();
 }
コード例 #7
0
ファイル: Turret.java プロジェクト: Aeo-Informatik/Bomberman
  @Override
  public void render() {

    switch (currDirection) {
      case ("Up"):
        super.setBombAnim(Up);
        break;
      case ("Right"):
        super.setBombAnim(Right);
        break;
      case ("Down"):
        super.setBombAnim(Down);
        break;
      case ("Left"):
        super.setBombAnim(Left);
        break;
      default:
        System.out.println("Something went wrong incorrect direction");
        break;
    }

    // To make sure no bomb gets placed into wall
    if (!map.isCellBlocked(new MapCellCoordinates(pos.getX(), pos.getY())) && !isExploded) {
      // Check if bomb has been hit by another bomb
      if (map.isCellDeadly(new MapCellCoordinates(pos.getX(), pos.getY()))
          && hasBombTouchedDeadlyTile == false) {
        this.isExploded = true;
        // Create new cell and set texture
        TiledMapTileLayer.Cell cellCenter = new TiledMapTileLayer.Cell();
        cellCenter.setTile(new StaticTiledMapTile(emptyBlock));
        deleteExplosionEffect(explosionRange, explosionRange, explosionRange, explosionRange);

        // Explosion center replaces bomb texture
        map.getBombLayer().setCell(cellPos.getX(), cellPos.getY(), cellCenter);
      }

      // If time to explode or deadly tile has been touched
      if (timerTillExplosion >= explosionTime) {
        //                fuseSound.stop();
        explode(AudioManager.getNormalExplosion());

        // Delete explosion effect after a while
        if (timerTillExplosionDelete >= explosionDuration) {
          deleteExplosionEffect(explosionRange, explosionRange, explosionRange, explosionRange);

        } else {
          // Add passed time to timer
          timerTillExplosionDelete += Constants.DELTATIME;
        }

      } else if (!hasBombTouchedDeadlyTile) // Creates bomb animation
      {
        // Create new cell and set its animation texture
        TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
        cell.setTile(new StaticTiledMapTile(animEffects.getFrame(bombAnim, true)));
        cell.getTile().getProperties().put("bomb", null);

        // Set bomb into bomb layer
        map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY(), cell);
      }

      if (rounds >= 3) {
        this.isExploded = true;
        // Create new cell and set texture
        TiledMapTileLayer.Cell cellCenter = new TiledMapTileLayer.Cell();
        cellCenter.setTile(new StaticTiledMapTile(emptyBlock));

        // Explosion center replaces bomb texture
        map.getBombLayer().setCell(cellPos.getX(), cellPos.getY(), cellCenter);
      }

      // Add passed time to bomb activation timer
      timerTillExplosion += Constants.DELTATIME;

    } else {
      // If bomb placed in wall delete bomb object.
      this.isExploded = true;
    }
  }
コード例 #8
0
  @Override
  public void renderTileLayer(TiledMapTileLayer layer) {

    final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());

    final int layerWidth = layer.getWidth();
    final int layerHeight = layer.getHeight();

    final float layerTileWidth = layer.getTileWidth() * unitScale;
    final float layerTileHeight = layer.getTileHeight() * unitScale;

    final float layerTileWidth25 = layerTileWidth * 0.25f;
    final float layerTileWidth50 = layerTileWidth * 0.50f;
    final float layerTileWidth75 = layerTileWidth * 0.75f;

    final float layerTileHeight50 = layerTileHeight * 0.50f;
    final float layerTileHeight150 = layerTileHeight * 1.50f;

    final int col1 = Math.max(0, (int) (((viewBounds.x - layerTileWidth25) / layerTileWidth75)));
    final int col2 =
        Math.min(
            layerWidth,
            (int) ((viewBounds.x + viewBounds.width + layerTileWidth75) / layerTileWidth75));

    final int row1 = Math.max(0, (int) ((viewBounds.y / layerTileHeight150)));
    final int row2 =
        Math.min(
            layerHeight,
            (int) ((viewBounds.y + viewBounds.height + layerTileHeight150) / layerTileHeight));

    final float[] vertices = this.vertices;

    for (int row = row1; row < row2; row++) {
      for (int col = col1; col < col2; col++) {

        float x = layerTileWidth75 * col;
        float y = (col % 2 == (yDown ? 0 : 1) ? 0 : layerTileHeight50) + (layerTileHeight * row);

        final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
        if (cell == null) {
          x += layerTileWidth;
          continue;
        }
        final TiledMapTile tile = cell.getTile();
        if (tile != null) {
          if (tile instanceof AnimatedTiledMapTile) continue;

          final boolean flipX = cell.getFlipHorizontally();
          final boolean flipY = cell.getFlipVertically();
          final int rotations = cell.getRotation();

          TextureRegion region = tile.getTextureRegion();

          float x1 = x;
          float y1 = y;
          float x2 = x1 + region.getRegionWidth() * unitScale;
          float y2 = y1 + region.getRegionHeight() * unitScale;

          float u1 = region.getU();
          float v1 = region.getV2();
          float u2 = region.getU2();
          float v2 = region.getV();

          vertices[X1] = x1;
          vertices[Y1] = y1;
          vertices[C1] = color;
          vertices[U1] = u1;
          vertices[V1] = v1;

          vertices[X2] = x1;
          vertices[Y2] = y2;
          vertices[C2] = color;
          vertices[U2] = u1;
          vertices[V2] = v2;

          vertices[X3] = x2;
          vertices[Y3] = y2;
          vertices[C3] = color;
          vertices[U3] = u2;
          vertices[V3] = v2;

          vertices[X4] = x2;
          vertices[Y4] = y1;
          vertices[C4] = color;
          vertices[U4] = u2;
          vertices[V4] = v1;

          if (flipX) {
            float temp = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = temp;
            temp = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = temp;
          }
          if (flipY) {
            float temp = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = temp;
            temp = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = temp;
          }
          if (rotations == 2) {
            float tempU = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = tempU;
            tempU = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = tempU;
            float tempV = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = tempV;
            tempV = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = tempV;
            break;
          }
          spriteBatch.draw(region.getTexture(), vertices, 0, 20);
        }
      }
    }
  }
コード例 #9
0
  @Override
  public void renderTileLayer(TiledMapTileLayer layer) {
    final Color batchColor = batch.getColor();
    final float color =
        Color.toFloatBits(
            batchColor.r, batchColor.g, batchColor.b, batchColor.a * layer.getOpacity());

    final int layerWidth = layer.getWidth();
    final int layerHeight = layer.getHeight();

    final float layerTileWidth = layer.getTileWidth() * unitScale;
    final float layerTileHeight = layer.getTileHeight() * unitScale;

    final float layerTileWidth50 = layerTileWidth * 0.50f;
    final float layerTileHeight50 = layerTileHeight * 0.50f;

    final int minX = Math.max(0, (int) (((viewBounds.x - layerTileWidth50) / layerTileWidth)));
    final int maxX =
        Math.min(
            layerWidth,
            (int)
                ((viewBounds.x + viewBounds.width + layerTileWidth + layerTileWidth50)
                    / layerTileWidth));

    final int minY = Math.max(0, (int) (((viewBounds.y - layerTileHeight) / layerTileHeight)));
    final int maxY =
        Math.min(
            layerHeight,
            (int) ((viewBounds.y + viewBounds.height + layerTileHeight) / layerTileHeight50));

    for (int y = maxY - 1; y >= minY; y--) {
      float offsetX = (y % 2 == 1) ? layerTileWidth50 : 0;
      for (int x = maxX - 1; x >= minX; x--) {
        final TiledMapTileLayer.Cell cell = layer.getCell(x, y);
        if (cell == null) continue;
        final TiledMapTile tile = cell.getTile();

        if (tile != null) {
          final boolean flipX = cell.getFlipHorizontally();
          final boolean flipY = cell.getFlipVertically();
          final int rotations = cell.getRotation();
          TextureRegion region = tile.getTextureRegion();

          float x1 = x * layerTileWidth - offsetX + tile.getOffsetX() * unitScale;
          float y1 = y * layerTileHeight50 + tile.getOffsetY() * unitScale;
          float x2 = x1 + region.getRegionWidth() * unitScale;
          float y2 = y1 + region.getRegionHeight() * unitScale;

          float u1 = region.getU();
          float v1 = region.getV2();
          float u2 = region.getU2();
          float v2 = region.getV();

          vertices[X1] = x1;
          vertices[Y1] = y1;
          vertices[C1] = color;
          vertices[U1] = u1;
          vertices[V1] = v1;

          vertices[X2] = x1;
          vertices[Y2] = y2;
          vertices[C2] = color;
          vertices[U2] = u1;
          vertices[V2] = v2;

          vertices[X3] = x2;
          vertices[Y3] = y2;
          vertices[C3] = color;
          vertices[U3] = u2;
          vertices[V3] = v2;

          vertices[X4] = x2;
          vertices[Y4] = y1;
          vertices[C4] = color;
          vertices[U4] = u2;
          vertices[V4] = v1;

          if (flipX) {
            float temp = vertices[U1];
            vertices[U1] = vertices[U3];
            vertices[U3] = temp;
            temp = vertices[U2];
            vertices[U2] = vertices[U4];
            vertices[U4] = temp;
          }

          if (flipY) {
            float temp = vertices[V1];
            vertices[V1] = vertices[V3];
            vertices[V3] = temp;
            temp = vertices[V2];
            vertices[V2] = vertices[V4];
            vertices[V4] = temp;
          }

          if (rotations != 0) {
            switch (rotations) {
              case Cell.ROTATE_90:
                {
                  float tempV = vertices[V1];
                  vertices[V1] = vertices[V2];
                  vertices[V2] = vertices[V3];
                  vertices[V3] = vertices[V4];
                  vertices[V4] = tempV;

                  float tempU = vertices[U1];
                  vertices[U1] = vertices[U2];
                  vertices[U2] = vertices[U3];
                  vertices[U3] = vertices[U4];
                  vertices[U4] = tempU;
                  break;
                }
              case Cell.ROTATE_180:
                {
                  float tempU = vertices[U1];
                  vertices[U1] = vertices[U3];
                  vertices[U3] = tempU;
                  tempU = vertices[U2];
                  vertices[U2] = vertices[U4];
                  vertices[U4] = tempU;
                  float tempV = vertices[V1];
                  vertices[V1] = vertices[V3];
                  vertices[V3] = tempV;
                  tempV = vertices[V2];
                  vertices[V2] = vertices[V4];
                  vertices[V4] = tempV;
                  break;
                }
              case Cell.ROTATE_270:
                {
                  float tempV = vertices[V1];
                  vertices[V1] = vertices[V4];
                  vertices[V4] = vertices[V3];
                  vertices[V3] = vertices[V2];
                  vertices[V2] = tempV;

                  float tempU = vertices[U1];
                  vertices[U1] = vertices[U4];
                  vertices[U4] = vertices[U3];
                  vertices[U3] = vertices[U2];
                  vertices[U2] = tempU;
                  break;
                }
            }
          }
          batch.draw(region.getTexture(), vertices, 0, 20);
        }
      }
    }
  }