コード例 #1
0
  public void loadShapes(JsonValue shapes, float x, float y) {
    Body body = null;
    JsonValue types = shapes.get("shapes");

    if (types != null) {
      for (JsonValue shapeVal : types) {
        String shape = shapeVal.get("shape").asString();
        String type = shapeVal.get("type").asString();

        float[] pos = shapeVal.get("location").asFloatArray();
        float friction = shapeVal.get("friction").asFloat();
        float density = shapeVal.get("density").asFloat();

        JsonValue jsonName = shapeVal.get("name");
        Shape.TYPE typeLookup = Shape.TYPE.WALL;

        // looking up enum type
        if (type.equals("GROUND")) {
          typeLookup = Shape.TYPE.GROUND;
        } else if (type.equals("DEATH")) {
          typeLookup = Shape.TYPE.DEATH;
        }

        if (shape.equals("box")) {
          float[] size = shapeVal.get("size").asFloatArray();
          controller.createBox(
              typeLookup, pos[0] + x, pos[1] + y, size[0], size[1], friction, density);

        } else if (shape.equals("circle")) {
          float radius = shapeVal.get("radius").asFloat();
          controller.createCircle(typeLookup, pos[0] + x, pos[1] + y, radius, 0, 0);
        }

        // Only add named blocks
        if (jsonName != null && body != null) {
          String name = shapeVal.get("name").asString();
        }
      }
    }
  }
コード例 #2
0
  public void loadPoints(JsonValue maps) {
    JsonValue points = maps.get("points");

    for (JsonValue value : points) {
      float[] pos = value.get("location").asFloatArray();
      String type = value.get("type").asString();
      String subtype = value.get("subtype").asString();
      Point.TYPE typeLookup = Point.TYPE.SPAWN;

      // looking up enum type
      if (type.equals("NODE")) {
        typeLookup = Point.TYPE.NODE;
        typeLookup = Point.TYPE.PICKUP;
      }
      controller.createPoint(typeLookup, subtype, pos[0], pos[1]);
    }
  }