Exemplo n.º 1
0
  public static Pixmap getScreenshot(
      PrettyPolygonBatch batch, OrthographicCamera camera, Rectangle boundingRectangle) {

    Vector2 center =
        CoordinateHelper.getScreenCoordinates(
            camera,
            boundingRectangle.x + boundingRectangle.getWidth() * 0.5f,
            boundingRectangle.y + boundingRectangle.getHeight() * 0.5f,
            new Vector2());

    Vector2 upperRight =
        CoordinateHelper.getScreenCoordinates(
            camera,
            boundingRectangle.x + boundingRectangle.getWidth(),
            boundingRectangle.y + boundingRectangle.getHeight(),
            new Vector2());

    int halfWidth = (int) (upperRight.x - center.x);
    int halfHeight = (int) (upperRight.y - center.y);

    Pixmap pixmap =
        getScreenshot(
            (int) (center.x - halfWidth),
            (int) (center.y - halfHeight),
            halfWidth * 2,
            halfHeight * 2,
            true);

    return pixmap;
  }
Exemplo n.º 2
0
  /**
   * Sets polygon with repeating texture region, the size of repeating grid is equal to region size
   *
   * @param region - region to repeat
   * @param vertices - cw vertices of polygon
   * @param density - number of regions per polygon width bound
   */
  public void setPolygon(TextureRegion region, float[] vertices, float density) {

    this.region = region;

    vertices = offset(vertices);

    Polygon polygon = new Polygon(vertices);
    Polygon tmpPoly = new Polygon();
    Polygon intersectionPoly = new Polygon();
    EarClippingTriangulator triangulator = new EarClippingTriangulator();

    int idx;

    Rectangle boundRect = polygon.getBoundingRectangle();

    if (density == -1) density = boundRect.getWidth() / region.getRegionWidth();

    float regionAspectRatio = (float) region.getRegionHeight() / (float) region.getRegionWidth();
    cols = (int) (Math.ceil(density));
    gridWidth = boundRect.getWidth() / density;
    gridHeight = regionAspectRatio * gridWidth;
    rows = (int) Math.ceil(boundRect.getHeight() / gridHeight);

    for (int col = 0; col < cols; col++) {
      for (int row = 0; row < rows; row++) {
        float[] verts = new float[8];
        idx = 0;
        verts[idx++] = col * gridWidth;
        verts[idx++] = row * gridHeight;
        verts[idx++] = (col) * gridWidth;
        verts[idx++] = (row + 1) * gridHeight;
        verts[idx++] = (col + 1) * gridWidth;
        verts[idx++] = (row + 1) * gridHeight;
        verts[idx++] = (col + 1) * gridWidth;
        verts[idx] = (row) * gridHeight;
        tmpPoly.setVertices(verts);

        Intersector.intersectPolygons(polygon, tmpPoly, intersectionPoly);
        verts = intersectionPoly.getVertices();
        if (verts.length > 0) {
          parts.add(snapToGrid(verts));
          ShortArray arr = triangulator.computeTriangles(verts);
          indices.add(arr.toArray());
        } else {
          // adding null for key consistancy, needed to get col/row from key
          // the other alternative is to make parts - IntMap<FloatArray>
          parts.add(null);
        }
      }
    }

    buildVertices();
  }
