Ejemplo n.º 1
0
  private void drawWeapon() {
    shapeRenderer.begin(ShapeType.Line);

    Player player = GameController.getInstance().getPlayer();

    float offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT;
    float offsetY = Constants.WEAPON_OFFSET_FROM_PLAYER_Y;

    if (player.getFacing() == 0) {
      offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT;
    } else {
      offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_LEFT;
    }

    Player p = player;

    Float deltaX = 0f;
    Float deltaY = 0f;

    Float playerXCentered = p.getX() + (p.getWidth() / 2);
    Float playerYCentered = p.getY() + (p.getHeight() / 2);

    Float mouseX = p.getTargetX();
    Float mouseY = p.getTargetY();

    deltaX = (mouseX - playerXCentered);
    deltaY = (mouseY - playerYCentered);

    Double angle = Math.atan2(deltaY.doubleValue(), deltaX.doubleValue());

    Double rotation = (Math.toDegrees(angle));

    float x = player.getX() + offsetX;
    float y = player.getY() + offsetY;
    shapeRenderer.setColor(Color.ORANGE);
    shapeRenderer.rect(
        x,
        y,
        Constants.WEAPON_ORIGIN_X,
        Constants.WEAPON_ORIGIN_Y,
        Constants.WEAPON_WIDTH,
        Constants.WEAPON_HEIGHT,
        1,
        player.getFacing() == 0 ? 1 : -1,
        rotation.intValue());
    shapeRenderer.setColor(Color.BLACK);
    shapeRenderer.circle(x + Constants.WEAPON_ORIGIN_X, y + Constants.WEAPON_ORIGIN_Y, 2);
    shapeRenderer.end();
  }
Ejemplo n.º 2
0
  private void drawTrajectory() {
    float offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT;
    float offsetY = Constants.WEAPON_OFFSET_FROM_PLAYER_Y;

    if (player.getFacing() == 0) {
      offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT;
    } else {
      offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_LEFT;
    }

    Player p = player;

    Float originX = p.getX() + offsetX + Constants.WEAPON_ORIGIN_X;
    Float originY = p.getY() + offsetY + Constants.WEAPON_ORIGIN_Y;

    Float mouseX = player.getTargetX();
    Float mouseY = player.getTargetY();

    Float deltaX = (mouseX - originX);
    Float deltaY = (mouseY - originY);

    Double angle = Math.atan2(deltaY.doubleValue(), deltaX.doubleValue());

    Float x = (float) Math.cos(angle.floatValue());
    Float y = (float) Math.sin(angle.floatValue());

    Float calculatedX = originX + x * Constants.SHOT_DISTANCE_FROM_ORIGIN;
    Float calculatedY = originY + y * Constants.SHOT_DISTANCE_FROM_ORIGIN;

    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.RED);
    shapeRenderer.line(calculatedX, calculatedY, mouseX, mouseY);
    shapeRenderer.end();
  }
Ejemplo n.º 3
0
 private void drawRectangles() {
   shapeRenderer.begin(ShapeType.Line);
   Player player = GameController.getInstance().getPlayer();
   float x = player.getX();
   float y = player.getY();
   shapeRenderer.setColor(Color.GREEN);
   shapeRenderer.rect(x, y, player.getWidth(), player.getHeight());
   shapeRenderer.end();
 }