Package com.badlogic.gdx.math

Examples of com.badlogic.gdx.math.Rectangle


        int yCell = (int) (y / tileHeight);
        Cell cell = TiledMapManager.collisionLayer.getCell(xCell, yCell);
       
        // Si es un bloque se añade para comprobar colisiones
        if ((cell != null) && (cell.getTile().getProperties().containsKey(TiledMapManager.BLOCKED))) {
          Rectangle rect = rectPool.obtain();
          // El jugador está saltando (se choca con la cabeza en una celda)
          if (velocity.y > 0)
            rect.set(x, y, 1, 1);
          // El jugador está cayendo (se posa en la celda que tenga debajo)
          else
            rect.set((int) (Math.ceil(x / tileWidth) * tileWidth), (int) (Math.ceil(y / tileHeight) * tileHeight), 0, 0);
         
          tiles.add(rect);
         
          if (velocity.y > 0)
            if (cell.getTile().getProperties().containsKey(TiledMapManager.BOX)) {
View Full Code Here


  /**
   * Comprueba las colisiones del jugador con los elementos móviles del juego
   * Enemigos e items
   */
  private void checkCollisions() {
    Rectangle playerRect = new Rectangle();
    playerRect.set(player.position.x, player.position.y, Player.WIDTH, Player.HEIGHT);
   
    // Comprueba si el enemigo ha chocado contra algún enemigo
    for (Enemy enemy : levelManager.enemies) {
      Rectangle enemyRect = new Rectangle();
      enemyRect.set(enemy.position.x, enemy.position.y, Enemy.WIDTH, Enemy.HEIGHT);
     
      if (enemyRect.overlaps(playerRect)) {
       
        // Si el jugador está por encima elimina el enemigo
        if (player.position.y > (enemy.position.y + 5)) {
          ResourceManager.getSound("sounds/kick.wav").play();
          levelManager.enemies.removeValue(enemy, true);
         
          // El jugador rebota
          player.jump(false);
        }
        // Si está al mismo nivel o por debajo se pierde una vida
        else {
          player.velocity.x = player.velocity.y = 0;
                    player.die();
        }
      }
    }
   
    // Comprueba si el jugador recoge algún item de la pantalla
    for (Item item : levelManager.items) {
      Rectangle itemRect = new Rectangle();
      itemRect.set(item.position.x, item.position.y, Item.WIDTH, Item.HEIGHT);
     
      if (itemRect.overlaps(playerRect)) {
        ResourceManager.getSound("sounds/1up.wav").play();
        levelManager.items.removeValue(item, true);
        levelManager.currentLives++;
      }
    }
   
    boolean stuck = false;
    // Comprueba colisiones con las plataformas móviles de la pantalla
    for (Platform platform : levelManager.platforms) {
      Rectangle platformRectangle = new Rectangle(platform.position.x, platform.position.y, platform.width, platform.height);
       
      // Si colisiona con una se coloca encima y se "pega" a ella
      if (platformRectangle.overlaps(playerRect)) {
       
        // Si está cayendo y está por encima se coloca en la plataforma
        if ((player.velocity.y < 0) && (player.position.y > platformRectangle.y)) {
          player.position.y = platformRectangle.y + platformRectangle.height;
          player.canJump = true;
View Full Code Here

    for (MapObject object : map.getLayers().get("objects").getObjects()) {
     
      if (object instanceof RectangleMapObject) {
        RectangleMapObject rectangleObject = (RectangleMapObject) object;
        if (rectangleObject.getProperties().containsKey(TiledMapManager.ENEMY)) {
          Rectangle rect = rectangleObject.getRectangle();
         
          enemy = new Enemy();
          enemy.position.set(rect.x, rect.y);
          enemies.add(enemy);
        }
View Full Code Here

    for (MapObject object : map.getLayers().get("objects").getObjects()) {
     
      if (object instanceof RectangleMapObject) {
        RectangleMapObject rectangleObject = (RectangleMapObject) object;
        if (rectangleObject.getProperties().containsKey(TiledMapManager.MOBILE)) {
          Rectangle rect = rectangleObject.getRectangle();
         
          Direction direction = null;
          if (Boolean.valueOf((String) rectangleObject.getProperties().get("right_direction")))
            direction = Direction.RIGHT;
          else
View Full Code Here

  }

  public BatchTiledMapRenderer (TiledMap map, float unitScale) {
    this.map = map;
    this.unitScale = unitScale;
    this.viewBounds = new Rectangle();
    this.spriteBatch = new SpriteBatch();
    this.ownsSpriteBatch = true;
  }
View Full Code Here

  }

  public BatchTiledMapRenderer (TiledMap map, float unitScale, SpriteBatch spriteBatch) {
    this.map = map;
    this.unitScale = unitScale;
    this.viewBounds = new Rectangle();
    this.spriteBatch = spriteBatch;
    this.ownsSpriteBatch = false;
  }
View Full Code Here

    }

    public TransientMapRenderer(TiledMap map, float unitScale, Coords topLeft) {
        this.map = map;
        this.unitScale = unitScale;
        this.viewBounds = new Rectangle(topLeft.x, topLeft.y, Detonator.INSTANCE.ScreenSizeX, Detonator.INSTANCE.ScreenSizeY);
        this.spriteBatch = new SpriteBatch();
        this.ownsSpriteBatch = true;
       
//        this.renderPrefix = "visible_";
    }
View Full Code Here

    }

    public TransientMapRenderer(TiledMap map, float unitScale, SpriteBatch spriteBatch) {
        this.map = map;
        this.unitScale = unitScale;
        this.viewBounds = new Rectangle();
        this.spriteBatch = spriteBatch;
        this.ownsSpriteBatch = false;
       
//        this.renderPrefix = "visible_";
    }
View Full Code Here

       
        terrainGrid = new TerrainScreenGrid(map, spriteBatch);
       
        unitGrid = new UnitScreenGrid(map, spriteBatch);
       
        mapRenderer.setViewBounds (new Rectangle(positionX, positionY, Detonator.INSTANCE.ScreenSizeX, Detonator.INSTANCE.ScreenSizeY));
    }
View Full Code Here

   * @param y
   */
  public Character(float x, float y) {
    currentFrame = null;
    position = new Vector2(x, y);
    rect = new Rectangle(x, y, Constants.ENEMY_WIDTH, Constants.ENEMY_HEIGHT);
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.math.Rectangle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.