Exemplo n.º 3
0
 private Rectangle scaleRectangle(Rectangle rect, float scaleX, float scaleY) {
   Rectangle scaled = new Rectangle();
   scaled.setX(rect.getX() * scaleX);
   scaled.setY(rect.getY() * scaleY);
   scaled.setWidth(rect.getWidth() * scaleX);
   scaled.setHeight(rect.getHeight() * scaleY);
   return scaled;
 }
  /**
   * Constructor for a defender button, with type specified
   *
   * @param type: The integer that denotes which button is being created
   */
  public DefenderButtons(int type) {
    // Creating a button doesn't draw it immediately - visible = false
    mVisible = false;

    switch (type) {
      case TYPE_NEW_GAME:
        mType = type;
        mText = "New Game";
        mRect = new Rectangle(125f, 280f, 115f, 50f);
        break;
      case TYPE_RESUME_SAVED_GAME:
        mType = type;
        mText = "Resume Game";
        mRect = new Rectangle(125f, 205f, 115f, 50f);
        break;
      case TYPE_PAUSE_GAME:
        mType = type;
        mText = "Pause";
        mRect = new Rectangle(650f, 375f, 100f, 35f);
        break;
      case TYPE_RESUME_PAUSED_GAME:
        mType = type;
        mText = "Resume";
        mRect = new Rectangle(350f, 345f, 100f, 35f);
        break;
      case TYPE_REPAIR_CASTLE:
        mType = type;
        mText = "Repair: -1000pts";
        mRect = new Rectangle(420f, 200f, 150f, 50f);
        break;
      case TYPE_CONTINUE_NEXT_ROUND:
        mType = type;
        mText = "Start Next Round";
        mRect = new Rectangle(420f, 50f, 150f, 50f);
        break;
      case TYPE_SAVE_GAME:
        mType = type;
        mText = "Save Current Round";
        mRect = new Rectangle(420f, 125f, 150f, 50f);
        break;
      default:
        mType = -1; // Shouldn't ever arrive here
        mText = "bad";
        mRect = new Rectangle(0f, 0f, 10f, 10f);
        break;
    }
    // Grab value from the rectangle
    mX = mRect.getX();
    mY = mRect.getY();
    mWidth = mRect.getWidth();
    mHeight = mRect.getHeight();
  }
Exemplo n.º 5
0
  public TileObject(PlayScreen screen, Rectangle bounds) {

    this.world = screen.getWorld();
    this.map = screen.getMap();
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(
        (bounds.getX() + bounds.getWidth() / 2) / StarWars.PPM,
        (bounds.getY() + bounds.getHeight() / 2) / StarWars.PPM);

    body = world.createBody(bdef);

    shape.setAsBox(bounds.getWidth() / 2 / StarWars.PPM, bounds.getHeight() / 2 / StarWars.PPM);
    fdef.shape = shape;
    fdef.filter.categoryBits = StarWars.PLATFORM_BIT;
    fixture = body.createFixture(fdef);
  }
Exemplo n.º 6
0
  /** Returns correct quadrant or -1 if it wont fit in any quadrants. */
  public int getIndex(Entity e) {
    int index = -1;
    float verticalMidpoint = bounds.getX() + (bounds.getWidth() / 2);
    float horizontalMidpoint = bounds.getY() + (bounds.getHeight() / 2);

    boolean isInBottomTwoQuadrants =
        (e.y < horizontalMidpoint && (e.y + e.height) < horizontalMidpoint);
    boolean isInTopTwoQuadrants = (e.y > horizontalMidpoint);

    if (e.x < verticalMidpoint && (e.x + e.width) < verticalMidpoint) {
      if (isInBottomTwoQuadrants) index = 0;
      else if (isInTopTwoQuadrants) index = 2;
    } else if (e.x > verticalMidpoint) {
      if (isInBottomTwoQuadrants) index = 1;
      else if (isInTopTwoQuadrants) index = 3;
    }
    return index;
  }
Exemplo n.º 7
0
  @Override
  public void render(SpriteBatch batch) {
    batch.end();
    mapRenderer.setView(camera);
    mapRenderer.render();
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
    shapeRenderer.setColor(Color.BLUE);
    for (Rectangle rect : collisions) {
      shapeRenderer.rect(rect.x, rect.y, rect.getWidth(), rect.getHeight());
    }

    shapeRenderer.end();
    batch.begin();
    drawDebugInformation(batch);
    for (Entity entity : entities) {
      entity.render(batch);
    }
  }
Exemplo n.º 8
0
  public void checkBoundsX() {

    for (Rectangle rect : collideRects) {

      if (sprite.getBoundingRectangle().overlaps(rect)) {

        float boundCalc = 0.0f;
        if (direction.x < 0) {

          boundCalc = rect.x + rect.getWidth() + 0.01f;
        } else {

          boundCalc = rect.x - sprite.getWidth() - 0.01f;
        }

        // sprite.setX(boundCalc - .2f);
        targetPos.x = boundCalc - .2f;
        direction.x = 0;
        Gdx.app.log("SpriteOverlap", "Target pos is" + sprite.getX() + ":" + sprite.getY());
      }
    }
  }
