Exemplo n.º 1
0
 private boolean isCellBlocked(float x, float y) {
   Vector2 newCoords = UtilityMethods.screenToMapCoordinate(new Vector2(x, y));
   // System.out.println("Player: x" + sprite.getX() + " y " + sprite.getY());
   // System.out.println("Tile: x" + newCoords.x + " y " + newCoords.y);
   // sprite.setPosition(newCoords.x, newCoords.y);
   Cell cell =
       collisionLayer.getCell(
           (int) (newCoords.x / collisionLayer.getTileWidth()),
           (int) (newCoords.y / collisionLayer.getTileHeight()));
   // System.out.println(cell);
   return cell != null
       && cell.getTile() != null
       && cell.getTile().getProperties().containsKey("blocked");
 }
Exemplo n.º 2
0
  @Override
  public void render(Batch batch) {
    Vector2 newPosition =
        UtilityMethods.moveCoordinate(
            new Vector2(sprite.getX(), sprite.getY()),
            spriteVector.x * Gdx.graphics.getDeltaTime(),
            spriteVector.y * Gdx.graphics.getDeltaTime());

    if (isCellBlocked(newPosition.x, newPosition.y)) return;

    sprite.setPosition(newPosition.x, newPosition.y);
    position.x = newPosition.x;
    position.y = newPosition.y;

    drawPlayer(batch);
  }
Exemplo n.º 3
0
  private void init(MapLayer objectLayer) {
    try {
      sprite = new Sprite(Assets.instance.player.getNorthAnimation().getKeyFrame(0, false));
      sprite.scale(1.25f);
      sprite.setOrigin(0.0f, 0.0f);

      collisionLayer = (TiledMapTileLayer) Assets.instance.world.getMap().getLayers().get(0);

      for (MapObject obj : objectLayer.getObjects()) {
        if (obj instanceof EllipseMapObject) {
          Ellipse ellipse = ((EllipseMapObject) obj).getEllipse();
          position = UtilityMethods.mapToScreenCoordinate(new Vector2(ellipse.x, ellipse.y));
        }
      }
      sprite.setPosition(position.x, position.y);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }