示例#1
0
  private Object interpretCollision(String formula) {
    int start = 0;
    String collidesWithTag =
        CatroidApplication.getAppContext().getString(R.string.formula_editor_function_collision);
    int end = formula.indexOf(collidesWithTag) - 1;
    String firstSpriteName = formula.substring(start, end);

    start = end + collidesWithTag.length() + 2;
    end = formula.length();
    String secondSpriteName = formula.substring(start, end);

    Look firstLook;
    Look secondLook;
    try {
      firstLook =
          ProjectManager.getInstance()
              .getCurrentScene()
              .getSpriteBySpriteName(firstSpriteName)
              .look;
      secondLook =
          ProjectManager.getInstance()
              .getCurrentScene()
              .getSpriteBySpriteName(secondSpriteName)
              .look;
    } catch (Resources.NotFoundException exception) {
      return 0d;
    }

    return CollisionDetection.checkCollisionBetweenLooks(firstLook, secondLook);
  }
示例#2
0
 public boolean containsSpriteInCollision(String name) {
   boolean contained = false;
   if (leftChild != null) {
     contained |= leftChild.containsSpriteInCollision(name);
   }
   if (rightChild != null) {
     contained |= rightChild.containsSpriteInCollision(name);
   }
   if (type == ElementType.COLLISION_FORMULA) {
     String collisionTag =
         CatroidApplication.getAppContext().getString(R.string.formula_editor_function_collision);
     String firstSprite = value.substring(0, value.indexOf(collisionTag) - 1);
     String secondSprite =
         value.substring(value.indexOf(collisionTag) + collisionTag.length() + 1, value.length());
     if (firstSprite.equals(name) || secondSprite.equals(name)) {
       contained = true;
     }
   }
   return contained;
 }
示例#3
0
  public void updateCollisionFormula(String oldName, String newName) {

    if (leftChild != null) {
      leftChild.updateCollisionFormula(oldName, newName);
    }
    if (rightChild != null) {
      rightChild.updateCollisionFormula(oldName, newName);
    }
    if (type == ElementType.COLLISION_FORMULA && value.contains(oldName)) {
      String collisionTag =
          CatroidApplication.getAppContext().getString(R.string.formula_editor_function_collision);
      String firstSprite = value.substring(0, value.indexOf(collisionTag) - 1);
      String secondSprite =
          value.substring(value.indexOf(collisionTag) + collisionTag.length() + 1, value.length());
      if (firstSprite.equals(oldName)) {
        value = newName + " " + collisionTag + " " + secondSprite;
      } else if (secondSprite.equals(oldName)) {
        value = firstSprite + " " + collisionTag + " " + newName;
      }
    }
  }