Exemplo n.º 9
0
  public void split() {
    int subWidth = (int) (bounds.getWidth() / 2);
    int subHeight = (int) (bounds.getHeight() / 2);

    int x = (int) bounds.getX();
    int y = (int) bounds.getY();

    /*
            Overview of children:
            2 3
            0 1
    */
    children[0] =
        new Quadtree(depth + 1, new Rectangle(x, y, subWidth, subHeight)); // First Quadrant
    children[1] =
        new Quadtree(depth + 1, new Rectangle(x + subWidth, y, subWidth, subHeight)); // Second
    children[2] =
        new Quadtree(depth + 1, new Rectangle(x, y + subHeight, subWidth, subHeight)); // Third
    children[3] =
        new Quadtree(
            depth + 1, new Rectangle(x + subWidth, y + subHeight, subWidth, subHeight)); // Forth
  }
Exemplo n.º 10
0
  @Override
  public void start() {
    OwnedObjectData data = new OwnedObjectData();

    data.drawAfter = true;

    if (bullet.getTicksAlive() < 20) animationPlaying = true;

    createTick = game.getTick();

    bullet.addOwnedObject(this, data);

    final Sprite current = (Sprite) this.ani.getKeyFrame(getTicksAlive());

    Polygon hitbox = bullet.getHitbox();
    Rectangle rect =
        hitbox != null ? hitbox.getBoundingRectangle() : current.getBoundingRectangle();

    final float modifier = 3f;
    float width = rect.getWidth() * modifier;
    float height = rect.getHeight() * modifier;

    final float scaleX = width / current.getWidth();
    final float scaleY = height / current.getHeight();

    current.setScale(scaleX, scaleY);
    current.setRotation(bullet.getRotationDeg());

    current.setOriginCenter();

    Color c = bullet.getDeletionColor().cpy();

    float min = Math.min(c.g, Math.min(c.r, c.b));
    c.r -= min;
    c.g -= min;
    c.b -= min;

    float mul = 0.8f;
    float start = (1f - mul) + 0.3f;

    Color color = new Color(start + (c.r * mul), start + (c.g * mul), start + (c.b * mul), 0f);

    current.setColor(color);
    current.setAlpha(1f);

    final SaveableObject<ScaleAlphaPhaseAnimation> sani =
        new SaveableObject<ScaleAlphaPhaseAnimation>();

    Getter<Sprite> getter =
        new Getter<Sprite>() {
          @Override
          public Sprite get() {
            Sprite current = (Sprite) ani.getKeyFrame(getTicksAlive());

            int over = 5;

            int ticks = (int) ((time.toTicks() - over) - getTicksAlive());

            double mul = 1f - (ticks <= 0 ? -(float) ticks / over : 0f);

            ScaleAlphaPhaseAnimation ani = sani.getObject();

            if (ani == null) return current;

            if (ticks <= 0) {
              animationPlaying = false;
              ani.setAlpha((float) Math.max(0, mul));
            }

            current.setPosition(
                bullet.getX() - current.getWidth() / 2f, bullet.getY() - current.getHeight() / 2f);

            current.setOriginCenter();

            current.setRotation(bullet.getRotationDeg());

            return current;
          }
        };

    final ScaleAlphaPhaseAnimation ani = new ScaleAlphaPhaseAnimation(getter, bullet);

    sani.setObject(ani);

    ani.setTime(time);
    ani.setAddedScale(scaleX * 3f, scaleY * 3f);
    ani.setAlpha(-0.1f);
    ani.start();

    bullet.removeOwnedObject(ani);
    bullet.addOwnedObject(ani, data);
  }
