Esempio n. 1
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();
  }
Esempio n. 2
0
  public LevelEditorGameState(GameStateManager gsm) {
    super(gsm);

    bitmapFont = new BitmapFont();
    stage = new Stage();

    Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
    Label titleLabel = new Label("Level Editor", skin);
    stage.addActor(titleLabel);
    Table table = new Table();
    stage.addActor(table);
    table.setSize(V_WIDTH / 3, V_HEIGHT);
    table.setPosition(0, 0);
    table.debug(); // show debug shit

    int i = 0;
    for (E_TOOL e : E_TOOL.values()) {
      // for use in the input listener
      final E_TOOL temp = e;
      TextButton b = new TextButton(e.name(), skin);
      b.addListener(
          new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
              current_Tool = temp;
              return false;
            }
          });

      if (++i % 2 == 0) {
        table.row();
      }
      table.add(b);
    }

    table.row();

    table.add(new Label("Zoom", skin));
    zoomSlider = new Slider(0.1f, 10.0f, 0.1f, false, skin);
    zoomSlider.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            cam.zoom = zoom = zoomSlider.getValue();
          }
        });
    table.add(zoomSlider);

    table.row();

    table.add(new Label("Grid", skin));
    gridSlider = new Slider(1, 20, 1, false, skin);
    gridSlider.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            gridSize = (int) gridSlider.getValue();
          }
        });
    table.add(gridSlider);

    final List pointTypeList = new List(skin);
    pointTypeList.setItems(Point.TYPE.values());
    pointTypeList.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            point_Type = (Point.TYPE) pointTypeList.getSelected();
          }
        });

    final List shapeTypeList = new List(skin);
    shapeTypeList.setItems(Shape.TYPE.values());
    shapeTypeList.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            shape_Type = (Shape.TYPE) shapeTypeList.getSelected();
          }
        });

    table.row();
    table.add(pointTypeList);

    table.row();
    table.add(shapeTypeList);

    current_Tool = E_TOOL.SELECT;
    point_Type = Point.TYPE.SPAWN;
    shape_Type = Shape.TYPE.WALL;

    gridSize = 2;
    width = V_WIDTH;
    height = V_HEIGHT;
    zoom = 5;

    cam.zoom = zoom;

    filename = "blacklevel.lvl";
    loadLevel(filename);

    setInputProcessor(new InputMultiplexer(stage, new EditorInputAdapter()));
  }