Exemplo n.º 1
0
  public void setupGUI() {
    stage = new Stage();

    skin = new Skin(Gdx.files.internal("uiskin.json"));
    table = new Table(skin);
    // table.setBounds(0, 0, Gdx.graphics.getWidth(),
    // Gdx.graphics.getHeight());
    // table.setClip(true);

    Gdx.input.setInputProcessor(stage);

    // defaultStyle.over = skin.getDrawable("button.hover");

    TextButton fullScreenButton = new TextButton("Toglle Full Screen", skin, "default");
    fullScreenButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Config.fullscreen = !Config.fullscreen;
          }
        });

    // fullScreenButton.setFillParent(true);
    TextButton saveSettingsButton = new TextButton("Save settings", skin, "default");
    saveSettingsButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Config.reload();
            show();
          }
        });
    Container<TextButton> saveSettingContainer = new Container<TextButton>(saveSettingsButton);

    saveSettingContainer.padTop(Value.percentHeight(.6f, table));

    TextButton backButton = new TextButton("Go back", skin, "default");
    backButton.addListener(
        new ClickListener() {
          @Override
          public void clicked(InputEvent event, float x, float y) {
            Screens.setScreen(Screens.MAIN_MENU_SCREEN);
          }
        });

    VerticalGroup buttons1 = new VerticalGroup();
    buttons1.fill();
    buttons1.addActor(fullScreenButton);

    VerticalGroup buttons2 = new VerticalGroup();
    buttons2.fill();
    buttons2.addActor(saveSettingsButton);
    buttons2.addActor(backButton);

    // buttons.setPosition(Gdx.graphics.getWidth()/4,
    // Gdx.graphics.getHeight()/5);

    VerticalGroup resolution = new VerticalGroup();
    ButtonGroup<TextButton> buttonGroup = new ButtonGroup<>();
    buttonGroup.setMaxCheckCount(1);
    resolution.fill();

    transparentSkin = new Skin(new TextureAtlas("select.pack"));
    TextButtonStyle transparent = new TextButtonStyle();
    transparent.checked = transparentSkin.getDrawable("checked");
    transparent.up = transparentSkin.getDrawable("up");
    transparent.font = FontUtil.generateFont(Color.WHITE, 20);

    addResolutions(buttonGroup, transparent);

    for (TextButton b : buttonGroup.getButtons()) {
      resolution.addActor(b);
    }

    resolution.right();

    ScrollPane resolScroll = new ScrollPane(resolution);
    resolScroll.setHeight(700);

    Label fullScreenLabel = new Label("", skin);
    fullScreenLabel.addAction(
        Actions.forever(
            new Action() {
              @Override
              public boolean act(float delta) {
                if (Config.fullscreen) {
                  fullScreenLabel.setColor(Color.GREEN);
                  fullScreenLabel.setText("on");
                } else {
                  fullScreenLabel.setColor(Color.RED);
                  fullScreenLabel.setText("off");
                }
                return true;
              }
            }));

    table.setFillParent(true);
    Table left = new Table();
    left.add(buttons1).spaceBottom(Value.percentHeight(.6f, table));
    left.add(fullScreenLabel).top();
    left.row();
    // left.row();
    left.add(buttons2);
    // table.add(buttons1.left()).left();
    table.add(left).left().padLeft(Value.percentWidth(0.1f, table)).expandX();
    // table.add(fullScreenLabel).top().spaceRight(Value.percentWidth(.5f,
    // table));
    table.add(resolScroll).right().padRight(Value.percentWidth(0.1f, table));

    // table.row();
    // table.add(buttons2).bottom().left();
    // table.center();

    stage.addActor(table);

    if (Config.debug) table.setDebug(true);
  }
Exemplo n.º 2
0
  public Beaver(World world, Island island) {
    this.island = island;
    float scale = 2.0f;
    float radius = 1.0f;
    BodyDef bd = new BodyDef();
    bd.type = BodyDef.BodyType.DynamicBody;

    Vector2 pos = island.physicsBody.getPosition();
    ang = island.physicsBody.getAngle();

    float islandW = island.getPhysicsWidth();
    float islandH = island.getPhysicsHeight();

    Vector2 off = new Vector2(islandW * MathUtils.random(0.3f, 0.6f), islandH);
    off.rotate(MathUtils.radiansToDegrees * ang);

    bd.position.set(new Vector2(pos.x + off.x, pos.y + off.y));
    bd.angle = ang;

    off.set(islandW * 0.075f, islandH);
    off.rotate(MathUtils.radiansToDegrees * ang);
    Vector2 rightEdge = new Vector2(pos.x + off.x, pos.y + off.y).scl(Mane.PTM_RATIO);
    off.set(islandW * 0.85f, islandH);
    off.rotate(MathUtils.radiansToDegrees * ang);
    Vector2 leftEdge = new Vector2(pos.x + off.x, pos.y + off.y).scl(Mane.PTM_RATIO);

    float speed = MathUtils.random(1.0f, 3.0f);
    addAction(
        Actions.delay(
            MathUtils.random(0.0f, 1.0f),
            Actions.forever(
                Actions.sequence(
                    Actions.moveTo(rightEdge.x, rightEdge.y, speed),
                    Actions.moveTo(leftEdge.x, leftEdge.y, speed)))));

    bd.linearDamping = 0.2f;

    Body body = world.createBody(bd);

    FixtureDef fd = new FixtureDef();

    fd.density = 1.0f;
    fd.filter.categoryBits = Collision.BEAVER;
    fd.filter.maskBits = Collision.SHARK;

    fd.restitution = 0.0f;
    fd.friction = 0.0f;
    fd.isSensor = true;

    CircleShape cs = new CircleShape();
    cs.setRadius(radius);
    cs.setPosition(new Vector2(radius, radius));

    fd.shape = cs;

    body.createFixture(fd);
    cs.dispose();
    super.initPhysicsBody(body);

    setSize(scale * Mane.PTM_RATIO, scale * Mane.PTM_RATIO);
    setOrigin(0.0f, 0.0f);
  }