Exemplo n.º 11
0
  private void initMilitaryTopPane() {
    Table contentTable = new Table();

    int itemPerRow =
        (int) (militaryTablePos.width / (militaryTablePortraitSize.x + militaryTableCaptionSize.x));
    int index = 0;
    for (Military m : parent.getCurrentArchitecture().getMilitariesWithLeader()) {
      Table item = new Table();

      Person leader = m.getLeader();
      ImageWidget<Military> portrait;
      if (leader != null) {
        portrait =
            new ImageWidget<>(
                parent.getScreen().getSmallPortrait(leader.getPortraitId()),
                militaryTablePortraitColor);
      } else {
        portrait = new ImageWidget<>(null, militaryTablePortraitColor);
      }
      portrait.setExtra(m);
      item.add(portrait).width(militaryTablePortraitSize.x).height(militaryTablePortraitSize.y);

      Table detail = new Table();

      TextWidget<Military> caption = new TextWidget<>(militaryTableCaptionTemplate);
      caption.setExtra(m);
      caption.setText(m.getName());
      detail
          .add(caption)
          .width(militaryTableCaptionSize.x)
          .height(militaryTableCaptionSize.y)
          .row();

      TextWidget<Military> quantity = new TextWidget<>(militaryTableDetailTemplate);
      quantity.setExtra(m);
      quantity.setText(
          GlobalStrings.getString(GlobalStrings.Keys.MILITARY_QUANTITY_SHORT) + m.getQuantity());
      detail.add(quantity).width(militaryTableDetailSize.x).height(militaryTableDetailSize.y).row();

      TextWidget<Military> morale = new TextWidget<>(militaryTableDetailTemplate);
      morale.setExtra(m);
      morale.setText(
          GlobalStrings.getString(GlobalStrings.Keys.MILITARY_MORALE_SHORT) + m.getMorale());
      detail.add(morale).width(militaryTableDetailSize.x).height(militaryTableDetailSize.y).row();

      TextWidget<Military> combativity = new TextWidget<>(militaryTableDetailTemplate);
      combativity.setExtra(m);
      combativity.setText(
          GlobalStrings.getString(GlobalStrings.Keys.MILITARY_COMBATIVITY_SHORT)
              + m.getCombativity());
      detail
          .add(combativity)
          .width(militaryTableDetailSize.x)
          .height(militaryTableDetailSize.y)
          .row();

      detail.top();
      item.add(detail);

      item.addListener(
          new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
              currentMilitary = m;
              currentMilitaryPos =
                  new Rectangle(
                      item.getX() + militaryTablePos.getX(),
                      item.getY() + militaryTablePos.getY(),
                      item.getWidth(),
                      item.getHeight());
              if (m.isCampaignable()) {
                parent
                    .getScreen()
                    .getMapLayer()
                    .startSelectingLocation(
                        parent.getCurrentArchitecture().getCampaignablePositions(),
                        p -> {
                          m.startCampaign(p);
                          invalidateListPanes();
                        });
              }
              return true;
            }
          });

      contentTable.add(item);

      index++;
      if (index % itemPerRow == 0) {
        contentTable.row();
      }
    }

    contentTable.top().left();

    ScrollPane data = new ScrollPane(contentTable);
    militaryTopPane =
        WidgetUtility.setupScrollpane(
            militaryTablePos.getX(),
            militaryTablePos.getY(),
            militaryTablePos.getWidth(),
            militaryTablePos.getHeight(),
            data,
            parent.getScrollbar());

    parent.addActor(militaryTopPane);
  }
Exemplo n.º 12
0
  private void initMilitaryBottomPane() {
    Table contentTable = new Table();

    for (Military m : parent.getCurrentArchitecture().getMilitariesWithoutLeader()) {
      List<TextWidget<Military>> rowWidgets = new ArrayList<>();

      TextWidget<Military> name = new TextWidget<>(militaryListTextTemplate);
      name.setExtra(m);
      name.setText(m.getName());
      contentTable.add(name).width(listNameWidth).height(listRowHeight);
      rowWidgets.add(name);

      TextWidget<Military> quantity = new TextWidget<>(militaryListTextTemplate);
      quantity.setExtra(m);
      quantity.setText(String.valueOf(m.getQuantity()));
      contentTable.add(quantity).width(listQuantityWidth).height(listRowHeight);
      rowWidgets.add(quantity);

      TextWidget<Military> recruit = new TextWidget<>(militaryListTextTemplate);
      recruit.setExtra(m);
      if (m.isFullyRecruited()) {
        recruit.setText(GlobalStrings.getString(GlobalStrings.Keys.TICK));
      } else if (m.isBeingRecruited()) {
        recruit.setText(GlobalStrings.getString(GlobalStrings.Keys.UP_ARROW));
      } else {
        recruit.setText("");
      }
      contentTable.add(recruit).width(listRecruitWidth).height(listRowHeight).center();
      rowWidgets.add(recruit);

      TextWidget<Military> train = new TextWidget<>(militaryListTextTemplate);
      train.setExtra(m);
      if (m.isFullyTrained()) {
        train.setText(GlobalStrings.getString(GlobalStrings.Keys.TICK));
      } else if (m.isBeingTrained()) {
        train.setText(GlobalStrings.getString(GlobalStrings.Keys.UP_ARROW));
      } else {
        train.setText("");
      }
      contentTable.add(train).width(listTrainWidth).height(listRowHeight).center();
      rowWidgets.add(train);

      rowWidgets.forEach(
          x ->
              x.addListener(
                  new InputListener() {
                    @Override
                    public boolean touchDown(
                        InputEvent event, float x, float y, int pointer, int button) {
                      currentMilitary = m;
                      currentMilitaryPos =
                          new Rectangle(
                              name.getX() + militaryListPos.getX(),
                              name.getY() + militaryListPos.getY(),
                              militaryListPos.getWidth(),
                              name.getHeight());
                      return true;
                    }
                  }));

      showingTextWidgets.addAll(rowWidgets);

      contentTable.row().height(listRowHeight);
    }

    contentTable.top().left();

    ScrollPane data = new ScrollPane(contentTable);
    militaryBottomPane =
        WidgetUtility.setupScrollpane(
            militaryListPos.getX(),
            militaryListPos.getY(),
            militaryListPos.getWidth(),
            militaryListPos.getHeight(),
            data,
            parent.getScrollbar());

    parent.addActor(militaryBottomPane);
  }
