示例#1
0
 public static Rectangle loadRectangleFromXmlOptSize(Node node) {
   Rectangle rect = new Rectangle();
   rect.setX(Integer.parseInt(XmlHelper.loadAttribute(node, "X")));
   rect.setY(Integer.parseInt(XmlHelper.loadAttribute(node, "Y")));
   rect.setWidth(Integer.parseInt(XmlHelper.loadAttribute(node, "Width", "0")));
   rect.setHeight(Integer.parseInt(XmlHelper.loadAttribute(node, "Height", "0")));
   return rect;
 }
 private Rectangle scaleRectangle(Rectangle rect, float scaleX, float scaleY) {
   Rectangle scaled = new Rectangle();
   scaled.setX(rect.getX() * scaleX);
   scaled.setY(rect.getY() * scaleY);
   scaled.setWidth(rect.getWidth() * scaleX);
   scaled.setHeight(rect.getHeight() * scaleY);
   return scaled;
 }
示例#3
0
  private void tryToMovePlayer() {
    boolean sticked = player.abilities.contains(Ability.SLICK);

    if (player.jumpCommand || sticked) {
      int nextBlock = (player.gravityDirection < 0) ? -1 : 2;

      Tile tile1 = map[(int) player.x / BLOCK_SIZE][(int) player.y / BLOCK_SIZE + nextBlock];
      Tile tile2 = map[(int) player.x / BLOCK_SIZE + 1][(int) player.y / BLOCK_SIZE + nextBlock];

      boolean onTheGround =
          player.state != State.SWIM
              && (tile1 == Tile.BLOCK
                  || tile1 == Tile.GLASS
                  || tile1 == Tile.TUBE_UP
                  || tile1 == Tile.TUBE_RIGHT
                  || tile1 == Tile.TUBE_DOWN
                  || tile1 == Tile.TUBE_LEFT
                  || tile2 == Tile.BLOCK
                  || tile2 == Tile.GLASS
                  || tile2 == Tile.TUBE_UP
                  || tile2 == Tile.TUBE_RIGHT
                  || tile2 == Tile.TUBE_DOWN
                  || tile2 == Tile.TUBE_LEFT);

      if (!player.isJumping && onTheGround && !sticked) {
        //                Sounds.get().play(Sounds.JUMP);
        player.vy -= player.gravityDirection * Player.JUMPING;
        player.isJumping = true;
      } else if (!onTheGround && sticked) {
        player.clearSlick();
      }

      player.jumpCommand = false;
    }

    Rectangle pr =
        new Rectangle(
            (int) player.x / BLOCK_SIZE + (((int) player.x % BLOCK_SIZE == 0) ? 0 : 1),
            (int) Math.floor(player.y / BLOCK_SIZE) + (((int) player.y % BLOCK_SIZE == 0) ? 0 : 1),
            1,
            1);
    Rectangle[] rs;

    boolean collided = false;

    player.x += player.vx;
    pr.setX((int) player.x / BLOCK_SIZE);
    rs = checkCollisions();
    for (Rectangle r : rs) {
      if (pr.overlaps(r)) {
        if (player.vx < 0) player.x = (r.x + 1) * BLOCK_SIZE + 0.01f;
        else player.x = (r.x - 1) * BLOCK_SIZE - 0.01f;

        collided = true;
      }
    }

    if (collided) {
      player.vx = 0; /*player.ax = 0;*/
    }
    collided = false;

    player.y += player.vy;
    pr.setX((int) player.x / BLOCK_SIZE);
    pr.setY((int) Math.floor(player.y / BLOCK_SIZE));
    rs = checkCollisions();
    for (Rectangle r : rs) {
      if (pr.overlaps(r)) {
        if (player.vy < 0) player.y = (r.y + 1) * BLOCK_SIZE + 0.01f;
        else player.y = (r.y - 1) * BLOCK_SIZE - 0.01f;

        collided = true;
      }
    }

    if (collided) {
      if (player.isJumping && player.vy * player.gravityDirection > 0) player.isJumping = false;

      if (player.gravityDirection > 0 && player.vy > 0) {
        //                if (! player.abilities.contains(Ability.SLICK)) {
        //                    wasCollided = true;
        //                    collidedCount = 50;
        //                }

        if (!sticked) player.gravityDirection = -1;

        player.abilities.remove(Ability.GAS);
      }

      player.vy = 0;
      player.ay = 0;

      //            if (! player.gravityAffection) {
      //                wasCollided = true;
      //                collidedCount++;
      //            }
    } /*else if (! player.gravityAffection*/ /* && wasCollided*/ /*) {
                                                                 //            if (collidedCount > 5) {
                                                                 //                player.clearSlick();
                                                                 //                wasCollided = false;
                                                                 //            }
                                                                         }*/
  }