@Override
  public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    unprojectVec.set(screenX, screenY, 0);
    cameraManager.getCamera().unproject(unprojectVec);

    float x = unprojectVec.x;
    float y = unprojectVec.y;

    if (state == GameState.RUNNING && pauseSprite.getBoundingRectangle().contains(x, y)) {
      soundController.playClick();
      state = GameState.PAUSED;
      resumeSprite.setAlpha(1);
    }

    if (state == GameState.PAUSED && resumeSprite.getBoundingRectangle().contains(x, y)) {
      soundController.playClick();
      state = GameState.RUNNING;
      resumeSprite.setAlpha(0);
    }

    if (state == GameState.GET_READY) {
      soundController.playClick();
      state = GameState.RUNNING;
      readySprite.setAlpha(0);
    }

    return false;
  }
  public void update() {
    if (Gdx.input.isKeyPressed(Input.Keys.BACK)) {
      Gdx.app.exit();
    }
    if (Gdx.input.justTouched()) {
      guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));

      if (startButton.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
        game.setScreen(new StartGameScreen(game));
        return;
      }

      if (creditsButton.getBoundingRectangle().contains(touchPoint.x, touchPoint.y)) {
        game.setScreen(new CreditsScreen(game));
        return;
      }
    }
  }
  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());
      }
    }
  }
示例#4
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);
  }