Exemplo n.º 13
0
  @Override
  public void draw(Batch batch, float parentAlpha) {
    batch.draw(
        reorganize.get(),
        parent.getX() + reorganizePos.x,
        parent.getY() + reorganizePos.y,
        reorganizePos.width,
        reorganizePos.height);
    batch.draw(
        newMilitary.get(),
        parent.getX() + newMilitaryPos.x,
        parent.getY() + newMilitaryPos.y,
        newMilitaryPos.width,
        newMilitaryPos.height);
    batch.draw(
        recruit.get(),
        parent.getX() + recruitPos.x,
        parent.getY() + recruitPos.y,
        recruitPos.width,
        recruitPos.height);
    batch.draw(
        training.get(),
        parent.getX() + trainingPos.x,
        parent.getY() + trainingPos.y,
        trainingPos.width,
        trainingPos.height);
    batch.draw(
        merge.get(),
        parent.getX() + mergePos.x,
        parent.getY() + mergePos.y,
        mergePos.width,
        mergePos.height);
    batch.draw(
        disband.get(),
        parent.getX() + disbandPos.x,
        parent.getY() + disbandPos.y,
        disbandPos.width,
        disbandPos.height);
    batch.draw(
        upgrade.get(),
        parent.getX() + upgradePos.x,
        parent.getY() + upgradePos.y,
        upgradePos.width,
        upgradePos.height);

    for (TextWidget<ArchitectureCommandFrame.TextType> textWidget : textWidgets) {
      textWidget.setPosition(
          textWidget.getExtra().position.x + parent.getX(),
          textWidget.getExtra().position.y + parent.getY());
      if (textWidget.getExtra().staticText) {
        textWidget.setText(textWidget.getExtra().name);
      } else {
        textWidget.setText(
            parent.getCurrentArchitecture().getFieldString(textWidget.getExtra().name));
      }
      textWidget.draw(batch, parentAlpha);
    }

    if (militaryBottomPane == null) {
      initMilitaryBottomPane();
    }
    if (militaryTopPane == null) {
      initMilitaryTopPane();
    }

    if (currentMilitary != null) {
      batch.end();

      shapeRenderer.begin(ShapeRenderer.ShapeType.Line);

      shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
      shapeRenderer.setTransformMatrix(batch.getTransformMatrix());

      shapeRenderer.setColor(selectedBorderColor);
      shapeRenderer.rect(
          parent.getX() + currentMilitaryPos.getX(),
          parent.getY() + currentMilitaryPos.getY(),
          currentMilitaryPos.getWidth(),
          currentMilitaryPos.getHeight());

      shapeRenderer.end();

      batch.begin();
    }
  }
Exemplo n.º 14
0
 private void recalculateBoundsSize(CharSequence text) {
   Rectangle textBounds = SpriteBatchUtils.getBounds(font, text, getX(), getY());
   width = textBounds.getWidth();
   height = textBounds.getHeight();
 }
 /**
  * Set right x value.
  *
  * @param x value for right side of the rectangle.
  */
 public final void setRight(float x) {
   location.x = x - location.getWidth();
 }
 /**
  * Value of right X location.
  *
  * @return Right X location.
  */
 public final float getRight() {
   return location.getX() + location.getWidth();
 }