예제 #1
0
  public void saveLevel() {
    String jsonString = "{\n\t\"level\":{\n";
    jsonString += "\t\t\"name\": \"testLevel\",\n";

    // print to separate sections
    String blocks = "\t\t\"shapes\" : [\n ";
    String points = "\t\t\"points\" : [\n ";

    // add to appropriate sections
    for (Selectable lo : controller.levelObjects) {
      if (lo instanceof Shape) blocks += "\t\t\t" + lo.toJson() + ",\n";
      else if (lo instanceof Point) points += "\t\t\t" + lo.toJson() + ",\n";
    }

    // remove last comma
    blocks = blocks.substring(0, blocks.length() - 2);
    points = points.substring(0, points.length() - 2);

    // finish sections
    blocks += "\n\t\t],\n";
    points += "\n\t\t]\n";

    jsonString += blocks + points + "\t}\n}";

    FileHandle file = Gdx.files.local(filename);
    file.writeString(jsonString, false); // false == overwrite
  }
예제 #2
0
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      touchDown.set(screenX, screenY, 0);
      cam.unproject(touchDown);
      toolLock = true;

      switch (current_Tool) {
        case SELECT:
          boolean selected = false;
          touchDown.set(screenX, screenY, 0);
          cam.unproject(touchDown);

          for (Selectable n : controller.levelObjects) {
            if (n.contains(touchDown.x, touchDown.y)) {
              if (n == controller.selection) {
                current_Tool = E_TOOL.TRANSLATE;
                selected = true;
              } else {
                controller.setSelection(n);
                selected = true;
              }
            }
          }

          if (selected == false) {
            controller.setSelection(null);
            current_Tool = E_TOOL.PAN;
          } else {
            if (controller.isSelectionShape()) {
              shape_Type = ((Shape) controller.selection).type;
            } else if (controller.isSelectionPoint()) {
              point_Type = ((Point) controller.selection).type;
            }
          }
          break;
        case RECTANGLE:
          controller.createBox(
              shape_Type, snapToGrid(touchDown.x), snapToGrid(touchDown.y), 2, 2, 0, 0);
          break;
        case CIRCLE:
          controller.createCircle(
              shape_Type, snapToGrid(touchDown.x), snapToGrid(touchDown.y), 2, 0, 0);
          break;
        case POINT:
          controller.createPoint(
              point_Type, "default", snapToGrid(touchUp.x), snapToGrid(touchUp.y));
          break;
      }

      return false;
    }
예제 #3
0
  @Override
  public void render(float dt) {
    Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT);

    ShapeRenderer shapeRenderer = this.gsm.game().getShapeRenderer();
    shapeRenderer.setProjectionMatrix(cam.combined);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
    shapeRenderer.setColor(Color.DARK_GRAY);

    float factor = zoom > 1 ? zoom : 1;
    for (int x = 0; x < V_WIDTH * factor; x += gridSize) {
      shapeRenderer.line(x, 0, x, height * factor);
    }

    for (int y = 0; y < V_HEIGHT * factor; y += gridSize) {
      shapeRenderer.line(0, y, width * factor, y);
    }

    for (Selectable shape : controller.levelObjects) {
      shape.render(shapeRenderer);
    }

    shapeRenderer.end();

    SpriteBatch sp = this.gsm.game().getBatch();
    sp.begin();
    bitmapFont.draw(sp, current_Tool.name(), 20, V_HEIGHT - 20);

    if (current_Tool == E_TOOL.POINT) bitmapFont.draw(sp, point_Type.name(), 20, V_HEIGHT - 40);

    if (current_Tool == E_TOOL.RECTANGLE || current_Tool == E_TOOL.CIRCLE)
      bitmapFont.draw(sp, shape_Type.name(), 20, V_HEIGHT - 40);

    if (current_Tool == E_TOOL.SELECT && controller.selection != null) {
      if (controller.selection instanceof Shape)
        bitmapFont.draw(sp, shape_Type.name(), 20, V_HEIGHT - 40);

      if (controller.selection instanceof Point)
        bitmapFont.draw(sp, point_Type.name(), 20, V_HEIGHT - 40);
    }

    sp.end();

    stage.draw();
  }
예제 #4
0
 public void printFeilds(Selectable selectable) {
   Field[] fields = selectable.getClass().getFields();
   for (Field field : fields) {
     try {
       System.out.println(field + " " + field.get(selectable));
     } catch (Exception e) {
       System.err.println("Issues getting fields for properties");
     }
   }
 }