Example #1
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();
 }
Example #2
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();
  }